Skip to content

Commit 994a253

Browse files
committed
Add calls
1 parent ab7f142 commit 994a253

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

takolib/src/ast/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ impl Ast {
7070
}
7171
eq
7272
}
73+
pub fn add_args(&mut self, node_id: NodeId, args: SmallVec<NodeId, CALL_ARGS_STANDARD_ITEM_NUM>) -> NodeId {
74+
let location = self[node_id].location;
75+
let id = self[node_id].id.clone();
76+
match id {
77+
NodeData::Identifier(_) | NodeData::Call(_) => {
78+
let call = Call {
79+
inner: node_id,
80+
args,
81+
};
82+
self.add_call(call, location)
83+
}
84+
node => todo!("Assignment to non definition head support: {node:?}"),
85+
}
86+
}
7387
pub fn add_implementation(&mut self, node_id: NodeId, imp: NodeId) -> NodeId {
7488
use crate::parser::semantics::BindingMode;
7589
let location = self[node_id].location;

takolib/src/ast/nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::parser::tokens::Symbol;
66
use smallvec::SmallVec;
77

88
pub const OP_ARGS_STANDARD_ITEM_NUM: usize = 2;
9-
pub const CALL_ARGS_STANDARD_ITEM_NUM: usize = 5;
9+
pub const CALL_ARGS_STANDARD_ITEM_NUM: usize = 2;
1010
pub const FMT_STR_STANDARD_ITEM_NUM: usize = 2; // TODO: Convert to a different store
1111

1212
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

takolib/src/parser/mod.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn language<'src, 'ast>() -> impl Parser<'src, &'src [Token], (), ParserConfig<'
174174
.labelled("an ordered set of values");
175175

176176
let unordered_container = op(Symbol::OpenCurly)
177-
.then(many)
177+
.then(many.clone())
178178
.then(op(Symbol::CloseCurly))
179179
.map_with(|((open, nodes), _close), extra| {
180180
let ast: &mut Ast = std::ops::DerefMut::deref_mut(extra.state());
@@ -236,13 +236,8 @@ fn language<'src, 'ast>() -> impl Parser<'src, &'src [Token], (), ParserConfig<'
236236
};
237237

238238
/*
239-
Source: https://www.foonathan.net/2017/07/operator-precedence/
240-
Inside the categories the relative precedence of the operators is as follows:
241-
logical operators: ! > &&,||, but not mixed && and || chains
242-
comparison operators: no chaining at all
243-
mathematical operators: unary +,- > *,/ > +,-, with the usual associativity
244-
bitwise operators: unary ~ before the binary operators, but again no mixed chaining of &, | and ^ and no chaining of the shift operators
245-
unary operators: just as usual
239+
For reference, some interesting ideas about partial ordering of precedences:
240+
- https://www.foonathan.net/2017/07/operator-precedence/
246241
*/
247242

248243
use Symbol::*;
@@ -308,9 +303,23 @@ fn language<'src, 'ast>() -> impl Parser<'src, &'src [Token], (), ParserConfig<'
308303
// postfix_op(11, Try),
309304
// infix_op(left(9), DoubleArrow),
310305
// infix_op(left(8), Arrow),
306+
let params = many
307+
.clone()
308+
.delimited_by(op(Symbol::OpenParen), op(Symbol::CloseParen))
309+
.labelled("a set of parameters");
310+
311+
let callable = expr
312+
.clone()
313+
.then(params)
314+
.map_with(|(lhs, rhs), extra| {
315+
let ast: &mut Ast = std::ops::DerefMut::deref_mut(extra.state());
316+
ast.add_args(lhs, rhs)
317+
})
318+
.labelled("a callable");
311319

312320
let expr = math_expr
313321
.clone()
322+
.or(callable)
314323
.or(boolean_expr)
315324
.or(comparison)
316325
.or(lshift_expr)

0 commit comments

Comments
 (0)