From ed151c2e3c9d732739c8b03acbe42a9a5c70bd0b Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sat, 4 May 2024 23:12:47 +0200 Subject: [PATCH] lang: handle and recover some errors in lists --- crates/lang/src/lst_parser/error.rs | 3 +++ .../grammar/expression/collection/vec.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/lang/src/lst_parser/error.rs b/crates/lang/src/lst_parser/error.rs index d13306c..1269acc 100644 --- a/crates/lang/src/lst_parser/error.rs +++ b/crates/lang/src/lst_parser/error.rs @@ -4,4 +4,7 @@ use crate::lst_parser::syntax_kind::SyntaxKind; pub enum SyntaxError { Expected(Vec), PipelineNeedsSink, + // if there was two space seperated items in a list + SpaceSepInList, + SemicolonInList, } diff --git a/crates/lang/src/lst_parser/grammar/expression/collection/vec.rs b/crates/lang/src/lst_parser/grammar/expression/collection/vec.rs index fa76058..6e5884d 100644 --- a/crates/lang/src/lst_parser/grammar/expression/collection/vec.rs +++ b/crates/lang/src/lst_parser/grammar/expression/collection/vec.rs @@ -17,8 +17,10 @@ pub fn vec_matrix_list(p: &mut Parser) -> CompletedMarker { finish_mat_or_vec(p, start, row_start) } else if p.eat(R_BRACK) { + row_start.abandon(p); start.complete(p, LIST) } else { + row_start.abandon(p); start.complete_err(p, SyntaxError::Expected(vec![EXPR, R_BRACK])) } } @@ -35,6 +37,21 @@ fn finish_list(p: &mut Parser, list_start: Marker) -> CompletedMarker { } } else if p.eat(R_BRACK) { return list_start.complete(p, LIST); + } else if let Some(item) = atom(p) { + item.precede(p, "next_item") + .complete(p, COLLECTION_ITEM) + .precede(p, "err_space_sep") + .complete_err(p, SyntaxError::SpaceSepInList); + } else if p.at(SEMICOLON) { + let semi_err = p.start("semicolon_err"); + p.eat(SEMICOLON); + semi_err.complete_err(p, SyntaxError::SemicolonInList); + if let Some(item) = atom(p) { + item.precede(p, "coll_item_start") + .complete(p, COLLECTION_ITEM); + } else if p.eat(R_BRACK) { + return list_start.complete(p, LIST); + } } } }