added return to the parser
This commit is contained in:
parent
aa57551763
commit
83e7238de4
3 changed files with 19 additions and 5 deletions
|
@ -100,6 +100,11 @@ fn log_ast_part(part: &ASTPart, prefix: String) {
|
|||
},
|
||||
ASTPart::Continue(cnt) => println!("{}{}: Continue", prefix, cnt.pos),
|
||||
ASTPart::RustFunction(func) => println!("{}{}: Rust Function", prefix, func.pos),
|
||||
ASTPart::Return(ret) => {
|
||||
println!("{}{}: Return", prefix, ret.pos);
|
||||
println!("{} Value:", prefix);
|
||||
log_ast_part(&ret.value, format!("{} ", prefix));
|
||||
}
|
||||
ASTPart::NOOP => println!("{}NOOP", prefix)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ pub enum ASTPart {
|
|||
Break(AstBreak),
|
||||
For(AstFor),
|
||||
Continue(AstContinue),
|
||||
Return(AstReturn),
|
||||
RustFunction(AstRustFunction),
|
||||
NOOP
|
||||
}
|
||||
|
@ -119,6 +120,11 @@ pub struct AstContinue {
|
|||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstReturn {
|
||||
pub value: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstRustFunction {
|
||||
pub func: fn(&mut Executor, Vec<ASTPart>) -> ASTPart,
|
||||
pub pos: usize
|
||||
|
@ -515,6 +521,13 @@ fn next_operation(pos: &mut usize, input: &Vec<Token>, op_ends: &Vec<Token>, par
|
|||
_ => panic!("Expected function body at {}", token.pos)
|
||||
};
|
||||
return ASTPart::Else(AstElse { body: real_body, pos: token.pos });
|
||||
} else if token.value == "reti" {
|
||||
if is_end(next_token, op_ends) || is_end(next_token, parse_ends) {
|
||||
return ASTPart::Return(AstReturn { value: Box::new(ASTPart::Null(AstNull { pos: token.pos })), pos: token.pos });
|
||||
} else {
|
||||
let value = read_exp(pos, input, op_ends, parse_ends);
|
||||
return ASTPart::Return(AstReturn { value: Box::new(value), pos: token.pos });
|
||||
}
|
||||
} else {
|
||||
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue