Function call with var path

This commit is contained in:
2026-04-14 03:31:13 +02:00
parent 9ced12933a
commit a914892fc1
3 changed files with 36 additions and 4 deletions
+18 -1
View File
@@ -43,4 +43,21 @@ expr_stmt = { expr ~ ";" }
// ================= EXPRESSIONS ================= // ================= EXPRESSIONS =================
type_expr = { identifier } 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
}
+17 -2
View File
@@ -169,10 +169,11 @@ impl Statement {
impl Expression { impl Expression {
pub fn from_pair(pair: pest::iterators::Pair<Rule>) -> Self { pub fn from_pair(pair: pest::iterators::Pair<Rule>) -> Self {
match pair.as_rule() { match pair.as_rule() {
Rule::expr => { Rule::expr | Rule::term => {
let inner = pair.into_inner().next().unwrap(); let inner = pair.into_inner().next().unwrap();
Expression::from_pair(inner) Expression::from_pair(inner)
} }
Rule::var_path => Expression::Identifier(pair.as_str().to_string()),
Rule::identifier => Expression::Identifier(pair.as_str().to_string()), Rule::identifier => Expression::Identifier(pair.as_str().to_string()),
Rule::integer => { Rule::integer => {
let value = pair.as_str().parse::<i64>().unwrap(); let value = pair.as_str().parse::<i64>().unwrap();
@@ -190,7 +191,21 @@ impl Expression {
let inner_str = pair.into_inner().next().unwrap().as_str(); let inner_str = pair.into_inner().next().unwrap().as_str();
Expression::StringLiteral(inner_str.to_string()) 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()
),
} }
} }
} }
+1 -1
View File
@@ -6,5 +6,5 @@ struct Point {
} }
function add(a: int, b: int): int { function add(a: int, b: int): int {
do_something; idk.do_something();
} }