diff --git a/crates/pawarser/src/parser.rs b/crates/pawarser/src/parser.rs index 3782f0f..c592cdb 100644 --- a/crates/pawarser/src/parser.rs +++ b/crates/pawarser/src/parser.rs @@ -120,6 +120,9 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> let mut errors: Vec = Vec::new(); raw_toks.reverse(); + // always have an implicit root node to avoid [`GreenNodeBuilder::finish()`] panicking due to multiple root elements. + builder.start_node(SyntaxKind::SYNTAX_ROOT.into()); + for i in 0..events.len() { match mem::replace(&mut events[i], Event::tombstone()) { Event::Start { @@ -185,6 +188,9 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> } } + // finish SYNTAX_ROOT + builder.finish_node(); + ParserOutput { green_node: builder.finish(), errors,