Extend function expression to values and indexes
This commit is contained in:
parent
17fa708739
commit
e10429e1e9
@ -112,6 +112,8 @@ impl AbstractTree for FunctionCall {
|
||||
FunctionExpression::FunctionCall(function_call) => {
|
||||
function_call.run(source, context)?
|
||||
}
|
||||
FunctionExpression::Value(value_node) => value_node.run(source, context)?,
|
||||
FunctionExpression::Index(index) => index.run(source, context)?,
|
||||
};
|
||||
|
||||
let mut arguments = Vec::with_capacity(self.arguments.len());
|
||||
@ -153,6 +155,8 @@ impl AbstractTree for FunctionCall {
|
||||
}
|
||||
}
|
||||
FunctionExpression::FunctionCall(function_call) => function_call.expected_type(context),
|
||||
FunctionExpression::Value(value_node) => value_node.expected_type(context),
|
||||
FunctionExpression::Index(index) => index.expected_type(context),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tree_sitter::Node;
|
||||
|
||||
use crate::{AbstractTree, Error, FunctionCall, Identifier, Map, Result, Type, Value};
|
||||
use crate::{
|
||||
AbstractTree, Error, FunctionCall, Identifier, Index, Map, Result, Type, Value, ValueNode,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
||||
pub enum FunctionExpression {
|
||||
Identifier(Identifier),
|
||||
FunctionCall(Box<FunctionCall>),
|
||||
Value(ValueNode),
|
||||
Index(Index),
|
||||
}
|
||||
|
||||
impl AbstractTree for FunctionExpression {
|
||||
@ -22,9 +26,13 @@ impl AbstractTree for FunctionExpression {
|
||||
"function_call" => FunctionExpression::FunctionCall(Box::new(
|
||||
FunctionCall::from_syntax_node(source, child, context)?,
|
||||
)),
|
||||
"value" => {
|
||||
FunctionExpression::Value(ValueNode::from_syntax_node(source, child, context)?)
|
||||
}
|
||||
"index" => FunctionExpression::Index(Index::from_syntax_node(source, child, context)?),
|
||||
_ => {
|
||||
return Err(Error::UnexpectedSyntaxNode {
|
||||
expected: "identifier or function call",
|
||||
expected: "identifier, function call, value or index",
|
||||
actual: child.kind(),
|
||||
location: child.start_position(),
|
||||
relevant_source: source[child.byte_range()].to_string(),
|
||||
@ -39,6 +47,8 @@ impl AbstractTree for FunctionExpression {
|
||||
match self {
|
||||
FunctionExpression::Identifier(identifier) => identifier.run(source, context),
|
||||
FunctionExpression::FunctionCall(function_call) => function_call.run(source, context),
|
||||
FunctionExpression::Value(value_node) => value_node.run(source, context),
|
||||
FunctionExpression::Index(index) => index.run(source, context),
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +56,8 @@ impl AbstractTree for FunctionExpression {
|
||||
match self {
|
||||
FunctionExpression::Identifier(identifier) => identifier.expected_type(context),
|
||||
FunctionExpression::FunctionCall(function_call) => function_call.expected_type(context),
|
||||
FunctionExpression::Value(value_node) => value_node.expected_type(context),
|
||||
FunctionExpression::Index(index) => index.expected_type(context),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,67 @@ Function Call
|
||||
(value
|
||||
(string)))))))
|
||||
|
||||
================================================================================
|
||||
Function Expressions
|
||||
================================================================================
|
||||
|
||||
(foobar "Hiya")
|
||||
(foo:bar "Hiya")
|
||||
((foobar) "Hiya")
|
||||
((fn msg <str>) <str> { msg } "Hiya")
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(identifier))
|
||||
(expression
|
||||
(value
|
||||
(string))))))
|
||||
(statement
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(index
|
||||
(expression
|
||||
(identifier))
|
||||
(expression
|
||||
(identifier))))
|
||||
(expression
|
||||
(value
|
||||
(string))))))
|
||||
(statement
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(identifier))))
|
||||
(expression
|
||||
(value
|
||||
(string))))))
|
||||
(statement
|
||||
(expression
|
||||
(function_call
|
||||
(function_expression
|
||||
(value
|
||||
(function
|
||||
(identifier)
|
||||
(type_definition
|
||||
(type))
|
||||
(type_definition
|
||||
(type))
|
||||
(block
|
||||
(statement
|
||||
(expression
|
||||
(identifier)))))))
|
||||
(expression
|
||||
(value
|
||||
(string)))))))
|
||||
|
||||
================================================================================
|
||||
Complex Function Call
|
||||
================================================================================
|
||||
|
@ -388,8 +388,10 @@ module.exports = grammar({
|
||||
|
||||
function_expression: $ =>
|
||||
choice(
|
||||
$.identifier,
|
||||
$.function_call,
|
||||
$.identifier,
|
||||
$.index,
|
||||
$.value,
|
||||
),
|
||||
|
||||
function_call: $ =>
|
||||
|
@ -1271,13 +1271,21 @@
|
||||
"function_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_call"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_call"
|
||||
"name": "index"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "value"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -209,6 +209,14 @@
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "index",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "value",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user