ast: add continue expression

This commit is contained in:
2025-10-28 22:47:58 -04:00
parent fb8677c937
commit d5e25a15dc
4 changed files with 5 additions and 0 deletions

View File

@@ -354,6 +354,7 @@ impl<A: Annotation> Display for Expr<A> {
Self::Bind(v) => v.fmt(f), Self::Bind(v) => v.fmt(f),
Self::Make(v) => v.fmt(f), Self::Make(v) => v.fmt(f),
Self::Op(op @ Op::Continue, exprs) => f.delimit(op, "").list(exprs, "!?,"),
Self::Op(op @ (Op::If | Op::While), exprs) => match exprs.as_slice() { Self::Op(op @ (Op::If | Op::While), exprs) => match exprs.as_slice() {
[cond, pass, Anno(Expr::Op(Op::Tuple, e), _)] if e.is_empty() => { [cond, pass, Anno(Expr::Op(Op::Tuple, e), _)] if e.is_empty() => {
write!(f, "{op}{cond} {pass}") write!(f, "{op}{cond} {pass}")

View File

@@ -292,6 +292,7 @@ impl<'t> Lexer<'t> {
"as" => TKind::As, "as" => TKind::As,
"break" => TKind::Break, "break" => TKind::Break,
"const" => TKind::Const, "const" => TKind::Const,
"continue" => TKind::Continue,
"do" => TKind::Do, "do" => TKind::Do,
"else" => TKind::Else, "else" => TKind::Else,
"enum" => TKind::Enum, "enum" => TKind::Enum,

View File

@@ -120,6 +120,7 @@ fn from_prefix(token: &Token) -> PResult<(Ps, Prec)> {
TKind::While => (Ps::Op(Op::While), Prec::Body), TKind::While => (Ps::Op(Op::While), Prec::Body),
TKind::Break => (Ps::Op(Op::Break), Prec::Body), TKind::Break => (Ps::Op(Op::Break), Prec::Body),
TKind::Return => (Ps::Op(Op::Return), Prec::Body), TKind::Return => (Ps::Op(Op::Return), Prec::Body),
TKind::Continue => (Ps::Op(Op::Continue), Prec::Min),
TKind::LCurly => (Ps::Op(Op::Block), Prec::Min), TKind::LCurly => (Ps::Op(Op::Block), Prec::Min),
TKind::RCurly => (Ps::End, Prec::Do), TKind::RCurly => (Ps::End, Prec::Do),
@@ -266,6 +267,7 @@ impl<'t> Parse<'t> for Expr {
Some(value) => Expr::Op(Op::Group, vec![value]), Some(value) => Expr::Op(Op::Group, vec![value]),
None => Expr::Op(Op::Tuple, vec![]), None => Expr::Op(Op::Tuple, vec![]),
}, },
Ps::Op(Op::Continue) => p.consume().then(Expr::Op(Op::Continue, vec![])),
Ps::Op(op @ (Op::If | Op::While)) => { Ps::Op(op @ (Op::If | Op::While)) => {
p.consume(); p.consume();
let exprs = vec![ let exprs = vec![

View File

@@ -67,6 +67,7 @@ pub enum TKind {
As, As,
Break, Break,
Const, Const,
Continue,
Do, Do,
Else, Else,
Enum, Enum,