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::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}")
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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![
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ pub enum TKind {
|
|||||||
As,
|
As,
|
||||||
Break,
|
Break,
|
||||||
Const,
|
Const,
|
||||||
|
Continue,
|
||||||
Do,
|
Do,
|
||||||
Else,
|
Else,
|
||||||
Enum,
|
Enum,
|
||||||
|
|||||||
Reference in New Issue
Block a user