lang: fix some details in the parser

This commit is contained in:
Schrottkatze 2024-06-05 09:57:08 +02:00
parent 0de076ace1
commit cfefab9fd0
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
2 changed files with 19 additions and 6 deletions

View file

@ -86,14 +86,17 @@ fn def(p: &mut Parser) -> Option<CompletedMarker> {
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<CompletedMarker> {
.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<CompletedMarker> {
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<CompletedMarker> {
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<CompletedMarker> {
.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])));

View file

@ -5,6 +5,7 @@ def hello_world = meow [ 1 2 ];
def test
mod hello {
use gay:;uwu_meow::*;
def meow = uwu;
}