interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / syn / tests / common / parse.rs

51 lines · 1317 bytes Raw Blame History
1extern crate rustc_ast;
2extern crate rustc_driver;
3extern crate rustc_expand;
4extern crate rustc_parse;
5extern crate rustc_session;
6extern crate rustc_span;
7
8use rustc_ast::ast;
9use rustc_parse::lexer::StripTokens;
10use rustc_session::parse::ParseSess;
11use rustc_span::FileName;
12use std::panic;
13
14pub fn librustc_expr(input: &str) -> Option<Box<ast::Expr>> {
15 match panic::catch_unwind(|| {
16 let sess = ParseSess::new();
17 let name = FileName::Custom("test_precedence".to_string());
18 let mut parser = rustc_parse::new_parser_from_source_str(
19 &sess,
20 name,
21 input.to_string(),
22 StripTokens::ShebangAndFrontmatter,
23 )
24 .unwrap();
25 let presult = parser.parse_expr();
26 match presult {
27 Ok(expr) => Some(expr),
28 Err(diagnostic) => {
29 diagnostic.emit();
30 None
31 }
32 }
33 }) {
34 Ok(Some(e)) => Some(e),
35 Ok(None) => None,
36 Err(_) => {
37 errorf!("librustc panicked\n");
38 None
39 }
40 }
41}
42
43pub fn syn_expr(input: &str) -> Option<syn::Expr> {
44 match syn::parse_str(input) {
45 Ok(e) => Some(e),
46 Err(msg) => {
47 errorf!("syn failed to parse\n{:?}\n", msg);
48 None
49 }
50 }
51}