added imports
This commit is contained in:
parent
ce93fb10d4
commit
b4f930d1c5
8 changed files with 91 additions and 14 deletions
|
@ -25,6 +25,7 @@ pub enum ASTPart {
|
|||
Table(AstTable),
|
||||
TableGet(AstTableGet),
|
||||
TableSet(AstTableSet),
|
||||
Import(AstImport),
|
||||
NOOP
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -150,6 +151,11 @@ pub struct AstTableSet {
|
|||
pub value: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstImport {
|
||||
pub path: String,
|
||||
pub pos: usize
|
||||
}
|
||||
|
||||
fn is_end(input: &Token, end: &Vec<Token>) -> bool {
|
||||
for token in end {
|
||||
|
@ -786,6 +792,28 @@ fn next_operation(pos: &mut usize, input: &Vec<Token>, op_ends: &Vec<Token>, par
|
|||
let value = read_exp(pos, input, op_ends, parse_ends, ctx);
|
||||
return ASTPart::Return(AstReturn { value: Box::new(value), pos: token.pos });
|
||||
}
|
||||
} else if token.value == "hámozd" {
|
||||
let var = &input[*pos];
|
||||
*pos += 1;
|
||||
if var.typ != TokenType::IDENTIFIER {
|
||||
let err = create_error(&format!("Expected identifier after hámozd"), token.pos, ErrorType::SyntaxError, ErrorSubType::Expected);
|
||||
print_error(&err, &ctx);
|
||||
process::exit(1);
|
||||
}
|
||||
if input[*pos].typ != TokenType::KEYWORD || (input[*pos].value != "be" && input[*pos].value != "ba") {
|
||||
let err = create_error(&format!("Expected `be`/`ba` after hámozd"), input[*pos].pos, ErrorType::SyntaxError, ErrorSubType::Expected);
|
||||
print_error(&err, &ctx);
|
||||
process::exit(1);
|
||||
}
|
||||
*pos += 1;
|
||||
let path = &input[*pos];
|
||||
if path.typ != TokenType::STRING {
|
||||
let err = create_error(&format!("Expected string for hámozd"), path.pos, ErrorType::SyntaxError, ErrorSubType::Expected);
|
||||
print_error(&err, &ctx);
|
||||
process::exit(1);
|
||||
}
|
||||
*pos += 1;
|
||||
return ASTPart::Assigment(AstAssigment { variable: var.value.clone(), value: Box::new(ASTPart::Import(AstImport { path: path.value.clone(), pos: token.pos })), pos: token.pos });
|
||||
} else {
|
||||
let err = create_error(&format!("Unexpected `{:?}({})`", token.typ, token.value), token.pos, ErrorType::SyntaxError, ErrorSubType::Unexpected);
|
||||
print_error(&err, &ctx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue