diff --git a/src/abstract_tree/expression.rs b/src/abstract_tree/expression.rs index 12ee2ba..4774f18 100644 --- a/src/abstract_tree/expression.rs +++ b/src/abstract_tree/expression.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::{ value_node::ValueNode, AbstractTree, Error, Format, FunctionCall, Identifier, Index, Logic, - Map, Math, Result, SyntaxNode, Type, Value, Yield, + Map, Math, New, Result, SyntaxNode, Type, Value, Yield, }; /// Abstract representation of an expression statement. @@ -19,6 +19,7 @@ pub enum Expression { Logic(Box), FunctionCall(Box), Yield(Box), + New(New), } impl AbstractTree for Expression { @@ -43,9 +44,10 @@ impl AbstractTree for Expression { child, source, context, )?)), "yield" => Expression::Yield(Box::new(Yield::from_syntax(child, source, context)?)), + "new" => Expression::New(New::from_syntax(child, source, context)?), _ => { return Err(Error::UnexpectedSyntaxNode { - expected: "value_node, identifier, index, math, logic, function_call or yield" + expected: "value, identifier, index, math, logic, function call, new or ->" .to_string(), actual: child.kind().to_string(), location: child.start_position(), @@ -66,6 +68,7 @@ impl AbstractTree for Expression { Expression::FunctionCall(function_call) => function_call.check_type(_source, _context), Expression::Index(index) => index.check_type(_source, _context), Expression::Yield(r#yield) => r#yield.check_type(_source, _context), + Expression::New(_) => todo!(), } } @@ -78,6 +81,7 @@ impl AbstractTree for Expression { Expression::FunctionCall(function_call) => function_call.run(source, context), Expression::Index(index) => index.run(source, context), Expression::Yield(r#yield) => r#yield.run(source, context), + Expression::New(_) => todo!(), } } @@ -90,6 +94,7 @@ impl AbstractTree for Expression { Expression::FunctionCall(function_call) => function_call.expected_type(context), Expression::Index(index) => index.expected_type(context), Expression::Yield(r#yield) => r#yield.expected_type(context), + Expression::New(_) => todo!(), } } } @@ -104,6 +109,7 @@ impl Format for Expression { Expression::FunctionCall(function_call) => function_call.format(output, indent_level), Expression::Index(index) => index.format(output, indent_level), Expression::Yield(r#yield) => r#yield.format(output, indent_level), + Expression::New(_) => todo!(), } } } diff --git a/src/abstract_tree/mod.rs b/src/abstract_tree/mod.rs index 57c56f1..a4a348f 100644 --- a/src/abstract_tree/mod.rs +++ b/src/abstract_tree/mod.rs @@ -25,6 +25,7 @@ pub mod logic_operator; pub mod r#match; pub mod math; pub mod math_operator; +pub mod new; pub mod statement; pub mod r#type; pub mod type_specification; @@ -36,7 +37,7 @@ pub use { assignment::*, assignment_operator::*, block::*, built_in_value::*, expression::*, function_call::*, function_expression::*, function_node::*, identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*, logic::*, logic_operator::*, - math::*, math_operator::*, r#for::*, r#match::*, r#type::*, r#while::*, r#yield::*, + math::*, math_operator::*, new::*, r#for::*, r#match::*, r#type::*, r#while::*, r#yield::*, statement::*, type_specification::*, value_node::*, }; diff --git a/src/abstract_tree/new.rs b/src/abstract_tree/new.rs new file mode 100644 index 0000000..ae16300 --- /dev/null +++ b/src/abstract_tree/new.rs @@ -0,0 +1,33 @@ +use serde::{Deserialize, Serialize}; + +use crate::{AbstractTree, Format, Identifier, Type, TypeSpecification, Value, ValueNode}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +pub struct New { + identifier: Identifier, + properties: Vec<(Identifier, ValueNode, Option)>, +} + +impl AbstractTree for New { + fn from_syntax( + node: tree_sitter::Node, + source: &str, + context: &crate::Map, + ) -> crate::Result { + todo!() + } + + fn run(&self, source: &str, context: &crate::Map) -> crate::Result { + todo!() + } + + fn expected_type(&self, context: &crate::Map) -> crate::Result { + todo!() + } +} + +impl Format for New { + fn format(&self, output: &mut String, indent_level: u8) { + todo!() + } +}