added else, elseif, cleaned up
This commit is contained in:
parent
efaca55138
commit
eae6c61c24
4 changed files with 66 additions and 1 deletions
|
@ -15,6 +15,8 @@ pub enum ASTPart {
|
|||
VarUpdate(AstVarUpdate),
|
||||
Function(AstFunction),
|
||||
If(AstIf),
|
||||
ElseIf(AstElseIf),
|
||||
Else(AstElse),
|
||||
While(AstWhile),
|
||||
Break(AstBreak),
|
||||
For(AstFor),
|
||||
|
@ -83,6 +85,17 @@ pub struct AstIf {
|
|||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstElseIf {
|
||||
pub condition: Box<ASTPart>,
|
||||
pub body: Vec<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstElse {
|
||||
pub body: Vec<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstWhile {
|
||||
pub condition: Box<ASTPart>,
|
||||
pub body: Vec<ASTPart>,
|
||||
|
@ -455,6 +468,32 @@ fn next_operation(pos: &mut usize, input: &Vec<Token>, op_ends: &Vec<Token>, par
|
|||
return ASTPart::For(AstFor { init: Box::new(init[0].clone()), condition: Box::new(condition), update: Box::new(update[0].clone()), body: real_body, pos: token.pos });
|
||||
} else if token.value == "szard le" {
|
||||
return ASTPart::Continue(AstContinue { pos: token.pos });
|
||||
} else if token.value == "ha nem geny akkor geny" {
|
||||
if next_token.typ != TokenType::SEPARATOR || next_token.value != "(" {
|
||||
panic!("Expected ( at {}", token.pos);
|
||||
}
|
||||
*pos += 1;
|
||||
let condition_end = vec![
|
||||
Token { typ: TokenType::SEPARATOR, value: String::from(")"), pos: 0 }
|
||||
];
|
||||
let condition = read_exp(pos, input, &condition_end, &condition_end);
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != ")" {
|
||||
panic!("Unexpected end of condition at {}", token.pos);
|
||||
}
|
||||
*pos += 1;
|
||||
let body = read_function(input, pos, false);
|
||||
let real_body = match body {
|
||||
ASTPart::Function(func) => func.body,
|
||||
_ => panic!("Expected function body at {}", token.pos)
|
||||
};
|
||||
return ASTPart::ElseIf(AstElseIf { condition: Box::new(condition), body: real_body, pos: token.pos });
|
||||
} else if token.value == "ha nem geny" {
|
||||
let body = read_function(input, pos, false);
|
||||
let real_body = match body {
|
||||
ASTPart::Function(func) => func.body,
|
||||
_ => panic!("Expected function body at {}", token.pos)
|
||||
};
|
||||
return ASTPart::Else(AstElse { body: real_body, pos: token.pos });
|
||||
} else {
|
||||
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue