While loop
This commit is contained in:
parent
1f66a5f94b
commit
0f90e8108c
|
@ -15,9 +15,10 @@ pub enum Token {
|
||||||
#[token("struct")] Struct,
|
#[token("struct")] Struct,
|
||||||
#[token("fn")] Function,
|
#[token("fn")] Function,
|
||||||
#[token("for")] For,
|
#[token("for")] For,
|
||||||
|
#[token("in")] In,
|
||||||
|
#[token("while")] While,
|
||||||
#[token("if")] If,
|
#[token("if")] If,
|
||||||
#[token("else")] Else,
|
#[token("else")] Else,
|
||||||
#[token("in")] In,
|
|
||||||
#[token("let")] Let,
|
#[token("let")] Let,
|
||||||
#[token("mut")] Mut,
|
#[token("mut")] Mut,
|
||||||
#[token("interface")] Interface,
|
#[token("interface")] Interface,
|
||||||
|
|
18
src/parse.rs
18
src/parse.rs
|
@ -317,6 +317,20 @@ impl<'a> BranchBody<'a> {
|
||||||
next = Some(tail);
|
next = Some(tail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Token::While => {
|
||||||
|
let test_expr = match Expr::build(lexer) {
|
||||||
|
(Some(test_expr), Token::BraceOpen) => test_expr,
|
||||||
|
(Some(_), _) => lexer.panic_message("Expected opening brace"),
|
||||||
|
_ => lexer.panic_message("Expected test expression"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let loop_body = BranchBody::build(lexer);
|
||||||
|
|
||||||
|
statements.push(Statement::While {
|
||||||
|
test_expr,
|
||||||
|
loop_body,
|
||||||
|
});
|
||||||
|
}
|
||||||
Token::BraceClose => break None,
|
Token::BraceClose => break None,
|
||||||
_ => match Expr::build_start(tok, lexer) {
|
_ => match Expr::build_start(tok, lexer) {
|
||||||
(None, Token::Semicolon | Token::BraceClose) => {}
|
(None, Token::Semicolon | Token::BraceClose) => {}
|
||||||
|
@ -516,6 +530,10 @@ pub enum Literal<'a> {
|
||||||
pub enum Statement<'a> {
|
pub enum Statement<'a> {
|
||||||
Expr(Expr<'a>),
|
Expr(Expr<'a>),
|
||||||
If(IfStmt<'a>),
|
If(IfStmt<'a>),
|
||||||
|
While {
|
||||||
|
test_expr: Expr<'a>,
|
||||||
|
loop_body: BranchBody<'a>,
|
||||||
|
},
|
||||||
Let {
|
Let {
|
||||||
var: &'a str,
|
var: &'a str,
|
||||||
mutable: bool,
|
mutable: bool,
|
||||||
|
|
Loading…
Reference in New Issue