Fix: Implement ~ and ~@ syntax to prevent parser deadlock
Adds parsing for the `~` (placeholder) and `~@` (splice) syntax. - `~expr` parses as a placeholder node. - `~@expr` parses as a splice node.
This commit is contained in:
@@ -378,6 +378,25 @@ impl<'a> Parser<'a> {
|
|||||||
ty: (),
|
ty: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TokenKind::Tilde => {
|
||||||
|
let token = self.advance(); // consume ~
|
||||||
|
if *self.peek() == TokenKind::At {
|
||||||
|
self.advance(); // consume @
|
||||||
|
let expr = self.parse_expression();
|
||||||
|
Node {
|
||||||
|
identity: NodeIdentity::new(token.location),
|
||||||
|
kind: UntypedKind::Splice(Box::new(expr)),
|
||||||
|
ty: (),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let expr = self.parse_expression();
|
||||||
|
Node {
|
||||||
|
identity: NodeIdentity::new(token.location),
|
||||||
|
kind: UntypedKind::Placeholder(Box::new(expr)),
|
||||||
|
ty: (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.diagnostics.push_error(
|
self.diagnostics.push_error(
|
||||||
format!(
|
format!(
|
||||||
@@ -386,6 +405,7 @@ impl<'a> Parser<'a> {
|
|||||||
),
|
),
|
||||||
Some(NodeIdentity::new(self.current_token.location)),
|
Some(NodeIdentity::new(self.current_token.location)),
|
||||||
);
|
);
|
||||||
|
self.advance();
|
||||||
Node {
|
Node {
|
||||||
identity: NodeIdentity::new(self.current_token.location),
|
identity: NodeIdentity::new(self.current_token.location),
|
||||||
kind: UntypedKind::Error,
|
kind: UntypedKind::Error,
|
||||||
|
|||||||
Reference in New Issue
Block a user