Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,7 @@ impl SyntaxAnalysis<'_> {
) -> anyhow::Result<Expression> {
debug!("Parsing a call expression.");

// check call expression was correctly called by an identifier on inlined function.
match &function {
Expression::Identifier { identifier: _ } => {}
Expression::Function {
parameters: _,
block: _,
} => {}
_ => {
anyhow::bail!(
"A call expression is not calling either an identifier or an inlined function."
);
}
}

// parse call expression
// Callability is a runtime concern, the evaluator rejects uncallable objects.
let arguments = self.parse_comma_separated_list("call expression's arguments", Ok)?;

Ok(Expression::Call {
Expand Down
9 changes: 9 additions & 0 deletions src/tests/call_expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ use super::*;
case(
"let add = fn(x, y) { x + y }; add(1, add(2, 3));",
"call_expression_case_5"
),
case("fn(x) { fn(y) { y } }(1)(2);", "call_expression_case_6"),
case(
"let curried = fn(x) { fn(y) { y } }; curried(1)(2);",
"call_expression_case_7"
),
case(
"fn(x) { fn(y) { fn(z) { z * 2 } } }(1)(2)(3);",
"call_expression_case_8"
)
)]
fn call_expression_cases(code: &str, snapshot_name: &str) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: src/tests/call_expression/mod.rs
expression: evaluator
---
Evaluator {
environment: Environment {
variables: {},
sub_environment: None,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: src/tests/call_expression/mod.rs
expression: evaluation
---
Integer {
value: 2,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: src/tests/call_expression/mod.rs
expression: tokens
---
[
Function,
OpeningRoundBracket,
Identifier {
literal: "x",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Function,
OpeningRoundBracket,
Identifier {
literal: "y",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Identifier {
literal: "y",
},
ClosingCurlyBracket,
ClosingCurlyBracket,
OpeningRoundBracket,
Integer {
literal: 1,
},
ClosingRoundBracket,
OpeningRoundBracket,
Integer {
literal: 2,
},
ClosingRoundBracket,
SemiColon,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
source: src/tests/call_expression/mod.rs
expression: abstract_syntax_tree
---
[
Expression {
expression: Call {
function: Call {
function: Function {
parameters: [
"x",
],
block: Block {
nodes: [
Expression {
expression: Function {
parameters: [
"y",
],
block: Block {
nodes: [
Expression {
expression: Identifier {
identifier: "y",
},
},
],
},
},
},
],
},
},
arguments: [
Integer {
literal: 1,
},
],
},
arguments: [
Integer {
literal: 2,
},
],
},
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: src/tests/call_expression/mod.rs
expression: evaluator
---
Evaluator {
environment: Environment {
variables: {
"curried": Function {
parameters: [
"x",
],
block: Block {
nodes: [
Expression {
expression: Function {
parameters: [
"y",
],
block: Block {
nodes: [
Expression {
expression: Identifier {
identifier: "y",
},
},
],
},
},
},
],
},
},
},
sub_environment: None,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: src/tests/call_expression/mod.rs
expression: evaluation
---
Integer {
value: 2,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
source: src/tests/call_expression/mod.rs
expression: tokens
---
[
Let,
Identifier {
literal: "curried",
},
Assign,
Function,
OpeningRoundBracket,
Identifier {
literal: "x",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Function,
OpeningRoundBracket,
Identifier {
literal: "y",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Identifier {
literal: "y",
},
ClosingCurlyBracket,
ClosingCurlyBracket,
SemiColon,
Identifier {
literal: "curried",
},
OpeningRoundBracket,
Integer {
literal: 1,
},
ClosingRoundBracket,
OpeningRoundBracket,
Integer {
literal: 2,
},
ClosingRoundBracket,
SemiColon,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
source: src/tests/call_expression/mod.rs
expression: abstract_syntax_tree
---
[
Statement {
statement: Let {
identifier: "curried",
expression: Function {
parameters: [
"x",
],
block: Block {
nodes: [
Expression {
expression: Function {
parameters: [
"y",
],
block: Block {
nodes: [
Expression {
expression: Identifier {
identifier: "y",
},
},
],
},
},
},
],
},
},
},
},
Expression {
expression: Call {
function: Call {
function: Identifier {
identifier: "curried",
},
arguments: [
Integer {
literal: 1,
},
],
},
arguments: [
Integer {
literal: 2,
},
],
},
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: src/tests/call_expression/mod.rs
expression: evaluator
---
Evaluator {
environment: Environment {
variables: {},
sub_environment: None,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: src/tests/call_expression/mod.rs
expression: evaluation
---
Integer {
value: 6,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
source: src/tests/call_expression/mod.rs
expression: tokens
---
[
Function,
OpeningRoundBracket,
Identifier {
literal: "x",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Function,
OpeningRoundBracket,
Identifier {
literal: "y",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Function,
OpeningRoundBracket,
Identifier {
literal: "z",
},
ClosingRoundBracket,
OpeningCurlyBracket,
Identifier {
literal: "z",
},
Multiply,
Integer {
literal: 2,
},
ClosingCurlyBracket,
ClosingCurlyBracket,
ClosingCurlyBracket,
OpeningRoundBracket,
Integer {
literal: 1,
},
ClosingRoundBracket,
OpeningRoundBracket,
Integer {
literal: 2,
},
ClosingRoundBracket,
OpeningRoundBracket,
Integer {
literal: 3,
},
ClosingRoundBracket,
SemiColon,
]
Loading
Loading