Fix show rule colon error message

This commit is contained in:
Laurenz 2023-03-21 13:08:18 +01:00
parent c913271b29
commit 53b57d8294
2 changed files with 25 additions and 2 deletions

View File

@ -872,11 +872,20 @@ fn set_rule(p: &mut Parser) {
fn show_rule(p: &mut Parser) { fn show_rule(p: &mut Parser) {
let m = p.marker(); let m = p.marker();
p.assert(SyntaxKind::Show); p.assert(SyntaxKind::Show);
p.unskip();
let m2 = p.marker();
p.skip();
if !p.at(SyntaxKind::Colon) { if !p.at(SyntaxKind::Colon) {
code_expr(p); code_expr(p);
} }
p.expect(SyntaxKind::Colon);
code_expr(p); if p.eat_if(SyntaxKind::Colon) {
code_expr(p);
} else {
p.expected_at(m2, "colon");
}
p.wrap(m, SyntaxKind::ShowRule); p.wrap(m, SyntaxKind::ShowRule);
} }
@ -1295,6 +1304,12 @@ impl<'s> Parser<'s> {
self.skip(); self.skip();
} }
fn expected_at(&mut self, m: Marker, thing: &str) {
let message = eco_format!("expected {}", thing);
let error = SyntaxNode::error(message, "", ErrorPos::Full);
self.nodes.insert(m.0, error);
}
fn unexpected(&mut self) { fn unexpected(&mut self) {
self.unskip(); self.unskip();
while self while self

View File

@ -31,3 +31,11 @@ Ignored
--- ---
// Error: 4-19 show is only allowed directly in code and content blocks // Error: 4-19 show is only allowed directly in code and content blocks
#((show: body => 2) * body) #((show: body => 2) * body)
---
// Error: 6 expected colon
#show it => {}
---
// Error: 6 expected colon
#show it