mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Add do-while statements
This commit is contained in:
parent
9b82622048
commit
0aae716b0c
2 changed files with 10 additions and 0 deletions
|
|
@ -300,5 +300,6 @@ pub enum Statement {
|
|||
Expr(Expression),
|
||||
Return(Option<Expression>),
|
||||
While(Expression, Vec<Statement>),
|
||||
DoWhile(Vec<Statement>, Expression),
|
||||
If(Vec<(Expression, Vec<Statement>)>, Option<Vec<Statement>>),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -546,6 +546,15 @@ impl<I> Parser<I> where
|
|||
let expr = require!(self.expression(false));
|
||||
require!(self.exact(Token::Punct(Punctuation::RParen)));
|
||||
success(Statement::While(expr, require!(self.block())))
|
||||
} else if let Some(()) = self.exact_ident("do")? {
|
||||
// statement :: 'do' block 'while' '(' expression ')' ';'
|
||||
let block = require!(self.block());
|
||||
require!(self.exact_ident("while"));
|
||||
require!(self.exact(Token::Punct(Punctuation::LParen)));
|
||||
let expr = require!(self.expression(false));
|
||||
require!(self.exact(Token::Punct(Punctuation::RParen)));
|
||||
require!(self.exact(Token::Punct(Punctuation::Semicolon)));
|
||||
success(Statement::DoWhile(block, expr))
|
||||
// SINGLE-LINE STATEMENTS
|
||||
} else if let Some(()) = self.exact_ident("return")? {
|
||||
// statement :: 'return' expression ';'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue