Add array expression parsing
This commit is contained in:
parent
887071eeb6
commit
8f95d445c0
@ -1,7 +1,7 @@
|
||||
// Arithmetic, function calls and imports!
|
||||
|
||||
fn array() -> [u16; 4] {
|
||||
return true;
|
||||
return [1, 2, 3, 4];
|
||||
}
|
||||
|
||||
fn main() -> u16 {
|
||||
|
@ -38,6 +38,7 @@ pub struct Expression(pub ExpressionKind, pub TokenRange);
|
||||
pub enum ExpressionKind {
|
||||
VariableName(String),
|
||||
Literal(Literal),
|
||||
Array(Vec<Expression>),
|
||||
Binop(BinaryOperator, Box<Expression>, Box<Expression>),
|
||||
FunctionCall(Box<FunctionCallExpression>),
|
||||
BlockExpr(Box<Block>),
|
||||
|
@ -97,7 +97,19 @@ impl Parse for PrimaryExpression {
|
||||
stream.expect(Token::ParenClose)?;
|
||||
exp
|
||||
}
|
||||
_ => Err(stream.expected_err("identifier, constant or parentheses")?)?,
|
||||
Token::BracketOpen => {
|
||||
let mut expressions = Vec::new();
|
||||
if let Ok(exp) = stream.parse() {
|
||||
expressions.push(exp);
|
||||
while let Some(Token::Comma) = stream.peek() {
|
||||
stream.next(); // Consume comma
|
||||
expressions.push(stream.parse()?);
|
||||
}
|
||||
}
|
||||
stream.expect(Token::BracketClose)?;
|
||||
Expression(Kind::Array(expressions), stream.get_range().unwrap())
|
||||
}
|
||||
_ => Err(stream.expected_err("identifier, constant, parentheses or brackets")?)?,
|
||||
}
|
||||
} else {
|
||||
Err(stream.expected_err("expression")?)?
|
||||
|
@ -149,6 +149,7 @@ impl ast::Expression {
|
||||
};
|
||||
mir::ExprKind::If(mir::IfExpression(Box::new(cond), then_block, else_block))
|
||||
}
|
||||
ast::ExpressionKind::Array(expressions) => todo!(),
|
||||
};
|
||||
|
||||
mir::Expression(kind, self.1.into())
|
||||
|
Loading…
Reference in New Issue
Block a user