1
0

Rename function node to anonymous function

This commit is contained in:
Jeff 2024-02-22 23:15:58 -05:00
parent 6b88fbf8b9
commit eed9a780e5
11 changed files with 251 additions and 251 deletions

View File

@ -9,7 +9,7 @@ use crate::{
}; };
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct FunctionNode { pub struct AnonymousFunction {
parameters: Vec<Identifier>, parameters: Vec<Identifier>,
body: Block, body: Block,
r#type: Type, r#type: Type,
@ -19,7 +19,7 @@ pub struct FunctionNode {
context: Context, context: Context,
} }
impl FunctionNode { impl AnonymousFunction {
pub fn parameters(&self) -> &Vec<Identifier> { pub fn parameters(&self) -> &Vec<Identifier> {
&self.parameters &self.parameters
} }
@ -51,7 +51,7 @@ impl FunctionNode {
} }
} }
impl AbstractTree for FunctionNode { impl AbstractTree for AnonymousFunction {
fn from_syntax(node: SyntaxNode, source: &str, context: &Context) -> Result<Self, SyntaxError> { fn from_syntax(node: SyntaxNode, source: &str, context: &Context) -> Result<Self, SyntaxError> {
SyntaxError::expect_syntax_node("function", node)?; SyntaxError::expect_syntax_node("function", node)?;
@ -86,7 +86,7 @@ impl AbstractTree for FunctionNode {
let r#type = Type::function(parameter_types, return_type.take_inner()); let r#type = Type::function(parameter_types, return_type.take_inner());
let syntax_position = node.range().into(); let syntax_position = node.range().into();
Ok(FunctionNode { Ok(AnonymousFunction {
parameters, parameters,
body, body,
r#type, r#type,
@ -141,7 +141,7 @@ impl AbstractTree for FunctionNode {
} }
} }
impl Format for FunctionNode { impl Format for AnonymousFunction {
fn format(&self, output: &mut String, indent_level: u8) { fn format(&self, output: &mut String, indent_level: u8) {
let (parameter_types, return_type) = if let Type::Function { let (parameter_types, return_type) = if let Type::Function {
parameter_types, parameter_types,
@ -169,7 +169,7 @@ impl Format for FunctionNode {
} }
} }
impl Display for FunctionNode { impl Display for AnonymousFunction {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let mut string = String::new(); let mut string = String::new();

View File

@ -1,6 +1,7 @@
//! Abstract, executable representations of corresponding items found in Dust //! Abstract, executable representations of corresponding items found in Dust
//! source code. The types that implement [AbstractTree] are inteded to be //! source code. The types that implement [AbstractTree] are inteded to be
//! created by an [Interpreter]. //! created by an [Interpreter].
pub mod anonymous_function;
pub mod r#as; pub mod r#as;
pub mod assignment; pub mod assignment;
pub mod assignment_operator; pub mod assignment_operator;
@ -12,7 +13,6 @@ pub mod expression;
pub mod r#for; pub mod r#for;
pub mod function_call; pub mod function_call;
pub mod function_expression; pub mod function_expression;
pub mod function_node;
pub mod identifier; pub mod identifier;
pub mod if_else; pub mod if_else;
pub mod index; pub mod index;
@ -34,8 +34,8 @@ pub mod value_node;
pub mod r#while; pub mod r#while;
pub use { pub use {
assignment::*, assignment_operator::*, block::*, command::*, enum_defintion::*, anonymous_function::*, assignment::*, assignment_operator::*, block::*, command::*,
enum_pattern::*, expression::*, function_call::*, function_expression::*, function_node::*, enum_defintion::*, enum_pattern::*, expression::*, function_call::*, function_expression::*,
identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*, identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*,
logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, r#as::*, logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, r#as::*,
r#for::*, r#match::*, r#type::*, r#while::*, statement::*, struct_definition::*, r#for::*, r#match::*, r#type::*, r#while::*, statement::*, struct_definition::*,

View File

@ -5,7 +5,7 @@ use tree_sitter::Node as SyntaxNode;
use crate::{ use crate::{
error::{RuntimeError, SyntaxError, ValidationError}, error::{RuntimeError, SyntaxError, ValidationError},
AbstractTree, Context, Expression, Format, Function, FunctionNode, AbstractTree, Context, Expression, Format, Function, AnonymousFunction,
Identifier, List, Type, Value, TypeDefinition, MapNode, Identifier, List, Type, Value, TypeDefinition, MapNode,
}; };
@ -39,7 +39,7 @@ impl AbstractTree for ValueNode {
"boolean" => ValueNode::Boolean(source[child.byte_range()].to_string()), "boolean" => ValueNode::Boolean(source[child.byte_range()].to_string()),
"float" => ValueNode::Float(source[child.byte_range()].to_string()), "float" => ValueNode::Float(source[child.byte_range()].to_string()),
"function" => { "function" => {
let function_node = FunctionNode::from_syntax(child, source, context)?; let function_node = AnonymousFunction::from_syntax(child, source, context)?;
ValueNode::Function(Function::ContextDefined(function_node)) ValueNode::Function(Function::ContextDefined(function_node))
} }

View File

@ -3,13 +3,13 @@ use std::fmt::{self, Display, Formatter};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
built_in_functions::Callable, BuiltInFunction, Format, FunctionNode, Identifier, Type, built_in_functions::Callable, AnonymousFunction, BuiltInFunction, Format, Identifier, Type,
}; };
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Function { pub enum Function {
BuiltIn(BuiltInFunction), BuiltIn(BuiltInFunction),
ContextDefined(FunctionNode), ContextDefined(AnonymousFunction),
} }
impl Function { impl Function {

View File

@ -22,7 +22,7 @@ fib = (i <int>) <int> {
(statement_kind (statement_kind
(expression (expression
(value (value
(function (anonymous_function
(identifier) (identifier)
(type_specification (type_specification
(type)) (type))

View File

@ -11,7 +11,7 @@ Anonymous Function
(statement_kind (statement_kind
(expression (expression
(value (value
(function (anonymous_function
(type_specification (type_specification
(type)) (type))
(block (block
@ -41,7 +41,7 @@ foobar = (x <int>, y <int>) <int> {
(statement_kind (statement_kind
(expression (expression
(value (value
(function (anonymous_function
(identifier) (identifier)
(type_specification (type_specification
(type)) (type))
@ -139,7 +139,7 @@ Anonymous Function Call
(function_call (function_call
(function_expression (function_expression
(value (value
(function (anonymous_function
(identifier) (identifier)
(type_specification (type_specification
(type)) (type))
@ -215,7 +215,7 @@ x(() <bool> { true })
(identifier)) (identifier))
(expression (expression
(value (value
(function (anonymous_function
(type_specification (type_specification
(type)) (type))
(block (block

View File

@ -138,7 +138,7 @@ module.exports = grammar({
value: $ => value: $ =>
choice( choice(
$.function, $.anonymous_function,
$.integer, $.integer,
$.float, $.float,
$.string, $.string,
@ -429,7 +429,7 @@ module.exports = grammar({
), ),
), ),
function: $ => anonymous_function: $ =>
seq( seq(
'(', '(',
repeat( repeat(

View File

@ -390,7 +390,7 @@
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "function" "name": "anonymous_function"
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
@ -1311,7 +1311,7 @@
] ]
} }
}, },
"function": { "anonymous_function": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {

View File

@ -1,4 +1,27 @@
[ [
{
"type": "anonymous_function",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "block",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "type_specification",
"named": true
}
]
}
},
{ {
"type": "as_node", "type": "as_node",
"named": true, "named": true,
@ -267,29 +290,6 @@
] ]
} }
}, },
{
"type": "function",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "block",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "type_specification",
"named": true
}
]
}
},
{ {
"type": "function_call", "type": "function_call",
"named": true, "named": true,
@ -852,6 +852,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "anonymous_function",
"named": true
},
{ {
"type": "boolean", "type": "boolean",
"named": true "named": true
@ -864,10 +868,6 @@
"type": "float", "type": "float",
"named": true "named": true
}, },
{
"type": "function",
"named": true
},
{ {
"type": "integer", "type": "integer",
"named": true "named": true

File diff suppressed because it is too large Load Diff