forked from AbleScript/ablescript
Tidy up
This commit is contained in:
parent
ca60f818eb
commit
eef7ec16fa
|
@ -1 +1 @@
|
|||
a(3,)
|
||||
1 + 4
|
|
@ -35,6 +35,12 @@ pub enum Expr {
|
|||
iden: Iden,
|
||||
args: Vec<Expr>,
|
||||
},
|
||||
|
||||
Addition {
|
||||
left: Box<Expr>,
|
||||
right: Box<Expr>,
|
||||
},
|
||||
|
||||
Literal(Value),
|
||||
Identifier(Iden),
|
||||
Melo(Iden),
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
/// Parse operations (got identifier/value)
|
||||
pub(super) fn parse_ops(&mut self, token: Token) -> Result<Expr, Error> {
|
||||
let iden = if let Token::Identifier(i) = token {
|
||||
Iden(i)
|
||||
|
@ -20,9 +19,11 @@ impl<'a> Parser<'a> {
|
|||
Ok(buf[0].clone())
|
||||
}
|
||||
|
||||
/// Parse function call
|
||||
fn fn_call(&mut self, iden: Iden) -> Result<Expr, Error> {
|
||||
self.lexer.next();
|
||||
let mut args: Vec<Expr> = Vec::new();
|
||||
|
||||
while let Some(token) = self.lexer.peek() {
|
||||
match token {
|
||||
Token::Identifier(id) => {
|
||||
|
@ -38,9 +39,6 @@ impl<'a> Parser<'a> {
|
|||
self.require(Token::Comma)?;
|
||||
}
|
||||
self.require(Token::RightParenthesis)?;
|
||||
Ok(Expr::FunctionCall {
|
||||
iden,
|
||||
args,
|
||||
})
|
||||
Ok(Expr::FunctionCall { iden, args })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Require an identifier on next and return it
|
||||
pub(super) fn require_iden(&mut self) -> Result<String, Error> {
|
||||
if let Some(Token::Identifier(id)) = self.lexer.next() {
|
||||
Ok(id)
|
||||
|
@ -41,6 +42,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Throw unexpected token error (optionally what was expected)
|
||||
pub(super) fn unexpected_token(&mut self, expected: Option<Token>) -> Error {
|
||||
let error_msg = match expected {
|
||||
Some(s) => format!(
|
||||
|
|
Loading…
Reference in a new issue