basic if expression
This commit is contained in:
parent
0e4469fa58
commit
f421918945
@ -122,26 +122,36 @@ fn let_expression(input: &mut Tokens) -> ParseResult {
|
|||||||
|
|
||||||
fn expression(input: &mut Tokens) -> ParseResult {
|
fn expression(input: &mut Tokens) -> ParseResult {
|
||||||
let lookahead = input.peek().map(|i| i.clone());
|
let lookahead = input.peek().map(|i| i.clone());
|
||||||
println!("{:?}", lookahead);
|
|
||||||
match lookahead {
|
match lookahead {
|
||||||
Some(&Keyword(Kw::If)) => {
|
Some(&Keyword(Kw::If)) => {
|
||||||
input.next();
|
if_expression(input)
|
||||||
ParseResult::Ok( AST::IfStatement(
|
|
||||||
Box::new(AST::Number(1.0)),
|
|
||||||
Box::new(AST::Number(2.0)),
|
|
||||||
None))
|
|
||||||
},
|
},
|
||||||
|
_ => rhs(input)
|
||||||
_ => ParseResult::Err("error in expression()".to_string())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
fn if_expression(input: &mut Tokens) -> ParseResult {
|
fn if_expression(input: &mut Tokens) -> ParseResult {
|
||||||
|
|
||||||
|
expect!(Keyword(Kw::If), input);
|
||||||
|
let if_clause = match expression(input) {
|
||||||
|
err@ParseResult::Err(_) => return err,
|
||||||
|
ParseResult::Ok(ast) => ast
|
||||||
|
};
|
||||||
|
|
||||||
|
expect!(Keyword(Kw::Then), input);
|
||||||
|
|
||||||
|
let then_clause = match expression(input) {
|
||||||
|
err@ParseResult::Err(_) => return err,
|
||||||
|
ParseResult::Ok(ast) => ast
|
||||||
|
};
|
||||||
|
|
||||||
|
expect!(Keyword(Kw::End), input);
|
||||||
|
|
||||||
|
ParseResult::Ok( AST::IfStatement(
|
||||||
|
Box::new(if_clause),
|
||||||
|
Box::new(then_clause),
|
||||||
|
None))
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
fn rhs(input: &mut Tokens) -> ParseResult {
|
fn rhs(input: &mut Tokens) -> ParseResult {
|
||||||
let next = input.next();
|
let next = input.next();
|
||||||
|
Loading…
Reference in New Issue
Block a user