more function stuff
This commit is contained in:
parent
315ccc1504
commit
92a8cabcab
2 changed files with 42 additions and 1 deletions
|
@ -196,6 +196,36 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
|
|||
}
|
||||
return output[0].clone();
|
||||
}
|
||||
fn read_function(input: &Vec<Token>, pos: &mut usize, with_args: bool) -> ASTPart {
|
||||
let mut args: Vec<String> = vec![];
|
||||
if with_args {
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != "(" {
|
||||
panic!("Expected ( at {}", input[*pos].pos);
|
||||
}
|
||||
*pos += 1;
|
||||
while pos < &mut input.len() {
|
||||
let token = &input[*pos];
|
||||
if token.typ == TokenType::SEPARATOR && token.value == ")" {
|
||||
break;
|
||||
}
|
||||
*pos += 1;
|
||||
if token.typ == TokenType::SEPARATOR && token.value == "," {
|
||||
continue;
|
||||
}
|
||||
if token.typ == TokenType::IDENTIFIER {
|
||||
args.push(token.value.clone());
|
||||
} else {
|
||||
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
||||
}
|
||||
}
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != ")" {
|
||||
panic!("Unexpected end of arguments at {}", input[*pos].pos);
|
||||
}
|
||||
*pos += 1;
|
||||
}
|
||||
println!("Args: {:?}", args);
|
||||
return ASTPart::NOOP;
|
||||
}
|
||||
fn read_exp(pos: &mut usize, input: &Vec<Token>, ends: &Vec<Token>, parse_ends: &Vec<Token>) -> ASTPart {
|
||||
let mut expressions: Vec<ASTPart> = vec![];
|
||||
while pos < &mut input.len() {
|
||||
|
@ -227,7 +257,8 @@ fn read_exp(pos: &mut usize, input: &Vec<Token>, ends: &Vec<Token>, parse_ends:
|
|||
} else if token.value == "nincs hám" {
|
||||
expressions.push(ASTPart::Null(AstNull { pos: token.pos }));
|
||||
} else if token.value == "lőcsve" {
|
||||
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
||||
let func = read_function(input, pos, true);
|
||||
println!("Function: {:?}", func);
|
||||
} else {
|
||||
panic!("Unexpected {:?}({}) at {}", token.typ, token.value, token.pos);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue