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)]
pub struct FunctionNode {
pub struct AnonymousFunction {
parameters: Vec<Identifier>,
body: Block,
r#type: Type,
@ -19,7 +19,7 @@ pub struct FunctionNode {
context: Context,
}
impl FunctionNode {
impl AnonymousFunction {
pub fn parameters(&self) -> &Vec<Identifier> {
&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> {
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 syntax_position = node.range().into();
Ok(FunctionNode {
Ok(AnonymousFunction {
parameters,
body,
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) {
let (parameter_types, return_type) = if let Type::Function {
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 {
let mut string = String::new();

View File

@ -1,6 +1,7 @@
//! Abstract, executable representations of corresponding items found in Dust
//! source code. The types that implement [AbstractTree] are inteded to be
//! created by an [Interpreter].
pub mod anonymous_function;
pub mod r#as;
pub mod assignment;
pub mod assignment_operator;
@ -12,7 +13,6 @@ pub mod expression;
pub mod r#for;
pub mod function_call;
pub mod function_expression;
pub mod function_node;
pub mod identifier;
pub mod if_else;
pub mod index;
@ -34,8 +34,8 @@ pub mod value_node;
pub mod r#while;
pub use {
assignment::*, assignment_operator::*, block::*, command::*, enum_defintion::*,
enum_pattern::*, expression::*, function_call::*, function_expression::*, function_node::*,
anonymous_function::*, assignment::*, assignment_operator::*, block::*, command::*,
enum_defintion::*, enum_pattern::*, expression::*, function_call::*, function_expression::*,
identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*,
logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, r#as::*,
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::{
error::{RuntimeError, SyntaxError, ValidationError},
AbstractTree, Context, Expression, Format, Function, FunctionNode,
AbstractTree, Context, Expression, Format, Function, AnonymousFunction,
Identifier, List, Type, Value, TypeDefinition, MapNode,
};
@ -39,7 +39,7 @@ impl AbstractTree for ValueNode {
"boolean" => ValueNode::Boolean(source[child.byte_range()].to_string()),
"float" => ValueNode::Float(source[child.byte_range()].to_string()),
"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))
}

View File

@ -3,13 +3,13 @@ use std::fmt::{self, Display, Formatter};
use serde::{Deserialize, Serialize};
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)]
pub enum Function {
BuiltIn(BuiltInFunction),
ContextDefined(FunctionNode),
ContextDefined(AnonymousFunction),
}
impl Function {

View File

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

View File

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

View File

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

View File

@ -390,7 +390,7 @@
"members": [
{
"type": "SYMBOL",
"name": "function"
"name": "anonymous_function"
},
{
"type": "SYMBOL",
@ -1311,7 +1311,7 @@
]
}
},
"function": {
"anonymous_function": {
"type": "SEQ",
"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",
"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",
"named": true,
@ -852,6 +852,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "anonymous_function",
"named": true
},
{
"type": "boolean",
"named": true
@ -864,10 +868,6 @@
"type": "float",
"named": true
},
{
"type": "function",
"named": true
},
{
"type": "integer",
"named": true

File diff suppressed because it is too large Load Diff