Roll back changes from 0.4.3
This commit is contained in:
parent
6b88fbf8b9
commit
2023e2c7e3
@ -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,9 +51,9 @@ 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)?;
|
||||
SyntaxError::expect_syntax_node("anonymous_function", node)?;
|
||||
|
||||
let child_count = node.child_count();
|
||||
let mut parameters = Vec::new();
|
||||
@ -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();
|
||||
|
@ -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::*,
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
@ -38,8 +38,8 @@ impl AbstractTree for ValueNode {
|
||||
let value_node = match child.kind() {
|
||||
"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)?;
|
||||
"anonymous_function" => {
|
||||
let function_node = AnonymousFunction::from_syntax(child, source, context)?;
|
||||
|
||||
ValueNode::Function(Function::ContextDefined(function_node))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -22,7 +22,7 @@ fib = (i <int>) <int> {
|
||||
(statement_kind
|
||||
(expression
|
||||
(value
|
||||
(function
|
||||
(anonymous_function
|
||||
(identifier)
|
||||
(type_specification
|
||||
(type))
|
||||
|
@ -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
|
||||
@ -247,3 +247,35 @@ from_json(read('file.json'))
|
||||
(expression
|
||||
(value
|
||||
(string))))))))))
|
||||
|
||||
================================================================================
|
||||
Function Definition
|
||||
================================================================================
|
||||
|
||||
fn foo<T> (bar <T>) <T> {
|
||||
bar
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(statement_kind
|
||||
(type_definition
|
||||
(function_definition
|
||||
(identifier)
|
||||
(type_arguments
|
||||
(type
|
||||
(identifier)))
|
||||
(identifier)
|
||||
(type_specification
|
||||
(type
|
||||
(identifier)))
|
||||
(type_specification
|
||||
(type
|
||||
(identifier)))
|
||||
(block
|
||||
(statement
|
||||
(statement_kind
|
||||
(expression
|
||||
(identifier))))))))))
|
||||
|
@ -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(
|
||||
@ -478,6 +478,7 @@ module.exports = grammar({
|
||||
type_definition: $ =>
|
||||
choice(
|
||||
$.enum_definition,
|
||||
$.function_definition,
|
||||
$.struct_definition,
|
||||
),
|
||||
|
||||
@ -555,5 +556,23 @@ module.exports = grammar({
|
||||
|
||||
struct_instance: $ =>
|
||||
seq($.identifier, '::', $.map),
|
||||
|
||||
function_definition: $ =>
|
||||
seq(
|
||||
'fn',
|
||||
$.identifier,
|
||||
optional($.type_arguments),
|
||||
'(',
|
||||
repeat(
|
||||
seq(
|
||||
$.identifier,
|
||||
$.type_specification,
|
||||
optional(','),
|
||||
),
|
||||
),
|
||||
')',
|
||||
$.type_specification,
|
||||
$.block,
|
||||
),
|
||||
},
|
||||
});
|
||||
|
@ -390,7 +390,7 @@
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function"
|
||||
"name": "anonymous_function"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
@ -1311,7 +1311,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"function": {
|
||||
"anonymous_function": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
@ -1451,6 +1451,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "enum_definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "struct_definition"
|
||||
@ -1717,6 +1721,75 @@
|
||||
"name": "map"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function_definition": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "fn"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "type_arguments"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "type_specification"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "type_specification"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
|
@ -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,
|
||||
@ -268,7 +291,26 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"type": "function_call",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
@ -284,26 +326,11 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type_specification",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function_call",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"type": "type_arguments",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_expression",
|
||||
"type": "type_specification",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
@ -822,6 +849,10 @@
|
||||
"type": "enum_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "struct_definition",
|
||||
"named": true
|
||||
@ -852,6 +883,10 @@
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "anonymous_function",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"named": true
|
||||
@ -864,10 +899,6 @@
|
||||
"type": "float",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"named": true
|
||||
@ -1074,6 +1105,10 @@
|
||||
"type": "float",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "fn",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "for",
|
||||
"named": false
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user