pub struct ParsedSource { /* private fields */ }Expand description
A source file plus its parse tree; the input to lowering and to the syntax-diagnostic pass.
Implementations§
Source§impl ParsedSource
impl ParsedSource
Sourcepub fn tree(&self) -> &Tree
pub fn tree(&self) -> &Tree
The tree-sitter parse tree.
Examples found in repository?
examples/conformance.rs (line 29)
13fn main() {
14 let path = std::env::args()
15 .nth(1)
16 .expect("usage: conformance <corpus.json>");
17 let raw = std::fs::read_to_string(&path).expect("corpus file readable");
18 let corpus: Vec<String> = parse_json_strings(&raw);
19
20 let mut failures = 0usize;
21 let mut report = String::new();
22 for (index, query) in corpus.iter().enumerate() {
23 let source = surrealguard_syntax::source::SourceId::new(format!("corpus:{index}"));
24 let Ok(parsed) = surrealguard_syntax::parse::parse_source(source, query.as_str()) else {
25 failures += 1;
26 let _ = writeln!(report, "#{index}: parser returned no tree");
27 continue;
28 };
29 if let Some(range) = first_broken_range(parsed.tree().root_node()) {
30 failures += 1;
31 let snippet: String = query[range.clone()].chars().take(60).collect();
32 let context: String = query.chars().take(80).collect();
33 let _ = writeln!(
34 report,
35 "#{index}: ERROR at {range:?}: `{}`\n in: {}",
36 snippet.replace('\n', " "),
37 context.replace('\n', " ")
38 );
39 }
40 }
41
42 print!("{report}");
43 println!(
44 "---\n{failures}/{} corpus entries fail to parse",
45 corpus.len()
46 );
47 if failures > 0 {
48 std::process::exit(1);
49 }
50}Sourcepub fn root_kind(&self) -> &str
pub fn root_kind(&self) -> &str
Kind of the root CST node ("SurrealQL" for a well-formed parse).
Sourcepub fn syntax_diagnostics(&self) -> &[SyntaxDiagnostic]
pub fn syntax_diagnostics(&self) -> &[SyntaxDiagnostic]
The recoverable syntax problems collected during parsing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ParsedSource
impl RefUnwindSafe for ParsedSource
impl Send for ParsedSource
impl Sync for ParsedSource
impl Unpin for ParsedSource
impl UnsafeUnpin for ParsedSource
impl UnwindSafe for ParsedSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more