ast: add continue expression
This commit is contained in:
@@ -354,6 +354,7 @@ impl<A: Annotation> Display for Expr<A> {
|
||||
Self::Bind(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() {
|
||||
[cond, pass, Anno(Expr::Op(Op::Tuple, e), _)] if e.is_empty() => {
|
||||
write!(f, "{op}{cond} {pass}")
|
||||
|
||||
@@ -292,6 +292,7 @@ impl<'t> Lexer<'t> {
|
||||
"as" => TKind::As,
|
||||
"break" => TKind::Break,
|
||||
"const" => TKind::Const,
|
||||
"continue" => TKind::Continue,
|
||||
"do" => TKind::Do,
|
||||
"else" => TKind::Else,
|
||||
"enum" => TKind::Enum,
|
||||
|
||||
@@ -120,6 +120,7 @@ fn from_prefix(token: &Token) -> PResult<(Ps, Prec)> {
|
||||
TKind::While => (Ps::Op(Op::While), Prec::Body),
|
||||
TKind::Break => (Ps::Op(Op::Break), 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::RCurly => (Ps::End, Prec::Do),
|
||||
@@ -266,6 +267,7 @@ impl<'t> Parse<'t> for Expr {
|
||||
Some(value) => Expr::Op(Op::Group, vec![value]),
|
||||
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)) => {
|
||||
p.consume();
|
||||
let exprs = vec![
|
||||
|
||||
@@ -67,6 +67,7 @@ pub enum TKind {
|
||||
As,
|
||||
Break,
|
||||
Const,
|
||||
Continue,
|
||||
Do,
|
||||
Else,
|
||||
Enum,
|
||||
|
||||
Reference in New Issue
Block a user