summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src/parser.rs
diff options
context:
space:
mode:
authorYip Coekjan <69834864+Coekjan@users.noreply.github.com>2024-06-04 23:33:08 +0800
committerGitHub <noreply@github.com>2024-06-04 15:33:08 +0000
commitada0f5da65ef41ac8fa11111839437c76edd3c68 (patch)
tree5e258c0e146904ab78ed28ca393e6575b22671eb /crates/typst-syntax/src/parser.rs
parentdf6e347bc55bdcbf370645442290198c0bcdd3fe (diff)
Hint for labels in code mode (#4319)
Diffstat (limited to 'crates/typst-syntax/src/parser.rs')
-rw-r--r--crates/typst-syntax/src/parser.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs
index d341bca2..e27cafcf 100644
--- a/crates/typst-syntax/src/parser.rs
+++ b/crates/typst-syntax/src/parser.rs
@@ -633,6 +633,10 @@ fn code_exprs(p: &mut Parser, mut stop: impl FnMut(&Parser) -> bool) {
code_expr(p);
if !p.end() && !stop(p) && !p.eat_if(SyntaxKind::Semicolon) {
p.expected("semicolon or line break");
+ if p.at(SyntaxKind::Label) {
+ p.hint("labels can only be applied in markup mode");
+ p.hint("try wrapping your code in a markup block (`[ ]`)");
+ }
}
}
@@ -1838,6 +1842,14 @@ impl<'s> Parser<'s> {
self.nodes.insert(m.0, error);
}
+ /// Produce a hint.
+ fn hint(&mut self, hint: &str) {
+ let m = self.before_trivia();
+ if let Some(error) = self.nodes.get_mut(m.0 - 1) {
+ error.hint(hint);
+ }
+ }
+
/// Consume the next token (if any) and produce an error stating that it was
/// unexpected.
fn unexpected(&mut self) {