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::Continue(cnt) => println!("{}{}: Continue", prefix, cnt.pos),
|
||||||
ASTPart::RustFunction(func) => println!("{}{}: Rust Function", prefix, func.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)
|
ASTPart::NOOP => println!("{}NOOP", prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub enum ASTPart {
|
||||||
Break(AstBreak),
|
Break(AstBreak),
|
||||||
For(AstFor),
|
For(AstFor),
|
||||||
Continue(AstContinue),
|
Continue(AstContinue),
|
||||||
|
Return(AstReturn),
|
||||||
RustFunction(AstRustFunction),
|
RustFunction(AstRustFunction),
|
||||||
NOOP
|
NOOP
|
||||||
}
|
}
|
||||||
|
@ -119,6 +120,11 @@ pub struct AstContinue {
|
||||||
pub pos: usize
|
pub pos: usize
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct AstReturn {
|
||||||
|
pub value: Box<ASTPart>,
|
||||||
|
pub pos: usize
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct AstRustFunction {
|
pub struct AstRustFunction {
|
||||||
pub func: fn(&mut Executor, Vec<ASTPart>) -> ASTPart,
|
pub func: fn(&mut Executor, Vec<ASTPart>) -> ASTPart,
|
||||||
pub pos: usize
|
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)
|
_ => panic!("Expected function body at {}", token.pos)
|
||||||
};
|
};
|
||||||
return ASTPart::Else(AstElse { body: real_body, pos: 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 {
|
} else {
|
||||||
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
||||||
}
|
}
|
||||||
|
|
6
test.as
6
test.as
|
@ -1,5 +1 @@
|
||||||
ha geny (1==1) {
|
reti 1
|
||||||
|
|
||||||
} ha nem geny akkor geny (2==2) {
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue