Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/syn-2.0.119/tests/common/parse.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / syn-2.0.119 / tests / common / parse.rs` 51 lines ยท 1317 bytes Raw Blame History 1 extern crate rustc_ast; 2 extern crate rustc_driver; 3 extern crate rustc_expand; 4 extern crate rustc_parse; 5 extern crate rustc_session; 6 extern crate rustc_span; 7 8 use rustc_ast::ast; 9 use rustc_parse::lexer::StripTokens; 10 use rustc_session::parse::ParseSess; 11 use rustc_span::FileName; 12 use std::panic; 13 14 pub fn librustc_expr(input: &str) -> Option> { 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 43 pub fn syn_expr(input: &str) -> Option { 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 }