diff --git a/src/parser/grammar.pest b/src/parser/grammar.pest index 9c9afd5..8c62804 100644 --- a/src/parser/grammar.pest +++ b/src/parser/grammar.pest @@ -43,4 +43,21 @@ expr_stmt = { expr ~ ";" } // ================= EXPRESSIONS ================= type_expr = { identifier } -expr = { identifier | integer | float | boolean | string_lit } +var_path = { identifier ~ ("." ~ identifier)* } + +term = { + integer + | float + | boolean + | string_lit + | var_path +} + +func_call = { + var_path ~ "(" ~ (expr ~ ("," ~ expr)*)? ~ ")" +} + +expr = { + func_call + | term +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 9477df1..22721b4 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -169,10 +169,11 @@ impl Statement { impl Expression { pub fn from_pair(pair: pest::iterators::Pair) -> Self { match pair.as_rule() { - Rule::expr => { + Rule::expr | Rule::term => { let inner = pair.into_inner().next().unwrap(); Expression::from_pair(inner) } + Rule::var_path => Expression::Identifier(pair.as_str().to_string()), Rule::identifier => Expression::Identifier(pair.as_str().to_string()), Rule::integer => { let value = pair.as_str().parse::().unwrap(); @@ -190,7 +191,21 @@ impl Expression { let inner_str = pair.into_inner().next().unwrap().as_str(); Expression::StringLiteral(inner_str.to_string()) } - _ => unimplemented!("Expression parsing not implemented yet"), + + Rule::func_call => { + let mut inner = pair.into_inner(); + let callee = Expression::from_pair(inner.next().unwrap()); + let args = inner.map(Expression::from_pair).collect(); + Expression::FunctionCall { + callee: Box::new(callee), + args, + } + } + + _ => unimplemented!( + "Expression parsing not implemented yet {:?}", + pair.as_rule() + ), } } } diff --git a/test/src/main.ms b/test/src/main.ms index 3932a50..eb93632 100644 --- a/test/src/main.ms +++ b/test/src/main.ms @@ -6,5 +6,5 @@ struct Point { } function add(a: int, b: int): int { - do_something; + idk.do_something(); }