summaryrefslogtreecommitdiff
path: root/src/parse/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-12-16 16:24:06 +0100
committerLaurenz <laurmaedje@gmail.com>2020-12-16 16:24:06 +0100
commit2336aeb4c32864f53a4d4e0f72e54a174df47a60 (patch)
treee45a039b82b62231a5bde9d58c28cb3df713a77e /src/parse/mod.rs
parent6bbedeaa2c6e0068e2fb6602cbf0002fb6a6ce03 (diff)
Tweak parser error messages 🔮
Diffstat (limited to 'src/parse/mod.rs')
-rw-r--r--src/parse/mod.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 33de5c24..61c90f6c 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -85,8 +85,9 @@ fn node(p: &mut Parser, at_start: bool) -> Option<Spanned<SynNode>> {
}
// Bad tokens.
- token => {
- p.diag_unexpected(token.span_with(start .. p.pos()));
+ _ => {
+ p.jump(start);
+ p.diag_unexpected();
return None;
}
};
@@ -233,6 +234,7 @@ fn paren_call(p: &mut Parser, name: Spanned<Ident>) -> ExprCall {
fn dict_contents(p: &mut Parser) -> (LitDict, bool) {
let mut dict = LitDict::new();
let mut comma_and_keyless = true;
+ let mut expected_comma = None;
loop {
p.skip_white();
@@ -243,10 +245,15 @@ fn dict_contents(p: &mut Parser) -> (LitDict, bool) {
let entry = if let Some(entry) = dict_entry(p) {
entry
} else {
- p.diag_expected("value");
+ expected_comma = None;
+ p.diag_unexpected();
continue;
};
+ if let Some(pos) = expected_comma.take() {
+ p.diag_expected_at("comma", pos);
+ }
+
if let Some(key) = &entry.key {
comma_and_keyless = false;
p.deco(Deco::DictKey.span_with(key.span));
@@ -261,7 +268,7 @@ fn dict_contents(p: &mut Parser) -> (LitDict, bool) {
}
if !p.eat_if(Token::Comma) {
- p.diag_expected_at("comma", behind);
+ expected_comma = Some(behind);
}
comma_and_keyless = false;
@@ -286,6 +293,7 @@ fn dict_entry(p: &mut Parser) -> Option<LitDictEntry> {
expr,
})
} else {
+ p.diag_expected("value");
None
}
}