added table set
This commit is contained in:
parent
7276312961
commit
9a915cd274
4 changed files with 52 additions and 5 deletions
|
@ -22,6 +22,7 @@ pub enum ASTPart {
|
|||
Return(AstReturn),
|
||||
Table(AstTable),
|
||||
TableGet(AstTableGet),
|
||||
TableSet(AstTableSet),
|
||||
NOOP
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -140,6 +141,13 @@ pub struct AstTableGet {
|
|||
pub key: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstTableSet {
|
||||
pub table: Box<ASTPart>,
|
||||
pub key: Box<ASTPart>,
|
||||
pub value: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
|
||||
fn is_end(input: &Token, end: &Vec<Token>) -> bool {
|
||||
for token in end {
|
||||
|
@ -629,6 +637,31 @@ fn next_operation(pos: &mut usize, input: &Vec<Token>, op_ends: &Vec<Token>, par
|
|||
if next_token.typ == TokenType::SEPARATOR && next_token.value == "(" {
|
||||
let var = ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: token.pos });
|
||||
return read_call(var, pos, input);
|
||||
} else if next_token.typ == TokenType::SEPARATOR && next_token.value == "[" {
|
||||
*pos += 1;
|
||||
let key_ends: Vec<Token> = vec![
|
||||
Token { typ: TokenType::SEPARATOR, value: String::from("]"), pos: 0 }
|
||||
];
|
||||
let keyy = read_exp(pos, input, &key_ends, &key_ends);
|
||||
match keyy {
|
||||
ASTPart::Table(_) => {
|
||||
panic!("Table keys cannot be tables at {}", input[*pos].pos);
|
||||
},
|
||||
ASTPart::Function(_) => {
|
||||
panic!("Table keys cannot be functions at {}", input[*pos].pos);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != "]" {
|
||||
panic!("Unexpected end of key at {}", input[*pos].pos);
|
||||
}
|
||||
*pos += 1;
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != "=" {
|
||||
panic!("Expected = after key at {}", input[*pos].pos);
|
||||
}
|
||||
*pos += 1;
|
||||
let value = read_exp(pos, input, op_ends, parse_ends);
|
||||
return ASTPart::TableSet(AstTableSet { table: Box::new(ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: token.pos })), key: Box::new(keyy), value: Box::new(value), pos: token.pos });
|
||||
} else if next_token.typ == TokenType::SEPARATOR && next_token.value == "=" {
|
||||
*pos += 1;
|
||||
let value = read_exp(pos, input, op_ends, parse_ends);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue