From cfefab9fd05fa8ecff99f99901a1cb77485f83e8 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Wed, 5 Jun 2024 09:57:08 +0200 Subject: [PATCH] lang: fix some details in the parser --- crates/lang/src/lst_parser/grammar/module.rs | 24 +++++++++++++++----- testfiles/test.owo | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/lang/src/lst_parser/grammar/module.rs b/crates/lang/src/lst_parser/grammar/module.rs index 1bce2a4..008627c 100644 --- a/crates/lang/src/lst_parser/grammar/module.rs +++ b/crates/lang/src/lst_parser/grammar/module.rs @@ -86,14 +86,17 @@ fn def(p: &mut Parser) -> Option { body.error(p, SyntaxError::Expected(vec![DEF_BODY])); } - let def = def_start.complete(p, DEF); Some(if p.eat(SEMICOLON) { - def + def_start.complete(p, DEF) } else if TOP_LEVEL_ITEM_START.contains(p.current()) || p.at(EOF) { - def.precede(p, "unterminated_tl_item") + def_start + .complete(p, DEF) + .precede(p, "unterminated_tl_item") .error(p, SyntaxError::UnterminatedTopLevelItem) } else { - def.precede(p, "err_unexpected") + def_start + .complete(p, DEF) + .precede(p, "err_unexpected") .error(p, SyntaxError::Expected(vec![SEMICOLON])) }) } @@ -110,7 +113,7 @@ fn r#use(p: &mut Parser) -> Option { .error(p, SyntaxError::Expected(vec![USE_PAT])); } - let use_item = use_start.complete(p, DEF); + let use_item = use_start.complete(p, USE); Some(if p.eat(SEMICOLON) { use_item } else if TOP_LEVEL_ITEM_START.contains(p.current()) || p.at(EOF) { @@ -142,6 +145,9 @@ fn use_pat(p: &mut Parser) -> Option { wrong_semi.error(p, SyntaxError::PathSepContainsSemicolon); p.eat(COLON); broken_sep.complete(p, PATH_SEP); + if pat_item(p).is_none() { + break Some(use_pat_marker.error(p, SyntaxError::UnfinishedPath)); + } } else if p.at(COLON) && p.nth_at(1, SEMICOLON) { let broken_sep = p.start("broken_path_sep"); p.eat(COLON); @@ -149,6 +155,9 @@ fn use_pat(p: &mut Parser) -> Option { p.eat(SEMICOLON); wrong_semi.error(p, SyntaxError::PathSepContainsSemicolon); broken_sep.complete(p, PATH_SEP); + if pat_item(p).is_none() { + break Some(use_pat_marker.error(p, SyntaxError::UnfinishedPath)); + } } else if p.at(SEMICOLON) && p.nth_at(1, SEMICOLON) { let broken_sep = p.start("broken_path_sep"); p.eat(SEMICOLON); @@ -157,7 +166,10 @@ fn use_pat(p: &mut Parser) -> Option { .complete(p, PATH_SEP) .precede(p, "semi_typo_err") .error(p, SyntaxError::PathSepContainsSemicolon); - } else if p.at(SEMICOLON) { + if pat_item(p).is_none() { + break Some(use_pat_marker.error(p, SyntaxError::UnfinishedPath)); + } + } else if p.eat(SEMICOLON) { break Some(use_pat_marker.complete(p, USE_PAT)); } else { break Some(use_pat_marker.error(p, SyntaxError::Expected(vec![PATH_SEP, SEMICOLON]))); diff --git a/testfiles/test.owo b/testfiles/test.owo index f94256a..4f06140 100644 --- a/testfiles/test.owo +++ b/testfiles/test.owo @@ -5,6 +5,7 @@ def hello_world = meow [ 1 2 ]; def test mod hello { + use gay:;uwu_meow::*; def meow = uwu; }