From 66c4d571c6dbd2c61fb24e4f1e696d9bd9a42107 Mon Sep 17 00:00:00 2001 From: azjezz Date: Fri, 20 Jan 2023 20:35:54 +0100 Subject: [PATCH] chore: merge all method definitions into one Signed-off-by: azjezz --- bin/snapshot.rs | 3 +- examples/linter.rs | 3 +- examples/parser.rs | 3 +- src/lexer/byte_string.rs | 8 +- src/parser/internal/definition/attribute.rs | 25 +- src/parser/internal/definition/class.rs | 21 +- src/parser/internal/definition/enum.rs | 49 +- src/parser/internal/definition/function.rs | 178 +-- src/parser/internal/definition/interface.rs | 20 +- src/parser/internal/definition/parameter.rs | 40 +- src/parser/internal/definition/template.rs | 7 - src/parser/internal/expression/class.rs | 47 +- src/parser/issue.rs | 147 +-- src/tree/definition/class.rs | 35 +- src/tree/definition/enum.rs | 6 +- src/tree/definition/function.rs | 216 +--- src/tree/definition/interface.rs | 10 +- src/tree/expression/class.rs | 91 +- tests/samples/0003/error.txt | 2 +- tests/samples/0023/error.txt | 2 +- tests/samples/0029/error.txt | 2 +- tests/samples/0036/tree.txt | 27 +- tests/samples/0040/tree.txt | 27 +- tests/samples/0043/error.txt | 2 +- tests/samples/0046/tree.txt | 32 +- tests/samples/0047/tree.txt | 32 +- tests/samples/0048/tree.txt | 112 +- tests/samples/0049/tree.txt | 124 +- tests/samples/0050/tree.txt | 110 +- tests/samples/0055/tree.txt | 182 +-- tests/samples/0057/tree.txt | 56 +- tests/samples/0065/error.txt | 2 +- tests/samples/0067/error.txt | 2 +- tests/samples/0068/error.txt | 2 +- tests/samples/0071/tree.txt | 27 +- tests/samples/0075/tree.txt | 1281 ++++++++++--------- tests/samples/0076/tree.txt | 84 +- tests/samples/0079/tree.txt | 2 +- tests/samples/0082/tree.txt | 1281 ++++++++++--------- tests/samples/0083/error.txt | 24 +- tests/samples/0085/tree.txt | 87 +- tests/samples/0086/error.txt | 40 +- tests/samples/0087/tree.txt | 118 +- tests/samples/0089/tree.txt | 42 +- tests/samples/0093/tree.txt | 42 +- tests/samples/0104/error.txt | 27 - tests/samples/0104/tree.txt | 319 +++++ tests/test.rs | 3 +- 48 files changed, 2384 insertions(+), 2618 deletions(-) delete mode 100644 tests/samples/0104/error.txt create mode 100644 tests/samples/0104/tree.txt diff --git a/bin/snapshot.rs b/bin/snapshot.rs index d3bbc9c..4aca896 100644 --- a/bin/snapshot.rs +++ b/bin/snapshot.rs @@ -1,7 +1,6 @@ use std::env; use std::fs::read_dir; use std::io; -use std::ops::Deref; use std::path::PathBuf; use ara_parser::parser; @@ -56,7 +55,7 @@ fn main() -> io::Result<()> { .with_colors(ColorChoice::Never); let error = builder - .as_string(report.deref()) + .as_string(report.as_ref()) .expect("failed to build the report"); std::fs::write(error_filename, error)?; diff --git a/examples/linter.rs b/examples/linter.rs index ce608aa..e681d4e 100644 --- a/examples/linter.rs +++ b/examples/linter.rs @@ -1,5 +1,4 @@ use std::env; -use std::ops::Deref; use ara_parser::parser; use ara_parser::traverser::visitor::NodeVisitor; @@ -75,7 +74,7 @@ fn main() -> Result<(), Error> { ReportBuilder::new(&source_map) .with_charset(CharSet::Unicode) .with_colors(ColorChoice::Always) - .print(report.deref())?; + .print(report.as_ref())?; } } diff --git a/examples/parser.rs b/examples/parser.rs index eaae79b..feb501d 100644 --- a/examples/parser.rs +++ b/examples/parser.rs @@ -1,5 +1,4 @@ use std::env; -use std::ops::Deref; use ara_parser::parser; use ara_reporting::builder::CharSet; @@ -21,7 +20,7 @@ fn main() -> Result<(), Error> { ReportBuilder::new(&source_map) .with_charset(CharSet::Unicode) .with_colors(ColorChoice::Always) - .print(report.deref())?; + .print(report.as_ref())?; } } diff --git a/src/lexer/byte_string.rs b/src/lexer/byte_string.rs index fe29e63..262603e 100644 --- a/src/lexer/byte_string.rs +++ b/src/lexer/byte_string.rs @@ -1,11 +1,11 @@ -use schemars::JsonSchema; -use serde::Deserialize; -use serde::Serialize; - use std::ops::Deref; use std::ops::DerefMut; use std::str::from_utf8; +use schemars::JsonSchema; +use serde::Deserialize; +use serde::Serialize; + /// A wrapper for Vec that provides a human-readable Debug impl and /// a few other conveniences. /// diff --git a/src/parser/internal/definition/attribute.rs b/src/parser/internal/definition/attribute.rs index a08b1f9..5b9d6f4 100644 --- a/src/parser/internal/definition/attribute.rs +++ b/src/parser/internal/definition/attribute.rs @@ -6,7 +6,6 @@ use crate::parser::result::ParseResult; use crate::parser::state::State; use crate::tree::definition::attribute::AttributeDefinition; use crate::tree::definition::attribute::AttributeGroupDefinition; -use crate::tree::expression::argument::ArgumentExpression; pub fn gather(state: &mut State) -> ParseResult { if state.iterator.current().kind != TokenKind::Attribute { @@ -21,29 +20,7 @@ pub fn gather(state: &mut State) -> ParseResult { Ok(AttributeDefinition { name: identifier::fully_qualified_type_identifier_including_self(state)?, arguments: if state.iterator.current().kind == TokenKind::LeftParen { - let arguments = argument::argument_list_expression(state)?; - - for argument in &arguments.arguments.inner { - match argument { - ArgumentExpression::Value { value, .. } - | ArgumentExpression::Named { value, .. } => { - if !value.is_constant(true) { - crate::parser_report!( - state, - invalid_constant_initialization_expression(value) - ); - } - } - expression => { - crate::parser_report!( - state, - invalid_constant_initialization_expression(expression) - ); - } - } - } - - Some(arguments) + Some(argument::argument_list_expression(state)?) } else { None }, diff --git a/src/parser/internal/definition/class.rs b/src/parser/internal/definition/class.rs index 40e45cd..de65b6c 100644 --- a/src/parser/internal/definition/class.rs +++ b/src/parser/internal/definition/class.rs @@ -2,8 +2,6 @@ use crate::lexer::token::TokenKind; use crate::parser::internal::definition::attribute; use crate::parser::internal::definition::constant::classish_constant_definition; use crate::parser::internal::definition::function::method_definition; -use crate::parser::internal::definition::function::MethodDefinitionReference; -use crate::parser::internal::definition::function::MethodDefinitionType; use crate::parser::internal::definition::modifier; use crate::parser::internal::definition::property; use crate::parser::internal::definition::template; @@ -83,7 +81,7 @@ pub fn class_definition(state: &mut State) -> ParseResult { }) } -fn class_definition_member(state: &mut State) -> ParseResult { +pub fn class_definition_member(state: &mut State) -> ParseResult { attribute::gather(state)?; let modifiers = modifier::collect(state)?; @@ -93,22 +91,7 @@ fn class_definition_member(state: &mut State) -> ParseResult { - Ok(ClassDefinitionMember::AbstractMethod(method)) - } - MethodDefinitionReference::Concrete(method) => { - Ok(ClassDefinitionMember::ConcreteMethod(method)) - } - MethodDefinitionReference::AbstractConstructor(ctor) => { - Ok(ClassDefinitionMember::AbstractConstructor(ctor)) - } - MethodDefinitionReference::ConcreteConstructor(ctor) => { - Ok(ClassDefinitionMember::ConcreteConstructor(ctor)) - } - }; + return method_definition(state, modifiers).map(ClassDefinitionMember::Method); } property::property_definition(state, modifiers).map(ClassDefinitionMember::Property) diff --git a/src/parser/internal/definition/enum.rs b/src/parser/internal/definition/enum.rs index 22679f3..d43c444 100644 --- a/src/parser/internal/definition/enum.rs +++ b/src/parser/internal/definition/enum.rs @@ -2,15 +2,12 @@ use crate::lexer::token::TokenKind; use crate::parser::internal::definition::attribute; use crate::parser::internal::definition::constant; use crate::parser::internal::definition::function; -use crate::parser::internal::definition::function::MethodDefinitionReference; use crate::parser::internal::definition::modifier; use crate::parser::internal::expression; use crate::parser::internal::identifier; use crate::parser::internal::utils; use crate::parser::result::ParseResult; use crate::parser::state::State; -use crate::tree::definition::function::ConcreteMethodDefinition; -use crate::tree::definition::modifier::ModifierGroupDefinition; use crate::tree::definition::r#enum::BackedEnumBodyDefinition; use crate::tree::definition::r#enum::BackedEnumCaseDefinition; use crate::tree::definition::r#enum::BackedEnumDefinition; @@ -164,8 +161,9 @@ fn unit_enum_definition_member( .map(Some); } - concrete_method_definition(state, modifiers, enum_name) - .map(|method| method.map(UnitEnumMemberDefinition::Method)) + Ok(Some(UnitEnumMemberDefinition::Method( + function::method_definition(state, modifiers)?, + ))) } fn backed_enum_definition_member( @@ -214,42 +212,7 @@ fn backed_enum_definition_member( .map(Some); } - concrete_method_definition(state, modifiers, enum_name) - .map(|method| method.map(BackedEnumMemberDefinition::Method)) -} - -fn concrete_method_definition( - state: &mut State, - modifiers: ModifierGroupDefinition, - enum_name: &Identifier, -) -> ParseResult> { - let method = - function::method_definition(state, function::MethodDefinitionType::Concrete, modifiers)?; - - match method { - MethodDefinitionReference::ConcreteConstructor(constructor) => { - crate::parser_report!(state, enum_cannot_have_constructor(enum_name, &constructor)); - - Ok(None) - } - MethodDefinitionReference::Concrete(method) => { - match method.name.value[..].to_ascii_lowercase().as_slice() { - b"__get" | b"__set" | b"__serialize" | b"__unserialize" | b"__destruct" - | b"__wakeup" | b"__sleep" | b"__set_state" | b"__unset" | b"__isset" - | b"__debuginfo" | b"__clone" | b"__tostring" => { - crate::parser_report!(state, enum_cannot_have_magic_method(enum_name, &method)); - } - _ => {} - } - - Ok(Some(method)) - } - MethodDefinitionReference::Abstract(_) - | MethodDefinitionReference::AbstractConstructor(_) => { - crate::parser_bail!( - state, - unreachable_code("unexpected abstract method in enum definition") - ) - } - } + Ok(Some(BackedEnumMemberDefinition::Method( + function::method_definition(state, modifiers)?, + ))) } diff --git a/src/parser/internal/definition/function.rs b/src/parser/internal/definition/function.rs index 2a2a024..c98f5b8 100644 --- a/src/parser/internal/definition/function.rs +++ b/src/parser/internal/definition/function.rs @@ -7,30 +7,14 @@ use crate::parser::internal::statement::block; use crate::parser::internal::utils; use crate::parser::result::ParseResult; use crate::parser::state::State; -use crate::tree::definition::function::AbstractConstructorDefinition; -use crate::tree::definition::function::AbstractMethodDefinition; -use crate::tree::definition::function::ConcreteConstructorDefinition; -use crate::tree::definition::function::ConcreteMethodDefinition; use crate::tree::definition::function::FunctionDefinition; use crate::tree::definition::function::FunctionLikeReturnTypeDefinition; +use crate::tree::definition::function::MethodBodyDefinition; +use crate::tree::definition::function::MethodDefinition; use crate::tree::definition::function::MethodTypeConstraintDefinition; use crate::tree::definition::function::MethodTypeConstraintGroupDefinition; -use crate::tree::definition::modifier::ModifierDefinition; use crate::tree::definition::modifier::ModifierGroupDefinition; -pub enum MethodDefinitionType { - Abstract, - Concrete, - Either, -} - -pub enum MethodDefinitionReference { - Abstract(AbstractMethodDefinition), - Concrete(ConcreteMethodDefinition), - AbstractConstructor(AbstractConstructorDefinition), - ConcreteConstructor(ConcreteConstructorDefinition), -} - pub fn function_definition(state: &mut State) -> ParseResult { let comments = state.iterator.comments(); let attributes = state.get_attributes(); @@ -56,118 +40,52 @@ pub fn function_definition(state: &mut State) -> ParseResult pub fn method_definition( state: &mut State, - r#type: MethodDefinitionType, modifiers: ModifierGroupDefinition, -) -> ParseResult { - let comments = state.iterator.comments(); - let attributes = state.get_attributes(); - let function = utils::skip_keyword(state, TokenKind::Function)?; - - let name = identifier::identifier_maybe_reserved(state)?; - let has_body = match r#type { - MethodDefinitionType::Abstract => false, - MethodDefinitionType::Concrete => true, - MethodDefinitionType::Either => !modifiers - .modifiers - .iter() - .any(|modifier| matches!(modifier, ModifierDefinition::Abstract(_))), - }; - - if name.to_string().to_lowercase() == "__construct" { - return if has_body { - let parameters = parameter::constructor_parameter_list_definition(state)?; - - Ok(MethodDefinitionReference::ConcreteConstructor( - ConcreteConstructorDefinition { - comments, - attributes, - modifiers, - function, - name, - parameters, - body: block::block_statement(state)?, - }, - )) +) -> ParseResult { + Ok(MethodDefinition { + comments: state.iterator.comments(), + attributes: state.get_attributes(), + modifiers, + function: utils::skip_keyword(state, TokenKind::Function)?, + name: identifier::identifier_maybe_reserved(state)?, + templates: if state.iterator.current().kind == TokenKind::LessThan { + Some(template::template_group_definition(state)?) } else { - let parameters = parameter::function_like_parameter_list_definition(state)?; - let semicolon = utils::skip_semicolon(state)?; - - Ok(MethodDefinitionReference::AbstractConstructor( - AbstractConstructorDefinition { - comments, - attributes, - modifiers, - function, - name, - parameters, - semicolon, - }, - )) - }; - } - - let templates = if state.iterator.current().kind == TokenKind::LessThan { - Some(template::template_group_definition(state)?) - } else { - None - }; - - let parameters = parameter::function_like_parameter_list_definition(state)?; - let return_type = FunctionLikeReturnTypeDefinition { - colon: utils::skip_colon(state)?, - type_definition: r#type::type_definition(state)?, - }; - let current = state.iterator.current(); - let constraints = if current.kind == TokenKind::Where { - Some(MethodTypeConstraintGroupDefinition { - comments: state.iterator.comments(), - r#where: utils::skip_keyword(state, TokenKind::Where)?, - constraints: utils::comma_separated( - state, - &|state| { - Ok(MethodTypeConstraintDefinition { - comments: state.iterator.comments(), - identifier: identifier::identifier_maybe_reserved(state)?, - r#is: utils::skip_keyword(state, TokenKind::Is)?, - type_definition: r#type::type_definition(state)?, - }) - }, - TokenKind::LeftBrace, - )?, - }) - } else { - None - }; - - if has_body { - Ok(MethodDefinitionReference::Concrete( - ConcreteMethodDefinition { - comments, - attributes, - modifiers, - function, - name, - templates, - parameters, - return_type, - constraints, - body: block::block_statement(state)?, - }, - )) - } else { - Ok(MethodDefinitionReference::Abstract( - AbstractMethodDefinition { - comments, - attributes, - modifiers, - function, - name, - templates, - parameters, - return_type, - constraints, - semicolon: utils::skip_semicolon(state)?, - }, - )) - } + None + }, + parameters: parameter::method_parameter_list_definition(state)?, + return_type: if state.iterator.current().kind == TokenKind::Colon { + Some(FunctionLikeReturnTypeDefinition { + colon: utils::skip_colon(state)?, + type_definition: r#type::type_definition(state)?, + }) + } else { + None + }, + constraints: if state.iterator.current().kind == TokenKind::Where { + Some(MethodTypeConstraintGroupDefinition { + comments: state.iterator.comments(), + r#where: utils::skip_keyword(state, TokenKind::Where)?, + constraints: utils::comma_separated( + state, + &|state| { + Ok(MethodTypeConstraintDefinition { + comments: state.iterator.comments(), + identifier: identifier::identifier_maybe_reserved(state)?, + r#is: utils::skip_keyword(state, TokenKind::Is)?, + type_definition: r#type::type_definition(state)?, + }) + }, + TokenKind::LeftBrace, + )?, + }) + } else { + None + }, + body: if state.iterator.current().kind == TokenKind::SemiColon { + MethodBodyDefinition::Abstract(utils::skip_semicolon(state)?) + } else { + MethodBodyDefinition::Concrete(block::block_statement(state)?) + }, + }) } diff --git a/src/parser/internal/definition/interface.rs b/src/parser/internal/definition/interface.rs index a105dd2..b84a3d6 100644 --- a/src/parser/internal/definition/interface.rs +++ b/src/parser/internal/definition/interface.rs @@ -2,8 +2,6 @@ use crate::lexer::token::TokenKind; use crate::parser::internal::definition::attribute; use crate::parser::internal::definition::constant; use crate::parser::internal::definition::function::method_definition; -use crate::parser::internal::definition::function::MethodDefinitionReference; -use crate::parser::internal::definition::function::MethodDefinitionType; use crate::parser::internal::definition::modifier; use crate::parser::internal::definition::template; use crate::parser::internal::identifier; @@ -74,22 +72,6 @@ fn interface_definition_member(state: &mut State) -> ParseResult { - Ok(InterfaceDefinitionMember::Method(method)) - } - MethodDefinitionReference::AbstractConstructor(ctor) => { - Ok(InterfaceDefinitionMember::Constructor(ctor)) - } - MethodDefinitionReference::ConcreteConstructor(_) - | MethodDefinitionReference::Concrete(_) => { - crate::parser_bail!( - state, - unreachable_code("unexpected concrete method in interface definition") - ) - } - } + method_definition(state, modifiers).map(InterfaceDefinitionMember::Method) } } diff --git a/src/parser/internal/definition/parameter.rs b/src/parser/internal/definition/parameter.rs index a37ac03..bc0c411 100644 --- a/src/parser/internal/definition/parameter.rs +++ b/src/parser/internal/definition/parameter.rs @@ -7,11 +7,11 @@ use crate::parser::internal::utils; use crate::parser::internal::variable; use crate::parser::result::ParseResult; use crate::parser::state::State; -use crate::tree::definition::function::ConstructorParameterDefinition; -use crate::tree::definition::function::ConstructorParameterListDefinition; use crate::tree::definition::function::FunctionLikeParameterDefaultValueDefinition; use crate::tree::definition::function::FunctionLikeParameterDefinition; use crate::tree::definition::function::FunctionLikeParameterListDefinition; +use crate::tree::definition::function::MethodParameterDefinition; +use crate::tree::definition::function::MethodParameterListDefinition; pub fn function_like_parameter_list_definition( state: &mut State, @@ -43,18 +43,7 @@ pub fn function_like_parameter_list_definition( Some(FunctionLikeParameterDefaultValueDefinition { equals: current.position, - value: { - let expression = expression::create(state)?; - - if !expression.is_constant(true) { - crate::parser_report!( - state, - invalid_constant_initialization_expression(&expression) - ); - } - - expression - }, + value: expression::create(state)?, }) } else { None @@ -82,13 +71,13 @@ pub fn function_like_parameter_list_definition( }) } -pub fn constructor_parameter_list_definition( +pub fn method_parameter_list_definition( state: &mut State, -) -> ParseResult { +) -> ParseResult { let comments = state.iterator.comments(); let left_parenthesis = utils::skip_left_parenthesis(state)?; - let parameters = utils::comma_separated::( + let parameters = utils::comma_separated::( state, &|state| { attribute::gather(state)?; @@ -111,24 +100,13 @@ pub fn constructor_parameter_list_definition( Some(FunctionLikeParameterDefaultValueDefinition { equals: current.position, - value: { - let expression = expression::create(state)?; - - if !expression.is_constant(true) { - crate::parser_report!( - state, - invalid_constant_initialization_expression(&expression) - ); - } - - expression - }, + value: expression::create(state)?, }) } else { None }; - let parameter = ConstructorParameterDefinition { + let parameter = MethodParameterDefinition { comments: state.iterator.comments(), variable, attributes: state.get_attributes(), @@ -145,7 +123,7 @@ pub fn constructor_parameter_list_definition( let right_parenthesis = utils::skip_right_parenthesis(state)?; - Ok(ConstructorParameterListDefinition { + Ok(MethodParameterListDefinition { comments, left_parenthesis, parameters, diff --git a/src/parser/internal/definition/template.rs b/src/parser/internal/definition/template.rs index 0edee3b..69835c8 100644 --- a/src/parser/internal/definition/template.rs +++ b/src/parser/internal/definition/template.rs @@ -125,13 +125,6 @@ pub fn type_template_group_definition( } }; - if members.inner.is_empty() { - crate::parser_report!( - state, - expected_at_least_one_type_in_template_group(less_than, greater_than) - ); - } - Ok(TypeTemplateGroupDefinition { comments, less_than, diff --git a/src/parser/internal/expression/class.rs b/src/parser/internal/expression/class.rs index 1b67a1e..42ff4bb 100644 --- a/src/parser/internal/expression/class.rs +++ b/src/parser/internal/expression/class.rs @@ -1,21 +1,15 @@ use crate::lexer::token::TokenKind; use crate::parser::internal::definition::attribute; -use crate::parser::internal::definition::constant::classish_constant_definition; -use crate::parser::internal::definition::function::method_definition; -use crate::parser::internal::definition::function::MethodDefinitionReference; -use crate::parser::internal::definition::function::MethodDefinitionType; -use crate::parser::internal::definition::modifier; -use crate::parser::internal::definition::property; +use crate::parser::internal::definition::class::class_definition_member; use crate::parser::internal::expression::argument; use crate::parser::internal::identifier; use crate::parser::internal::utils; use crate::parser::result::ParseResult; use crate::parser::state::State; +use crate::tree::definition::class::ClassDefinitionBody; use crate::tree::definition::class::ClassDefinitionExtends; use crate::tree::definition::class::ClassDefinitionImplements; use crate::tree::expression::class::AnonymousClassExpression; -use crate::tree::expression::class::AnonymousClassExpressionBody; -use crate::tree::expression::class::AnonymousClassExpressionMember; use crate::tree::expression::operator::ClassOperationExpression; pub fn anonymous_initialization_class_operation_expression( @@ -69,12 +63,12 @@ pub fn anonymous_class_expression(state: &mut State) -> ParseResult ParseResult ParseResult { - attribute::gather(state)?; - - let modifiers = modifier::collect(state)?; - - if state.iterator.current().kind == TokenKind::Const { - return classish_constant_definition(state, modifiers) - .map(AnonymousClassExpressionMember::Constant); - } - - if state.iterator.current().kind == TokenKind::Function { - let method = method_definition(state, MethodDefinitionType::Concrete, modifiers)?; - - match method { - MethodDefinitionReference::Concrete(method) => { - return Ok(AnonymousClassExpressionMember::ConcreteMethod(method)); - } - MethodDefinitionReference::ConcreteConstructor(ctor) => { - return Ok(AnonymousClassExpressionMember::ConcreteConstructor(ctor)); - } - MethodDefinitionReference::Abstract(_) - | MethodDefinitionReference::AbstractConstructor(_) => crate::parser_bail!( - state, - unreachable_code("unexpected abstract method in anonymous class") - ), - } - } - - property::property_definition(state, modifiers).map(AnonymousClassExpressionMember::Property) -} diff --git a/src/parser/issue.rs b/src/parser/issue.rs index 32a5460..c59eee3 100644 --- a/src/parser/issue.rs +++ b/src/parser/issue.rs @@ -6,8 +6,6 @@ use ara_reporting::issue::Issue; use crate::lexer::token::Token; use crate::lexer::token::TokenKind; use crate::parser::state::State as ParserState; -use crate::tree::definition::function::ConcreteConstructorDefinition; -use crate::tree::definition::function::ConcreteMethodDefinition; use crate::tree::identifier::Identifier; use crate::tree::Node; @@ -79,37 +77,6 @@ pub enum ParserIssueCode { /// - Change the enum to a unit enum BackedEnumCaseMustHaveValue = 4, - /// Enum cannot have a constructor ( code = 5 ) - /// - /// Example: - /// - /// ```ara - /// enum Foo { - /// public function __construct() {} - /// } - /// ``` - /// - /// Possible solution(s): - /// - /// - Remove the constructor - /// - Change the enum to a class - EnumCannotHaveConstructor = 5, - - /// Enum cannot have a magic method ( code = 6 ) - /// - /// Example: - /// - /// ```ara - /// enum Foo { - /// public function __toString() {} - /// } - /// ``` - /// - /// Possible solution(s): - /// - /// - Remove the magic method - EnumCannotHaveMagicMethod = 6, - /// Missing item definition after attributes ( code = 7 ) /// /// Example: @@ -122,7 +89,7 @@ pub enum ParserIssueCode { /// /// - Add an item definition after the attributes /// - Remove the attributes - MissingItemDefinitionAfterAttributes = 7, + MissingItemDefinitionAfterAttributes = 5, /// Reserved keyword cannot be used for type name ( code = 8 ) /// @@ -135,7 +102,7 @@ pub enum ParserIssueCode { /// Possible solution(s): /// /// - Use a different name - ReservedKeywordCannotBeUsedForTypeName = 8, + ReservedKeywordCannotBeUsedForTypeName = 6, /// Reserved keyword cannot be used for constant name ( code = 9 ) /// @@ -148,7 +115,7 @@ pub enum ParserIssueCode { /// Possible solution(s): /// /// - Use a different name - ReservedKeywordCannotBeUsedForConstantName = 9, + ReservedKeywordCannotBeUsedForConstantName = 7, /// Type cannot be used in current context ( code = 10 ) /// @@ -161,7 +128,7 @@ pub enum ParserIssueCode { /// Possible solution(s): /// /// - Use a different type - TypeCannotBeUsedInCurrentContext = 10, + TypeCannotBeUsedInCurrentContext = 8, /// Missing item expression after attribute(s) ( code = 11 ) /// @@ -177,7 +144,7 @@ pub enum ParserIssueCode { /// /// - Add an item expression after the attribute(s) /// - Remove the attribute(s) - MissingItemExpressionAfterAttributes = 11, + MissingItemExpressionAfterAttributes = 9, /// Enum backing type must be either `int` or `string` ( code = 12 ) /// @@ -192,7 +159,7 @@ pub enum ParserIssueCode { /// Possible solution(s): /// /// - Change the backing type to `int` or `string` - InvalidEnumBackingType = 12, + InvalidEnumBackingType = 10, /// Unexpected token ( code = 13 ) /// @@ -202,38 +169,7 @@ pub enum ParserIssueCode { /// function foo() -> void { /// } /// ``` - UnexpectedToken = 13, - - /// Invalid constant initialization expression ( code = 14 ) - /// - /// Example: - /// - /// ```ara - /// function foo( - /// Closure<(), void> $a = ( - /// function(): void { } - /// ) - /// ): void {} - /// ``` - /// - /// Possible solution(s): - /// - /// - Use a valid constant initialization expression - InvalidConstantInitializationExpression = 14, - - /// Invalid empty type template ( code = 15 ) - /// - /// Example: - /// - /// ```ara - /// type Foo = Bar<>; - /// ``` - /// - /// Possible solution(s): - /// - /// - Remove the empty type template - /// - Add a type template - ExpectedAtLeastOneTypeInTemplateGroup = 15, + UnexpectedToken = 11, } pub(crate) fn unreachable_code>(state: &ParserState, message: M) -> Issue { @@ -325,48 +261,6 @@ pub(crate) fn backed_enum_case_must_have_value( )) } -pub(crate) fn enum_cannot_have_constructor( - state: &ParserState, - r#enum: &Identifier, - constructor: &ConcreteConstructorDefinition, -) -> Issue { - let origin = state.source.name(); - - Issue::error( - ParserIssueCode::EnumCannotHaveConstructor, - format!("enum `{}` cannot have constructor", state.named(&r#enum),), - ) - .with_source( - origin, - constructor.initial_position(), - constructor.final_position(), - ) - .with_annotation(Annotation::secondary( - origin, - r#enum.initial_position(), - r#enum.final_position(), - )) -} - -pub(crate) fn enum_cannot_have_magic_method( - state: &ParserState, - r#enum: &Identifier, - method: &ConcreteMethodDefinition, -) -> Issue { - let origin = state.source.name(); - - Issue::error( - ParserIssueCode::EnumCannotHaveMagicMethod, - format!("enum `{}` cannot have magic method", state.named(&r#enum),), - ) - .with_source(origin, method.initial_position(), method.final_position()) - .with_annotation(Annotation::secondary( - origin, - r#enum.initial_position(), - r#enum.final_position(), - )) -} - pub(crate) fn missing_item_definition_after_attributes(state: &ParserState) -> Issue { let origin = state.source.name(); let current = state.iterator.current(); @@ -548,33 +442,6 @@ pub(crate) fn unexpected_token( ) } -pub(crate) fn invalid_constant_initialization_expression( - state: &ParserState, - expression: &dyn Node, -) -> Issue { - Issue::error( - ParserIssueCode::InvalidConstantInitializationExpression, - "invalid constant initialization expression", - ) - .with_source( - state.source.name(), - expression.initial_position(), - expression.final_position(), - ) -} - -pub(crate) fn expected_at_least_one_type_in_template_group( - state: &ParserState, - less_than: usize, - greater_than: usize, -) -> Issue { - Issue::error( - ParserIssueCode::ExpectedAtLeastOneTypeInTemplateGroup, - "expected at least one type in template group", - ) - .with_source(state.source.name(), less_than, greater_than) -} - impl ::std::fmt::Display for ParserIssueCode { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { write!(f, "P{:04}", *self as u8) diff --git a/src/tree/definition/class.rs b/src/tree/definition/class.rs index e4afa10..01ddbd7 100644 --- a/src/tree/definition/class.rs +++ b/src/tree/definition/class.rs @@ -5,10 +5,7 @@ use serde::Serialize; use crate::tree::comment::CommentGroup; use crate::tree::definition::attribute::AttributeGroupDefinition; use crate::tree::definition::constant::ClassishConstantDefinition; -use crate::tree::definition::function::AbstractConstructorDefinition; -use crate::tree::definition::function::AbstractMethodDefinition; -use crate::tree::definition::function::ConcreteConstructorDefinition; -use crate::tree::definition::function::ConcreteMethodDefinition; +use crate::tree::definition::function::MethodDefinition; use crate::tree::definition::modifier::ModifierGroupDefinition; use crate::tree::definition::property::PropertyDefinition; use crate::tree::definition::template::TemplateGroupDefinition; @@ -59,10 +56,7 @@ pub struct ClassDefinitionBody { pub enum ClassDefinitionMember { Constant(ClassishConstantDefinition), Property(PropertyDefinition), - AbstractMethod(AbstractMethodDefinition), - AbstractConstructor(AbstractConstructorDefinition), - ConcreteMethod(ConcreteMethodDefinition), - ConcreteConstructor(ConcreteConstructorDefinition), + Method(MethodDefinition), } impl Node for ClassDefinition { @@ -194,10 +188,7 @@ impl Node for ClassDefinitionMember { match &self { Self::Constant(constant) => constant.comments(), Self::Property(property) => property.comments(), - Self::AbstractMethod(method) => method.comments(), - Self::AbstractConstructor(constructor) => constructor.comments(), - Self::ConcreteMethod(method) => method.comments(), - Self::ConcreteConstructor(constructor) => constructor.comments(), + Self::Method(method) => method.comments(), } } @@ -205,10 +196,7 @@ impl Node for ClassDefinitionMember { match &self { Self::Constant(constant) => constant.initial_position(), Self::Property(property) => property.initial_position(), - Self::AbstractMethod(method) => method.initial_position(), - Self::AbstractConstructor(constructor) => constructor.initial_position(), - Self::ConcreteMethod(method) => method.initial_position(), - Self::ConcreteConstructor(constructor) => constructor.initial_position(), + Self::Method(method) => method.initial_position(), } } @@ -216,10 +204,7 @@ impl Node for ClassDefinitionMember { match &self { Self::Constant(constant) => constant.final_position(), Self::Property(property) => property.final_position(), - Self::AbstractMethod(method) => method.final_position(), - Self::AbstractConstructor(constructor) => constructor.final_position(), - Self::ConcreteMethod(method) => method.final_position(), - Self::ConcreteConstructor(constructor) => constructor.final_position(), + Self::Method(method) => method.final_position(), } } @@ -227,10 +212,7 @@ impl Node for ClassDefinitionMember { match &self { Self::Constant(constant) => vec![constant], Self::Property(property) => vec![property], - Self::AbstractMethod(method) => vec![method], - Self::AbstractConstructor(constructor) => vec![constructor], - Self::ConcreteMethod(method) => vec![method], - Self::ConcreteConstructor(constructor) => vec![constructor], + Self::Method(method) => vec![method], } } @@ -238,10 +220,7 @@ impl Node for ClassDefinitionMember { match &self { Self::Constant(constant) => constant.get_description(), Self::Property(property) => property.get_description(), - Self::AbstractMethod(method) => method.get_description(), - Self::AbstractConstructor(constructor) => constructor.get_description(), - Self::ConcreteMethod(method) => method.get_description(), - Self::ConcreteConstructor(constructor) => constructor.get_description(), + Self::Method(method) => method.get_description(), } } } diff --git a/src/tree/definition/enum.rs b/src/tree/definition/enum.rs index 1751584..5138a62 100644 --- a/src/tree/definition/enum.rs +++ b/src/tree/definition/enum.rs @@ -5,7 +5,7 @@ use serde::Serialize; use crate::tree::comment::CommentGroup; use crate::tree::definition::attribute::AttributeGroupDefinition; use crate::tree::definition::constant::ClassishConstantDefinition; -use crate::tree::definition::function::ConcreteMethodDefinition; +use crate::tree::definition::function::MethodDefinition; use crate::tree::expression::Expression; use crate::tree::identifier::Identifier; use crate::tree::identifier::TemplatedIdentifier; @@ -50,7 +50,7 @@ pub struct UnitEnumBodyDefinition { #[serde(rename_all = "snake_case", tag = "type", content = "value")] pub enum UnitEnumMemberDefinition { Case(UnitEnumCaseDefinition), - Method(ConcreteMethodDefinition), + Method(MethodDefinition), Constant(ClassishConstantDefinition), } @@ -94,7 +94,7 @@ pub struct BackedEnumBodyDefinition { #[serde(rename_all = "snake_case", tag = "type", content = "value")] pub enum BackedEnumMemberDefinition { Case(BackedEnumCaseDefinition), - Method(ConcreteMethodDefinition), + Method(MethodDefinition), Constant(ClassishConstantDefinition), } diff --git a/src/tree/definition/function.rs b/src/tree/definition/function.rs index 4621835..721dcd5 100644 --- a/src/tree/definition/function.rs +++ b/src/tree/definition/function.rs @@ -64,7 +64,7 @@ pub struct FunctionDefinition { #[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] -pub struct ConstructorParameterDefinition { +pub struct MethodParameterDefinition { pub attributes: Vec, pub comments: CommentGroup, pub modifiers: ModifierGroupDefinition, @@ -76,37 +76,13 @@ pub struct ConstructorParameterDefinition { #[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] -pub struct ConstructorParameterListDefinition { +pub struct MethodParameterListDefinition { pub comments: CommentGroup, pub left_parenthesis: usize, - pub parameters: CommaSeparated, + pub parameters: CommaSeparated, pub right_parenthesis: usize, } -#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct AbstractConstructorDefinition { - pub comments: CommentGroup, - pub attributes: Vec, - pub modifiers: ModifierGroupDefinition, - pub function: Keyword, - pub name: Identifier, - pub parameters: FunctionLikeParameterListDefinition, - pub semicolon: usize, -} - -#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct ConcreteConstructorDefinition { - pub comments: CommentGroup, - pub attributes: Vec, - pub modifiers: ModifierGroupDefinition, - pub function: Keyword, - pub name: Identifier, - pub parameters: ConstructorParameterListDefinition, - pub body: BlockStatement, -} - #[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct MethodTypeConstraintDefinition { @@ -126,32 +102,24 @@ pub struct MethodTypeConstraintGroupDefinition { #[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] -pub struct AbstractMethodDefinition { - pub comments: CommentGroup, - pub attributes: Vec, - pub modifiers: ModifierGroupDefinition, - pub function: Keyword, - pub name: Identifier, - pub templates: Option, - pub parameters: FunctionLikeParameterListDefinition, - pub return_type: FunctionLikeReturnTypeDefinition, - pub constraints: Option, - pub semicolon: usize, +pub enum MethodBodyDefinition { + Concrete(BlockStatement), + Abstract(usize), } #[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] -pub struct ConcreteMethodDefinition { +pub struct MethodDefinition { pub comments: CommentGroup, pub attributes: Vec, pub modifiers: ModifierGroupDefinition, pub function: Keyword, pub name: Identifier, pub templates: Option, - pub parameters: FunctionLikeParameterListDefinition, - pub return_type: FunctionLikeReturnTypeDefinition, + pub parameters: MethodParameterListDefinition, + pub return_type: Option, pub constraints: Option, - pub body: BlockStatement, + pub body: MethodBodyDefinition, } impl Node for FunctionLikeReturnTypeDefinition { @@ -297,7 +265,7 @@ impl Node for FunctionDefinition { } } -impl Node for ConstructorParameterDefinition { +impl Node for MethodParameterDefinition { fn comments(&self) -> Option<&CommentGroup> { Some(&self.comments) } @@ -329,11 +297,11 @@ impl Node for ConstructorParameterDefinition { } fn get_description(&self) -> String { - "constructor parameter definition".to_string() + "method parameter definition".to_string() } } -impl Node for ConstructorParameterListDefinition { +impl Node for MethodParameterListDefinition { fn comments(&self) -> Option<&CommentGroup> { Some(&self.comments) } @@ -357,130 +325,7 @@ impl Node for ConstructorParameterListDefinition { } fn get_description(&self) -> String { - "constructor parameter list definition".to_string() - } -} - -impl Node for AbstractConstructorDefinition { - fn comments(&self) -> Option<&CommentGroup> { - Some(&self.comments) - } - - fn initial_position(&self) -> usize { - if let Some(attributes) = self.attributes.first() { - return attributes.initial_position(); - } - - self.modifiers.initial_position() - } - - fn final_position(&self) -> usize { - self.semicolon + 1 - } - - fn children(&self) -> Vec<&dyn Node> { - let mut children: Vec<&dyn Node> = vec![]; - - for attribute in &self.attributes { - children.push(attribute); - } - - children.push(&self.modifiers); - - children.push(&self.function); - children.push(&self.name); - children.push(&self.parameters); - - children - } - - fn get_description(&self) -> String { - "abstract constructor definition".to_string() - } -} - -impl Node for ConcreteConstructorDefinition { - fn comments(&self) -> Option<&CommentGroup> { - Some(&self.comments) - } - - fn initial_position(&self) -> usize { - if let Some(attributes) = self.attributes.first() { - return attributes.initial_position(); - } - - self.modifiers.initial_position() - } - - fn final_position(&self) -> usize { - self.body.final_position() - } - - fn children(&self) -> Vec<&dyn Node> { - let mut children: Vec<&dyn Node> = vec![]; - - for attribute in &self.attributes { - children.push(attribute); - } - - children.push(&self.modifiers); - children.push(&self.function); - children.push(&self.name); - children.push(&self.parameters); - children.push(&self.body); - - children - } - - fn get_description(&self) -> String { - "concrete constructor definition".to_string() - } -} - -impl Node for AbstractMethodDefinition { - fn comments(&self) -> Option<&CommentGroup> { - Some(&self.comments) - } - - fn initial_position(&self) -> usize { - if let Some(attributes) = self.attributes.first() { - return attributes.initial_position(); - } - - self.modifiers.initial_position() - } - - fn final_position(&self) -> usize { - self.semicolon + 1 - } - - fn children(&self) -> Vec<&dyn Node> { - let mut children: Vec<&dyn Node> = vec![]; - - for attribute in &self.attributes { - children.push(attribute); - } - - children.push(&self.modifiers); - children.push(&self.function); - children.push(&self.name); - - if let Some(templates) = &self.templates { - children.push(templates); - } - - children.push(&self.parameters); - children.push(&self.return_type); - - if let Some(constraints) = &self.constraints { - children.push(constraints); - } - - children - } - - fn get_description(&self) -> String { - "abstract method definition".to_string() + "method parameter list definition".to_string() } } @@ -542,7 +387,34 @@ impl Node for MethodTypeConstraintGroupDefinition { } } -impl Node for ConcreteMethodDefinition { +impl Node for MethodBodyDefinition { + fn initial_position(&self) -> usize { + match &self { + MethodBodyDefinition::Concrete(block) => block.initial_position(), + MethodBodyDefinition::Abstract(semicolon) => *semicolon, + } + } + + fn final_position(&self) -> usize { + match &self { + MethodBodyDefinition::Concrete(block) => block.final_position(), + MethodBodyDefinition::Abstract(semicolon) => semicolon + 1, + } + } + + fn children(&self) -> Vec<&dyn Node> { + match &self { + MethodBodyDefinition::Concrete(block) => vec![block], + MethodBodyDefinition::Abstract(..) => vec![], + } + } + + fn get_description(&self) -> String { + "method body definition".to_string() + } +} + +impl Node for MethodDefinition { fn comments(&self) -> Option<&CommentGroup> { Some(&self.comments) } @@ -575,7 +447,9 @@ impl Node for ConcreteMethodDefinition { } children.push(&self.parameters); - children.push(&self.return_type); + if let Some(return_type) = &self.return_type { + children.push(return_type); + } if let Some(constraints) = &self.constraints { children.push(constraints); diff --git a/src/tree/definition/interface.rs b/src/tree/definition/interface.rs index 2297ca6..e229eb6 100644 --- a/src/tree/definition/interface.rs +++ b/src/tree/definition/interface.rs @@ -5,8 +5,7 @@ use serde::Serialize; use crate::tree::comment::CommentGroup; use crate::tree::definition::attribute::AttributeGroupDefinition; use crate::tree::definition::constant::ClassishConstantDefinition; -use crate::tree::definition::function::AbstractConstructorDefinition; -use crate::tree::definition::function::AbstractMethodDefinition; +use crate::tree::definition::function::MethodDefinition; use crate::tree::definition::template::TemplateGroupDefinition; use crate::tree::identifier::Identifier; use crate::tree::identifier::TemplatedIdentifier; @@ -45,8 +44,7 @@ pub struct InterfaceDefinitionBody { #[serde(rename_all = "snake_case", tag = "type", content = "value")] pub enum InterfaceDefinitionMember { Constant(ClassishConstantDefinition), - Constructor(AbstractConstructorDefinition), - Method(AbstractMethodDefinition), + Method(MethodDefinition), } impl Node for InterfaceDefinition { @@ -151,7 +149,6 @@ impl Node for InterfaceDefinitionMember { fn initial_position(&self) -> usize { match &self { Self::Constant(constant) => constant.initial_position(), - Self::Constructor(constructor) => constructor.initial_position(), Self::Method(method) => method.initial_position(), } } @@ -159,7 +156,6 @@ impl Node for InterfaceDefinitionMember { fn final_position(&self) -> usize { match &self { Self::Constant(constant) => constant.final_position(), - Self::Constructor(constructor) => constructor.final_position(), Self::Method(method) => method.final_position(), } } @@ -167,7 +163,6 @@ impl Node for InterfaceDefinitionMember { fn children(&self) -> Vec<&dyn Node> { match &self { Self::Constant(constant) => vec![constant], - Self::Constructor(constructor) => vec![constructor], Self::Method(method) => vec![method], } } @@ -175,7 +170,6 @@ impl Node for InterfaceDefinitionMember { fn get_description(&self) -> String { match &self { Self::Constant(constant) => constant.get_description(), - Self::Constructor(constructor) => constructor.get_description(), Self::Method(method) => method.get_description(), } } diff --git a/src/tree/expression/class.rs b/src/tree/expression/class.rs index 8d192e3..2c75ffb 100644 --- a/src/tree/expression/class.rs +++ b/src/tree/expression/class.rs @@ -4,12 +4,9 @@ use serde::Serialize; use crate::tree::comment::CommentGroup; use crate::tree::definition::attribute::AttributeGroupDefinition; +use crate::tree::definition::class::ClassDefinitionBody; use crate::tree::definition::class::ClassDefinitionExtends; use crate::tree::definition::class::ClassDefinitionImplements; -use crate::tree::definition::constant::ClassishConstantDefinition; -use crate::tree::definition::function::ConcreteConstructorDefinition; -use crate::tree::definition::function::ConcreteMethodDefinition; -use crate::tree::definition::property::PropertyDefinition; use crate::tree::expression::argument::ArgumentListExpression; use crate::tree::token::Keyword; use crate::tree::Node; @@ -23,24 +20,7 @@ pub struct AnonymousClassExpression { pub arguments: ArgumentListExpression, pub extends: Option, pub implements: Option, - pub body: AnonymousClassExpressionBody, -} - -#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct AnonymousClassExpressionBody { - pub left_brace: usize, - pub members: Vec, - pub right_brace: usize, -} - -#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize, JsonSchema)] -#[serde(rename_all = "snake_case", tag = "type", content = "value")] -pub enum AnonymousClassExpressionMember { - Constant(ClassishConstantDefinition), - Property(PropertyDefinition), - ConcreteMethod(ConcreteMethodDefinition), - ConcreteConstructor(ConcreteConstructorDefinition), + pub body: ClassDefinitionBody, } impl Node for AnonymousClassExpression { @@ -82,70 +62,3 @@ impl Node for AnonymousClassExpression { "anonymous class expression".to_string() } } - -impl Node for AnonymousClassExpressionMember { - fn comments(&self) -> Option<&CommentGroup> { - None - } - - fn initial_position(&self) -> usize { - match &self { - Self::Constant(constant) => constant.initial_position(), - Self::Property(property) => property.initial_position(), - Self::ConcreteMethod(method) => method.initial_position(), - Self::ConcreteConstructor(constructor) => constructor.initial_position(), - } - } - - fn final_position(&self) -> usize { - match &self { - Self::Constant(constant) => constant.final_position(), - Self::Property(property) => property.final_position(), - Self::ConcreteMethod(method) => method.final_position(), - Self::ConcreteConstructor(constructor) => constructor.final_position(), - } - } - - fn children(&self) -> Vec<&dyn Node> { - match &self { - Self::Constant(constant) => vec![constant], - Self::Property(property) => vec![property], - Self::ConcreteMethod(method) => vec![method], - Self::ConcreteConstructor(constructor) => vec![constructor], - } - } - - fn get_description(&self) -> String { - match &self { - Self::Constant(constant) => constant.get_description(), - Self::Property(property) => property.get_description(), - Self::ConcreteMethod(method) => method.get_description(), - Self::ConcreteConstructor(constructor) => constructor.get_description(), - } - } -} - -impl Node for AnonymousClassExpressionBody { - fn comments(&self) -> Option<&CommentGroup> { - None - } - - fn initial_position(&self) -> usize { - self.left_brace - } - - fn final_position(&self) -> usize { - self.right_brace + 1 - } - - fn children(&self) -> Vec<&dyn Node> { - self.members - .iter() - .map(|member| member as &dyn Node) - .collect() - } - - fn get_description(&self) -> String { - "anonymous class expression body".to_string() - } -} diff --git a/tests/samples/0003/error.txt b/tests/samples/0003/error.txt index 21e0994..78a24e6 100644 --- a/tests/samples/0003/error.txt +++ b/tests/samples/0003/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `[`, expected an expression +error[P0011]: unexpected token `[`, expected an expression --> 0003/code.ara:5:10 | 5 | $a = [ diff --git a/tests/samples/0023/error.txt b/tests/samples/0023/error.txt index 4984be4..015597c 100644 --- a/tests/samples/0023/error.txt +++ b/tests/samples/0023/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `implements`, expected `(` +error[P0011]: unexpected token `implements`, expected `(` --> 0023/code.ara:3:22 | 3 | return new class implements Foo, Bar {}; diff --git a/tests/samples/0029/error.txt b/tests/samples/0029/error.txt index a82bb1a..42f2be8 100644 --- a/tests/samples/0029/error.txt +++ b/tests/samples/0029/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `,`, expected `;` +error[P0011]: unexpected token `,`, expected `;` --> 0029/code.ara:1:18 | 1 | const int FOO = 1, BAR = 2; diff --git a/tests/samples/0036/tree.txt b/tests/samples/0036/tree.txt index dbfa97e..8c8006d 100644 --- a/tests/samples/0036/tree.txt +++ b/tests/samples/0036/tree.txt @@ -24,8 +24,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 10, members: [ - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -49,14 +49,15 @@ DefinitionTree { position: 32, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 43, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -113,14 +114,18 @@ DefinitionTree { }, right_parenthesis: 90, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 92, + statements: [], + right_brace: 93, }, - left_brace: 92, - statements: [], - right_brace: 93, - }, + ), }, ), ], diff --git a/tests/samples/0040/tree.txt b/tests/samples/0040/tree.txt index ff85688..fca5ac9 100644 --- a/tests/samples/0040/tree.txt +++ b/tests/samples/0040/tree.txt @@ -43,8 +43,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 36, members: [ - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -68,14 +68,15 @@ DefinitionTree { position: 59, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 70, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -132,14 +133,18 @@ DefinitionTree { }, right_parenthesis: 125, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 127, + statements: [], + right_brace: 128, }, - left_brace: 127, - statements: [], - right_brace: 128, - }, + ), }, ), ], diff --git a/tests/samples/0043/error.txt b/tests/samples/0043/error.txt index 8d23155..fd5af46 100644 --- a/tests/samples/0043/error.txt +++ b/tests/samples/0043/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `,`, expected `;` +error[P0011]: unexpected token `,`, expected `;` --> 0043/code.ara:10:35 | 10 | final public const u16 R = 344, P = 214; diff --git a/tests/samples/0046/tree.txt b/tests/samples/0046/tree.txt index 5cc14f5..7100b89 100644 --- a/tests/samples/0046/tree.txt +++ b/tests/samples/0046/tree.txt @@ -20,7 +20,7 @@ DefinitionTree { left_brace: 14, members: [ Method( - AbstractMethodDefinition { + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -45,7 +45,7 @@ DefinitionTree { value: "bar", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -56,20 +56,24 @@ DefinitionTree { }, right_parenthesis: 40, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 41, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 43, - value: "parent", + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 41, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 43, + value: "parent", + }, + templates: None, }, - templates: None, - }, - ), - }, + ), + }, + ), constraints: None, - semicolon: 49, + body: Abstract( + 49, + ), }, ), ], diff --git a/tests/samples/0047/tree.txt b/tests/samples/0047/tree.txt index 571e9e7..7c3dc0e 100644 --- a/tests/samples/0047/tree.txt +++ b/tests/samples/0047/tree.txt @@ -62,7 +62,7 @@ DefinitionTree { left_brace: 40, members: [ Method( - AbstractMethodDefinition { + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -87,7 +87,7 @@ DefinitionTree { value: "bar", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -98,20 +98,24 @@ DefinitionTree { }, right_parenthesis: 66, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 67, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 69, - value: "parent", + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 67, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 69, + value: "parent", + }, + templates: None, }, - templates: None, - }, - ), - }, + ), + }, + ), constraints: None, - semicolon: 75, + body: Abstract( + 75, + ), }, ), ], diff --git a/tests/samples/0048/tree.txt b/tests/samples/0048/tree.txt index b42aa75..cd5ed0d 100644 --- a/tests/samples/0048/tree.txt +++ b/tests/samples/0048/tree.txt @@ -24,8 +24,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 10, members: [ - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -50,7 +50,7 @@ DefinitionTree { value: "bar", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -61,62 +61,66 @@ DefinitionTree { }, right_parenthesis: 36, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 37, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 39, - value: "parent", + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 37, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 39, + value: "parent", + }, + templates: None, }, - templates: None, - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + ), }, - left_brace: 46, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: ExitConstruct( - ExitWith { - comments: CommentGroup { - comments: [], - }, - exit: Keyword { - value: "exit", - position: 56, - }, - left_parenthesis: 60, - value: Some( - Literal( - Integer( - LiteralInteger { - comments: CommentGroup { - comments: [], + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 46, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: ExitConstruct( + ExitWith { + comments: CommentGroup { + comments: [], + }, + exit: Keyword { + value: "exit", + position: 56, + }, + left_parenthesis: 60, + value: Some( + Literal( + Integer( + LiteralInteger { + comments: CommentGroup { + comments: [], + }, + value: "1", + position: 61, }, - value: "1", - position: 61, - }, + ), ), ), - ), - right_parenthesis: 62, - }, - ), - semicolon: 63, - }, - ), - ], - right_brace: 69, - }, + right_parenthesis: 62, + }, + ), + semicolon: 63, + }, + ), + ], + right_brace: 69, + }, + ), }, ), ], diff --git a/tests/samples/0049/tree.txt b/tests/samples/0049/tree.txt index 814b40d..b0df2b1 100644 --- a/tests/samples/0049/tree.txt +++ b/tests/samples/0049/tree.txt @@ -66,8 +66,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 32, members: [ - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -92,7 +92,7 @@ DefinitionTree { value: "bar", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -103,71 +103,75 @@ DefinitionTree { }, right_parenthesis: 58, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 59, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 61, - value: "parent", + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 59, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 61, + value: "parent", + }, + templates: None, }, - templates: None, - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + ), }, - left_brace: 68, - statements: [ - Return( - Explicit { - comments: CommentGroup { - comments: [], - }, - return: Keyword { - value: "return", - position: 78, - }, - expression: Some( - ClassOperation( - Initialization { - comments: CommentGroup { - comments: [], - }, - new: Keyword { - value: "new", - position: 85, - }, - class: Identifier( - Identifier { - position: 89, - value: "s", - }, - ), - generics: None, - arguments: ArgumentListExpression { + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 68, + statements: [ + Return( + Explicit { + comments: CommentGroup { + comments: [], + }, + return: Keyword { + value: "return", + position: 78, + }, + expression: Some( + ClassOperation( + Initialization { comments: CommentGroup { comments: [], }, - left_parenthesis: 90, - arguments: CommaSeparated { - inner: [], - commas: [], + new: Keyword { + value: "new", + position: 85, + }, + class: Identifier( + Identifier { + position: 89, + value: "s", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 90, + arguments: CommaSeparated { + inner: [], + commas: [], + }, + right_parenthesis: 91, }, - right_parenthesis: 91, }, - }, + ), ), - ), - semicolon: 92, - }, - ), - ], - right_brace: 98, - }, + semicolon: 92, + }, + ), + ], + right_brace: 98, + }, + ), }, ), ], diff --git a/tests/samples/0050/tree.txt b/tests/samples/0050/tree.txt index 8006f19..39761a5 100644 --- a/tests/samples/0050/tree.txt +++ b/tests/samples/0050/tree.txt @@ -20,7 +20,7 @@ DefinitionTree { left_brace: 9, members: [ Method( - ConcreteMethodDefinition { + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -45,7 +45,7 @@ DefinitionTree { value: "bar", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -56,62 +56,66 @@ DefinitionTree { }, right_parenthesis: 35, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 36, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 38, - value: "parent", + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 36, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 38, + value: "parent", + }, + templates: None, }, - templates: None, - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + ), }, - left_brace: 45, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: ExitConstruct( - ExitWith { - comments: CommentGroup { - comments: [], - }, - exit: Keyword { - value: "exit", - position: 55, - }, - left_parenthesis: 59, - value: Some( - Literal( - Integer( - LiteralInteger { - comments: CommentGroup { - comments: [], + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 45, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: ExitConstruct( + ExitWith { + comments: CommentGroup { + comments: [], + }, + exit: Keyword { + value: "exit", + position: 55, + }, + left_parenthesis: 59, + value: Some( + Literal( + Integer( + LiteralInteger { + comments: CommentGroup { + comments: [], + }, + value: "1", + position: 60, }, - value: "1", - position: 60, - }, + ), ), ), - ), - right_parenthesis: 61, - }, - ), - semicolon: 62, - }, - ), - ], - right_brace: 68, - }, + right_parenthesis: 61, + }, + ), + semicolon: 62, + }, + ), + ], + right_brace: 68, + }, + ), }, ), ], diff --git a/tests/samples/0055/tree.txt b/tests/samples/0055/tree.txt index 52ece8b..57b3404 100644 --- a/tests/samples/0055/tree.txt +++ b/tests/samples/0055/tree.txt @@ -65,8 +65,8 @@ DefinitionTree { semicolon: 32, }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -97,7 +97,7 @@ DefinitionTree { value: "foo", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -108,103 +108,107 @@ DefinitionTree { }, right_parenthesis: 66, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 67, - type_definition: Void( - Keyword { - value: "void", - position: 69, - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 67, + type_definition: Void( + Keyword { + value: "void", + position: 69, + }, + ), }, - left_brace: 74, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: Variable( - Variable { - position: 84, - name: "$a", + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 74, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { + comments: CommentGroup { + comments: [], }, - ), - equals: 87, - right: ClassOperation( - ConstantFetch { - comments: CommentGroup { - comments: [], + left: Variable( + Variable { + position: 84, + name: "$a", }, - class: Identifier( - Identifier { - position: 89, - value: "static", + ), + equals: 87, + right: ClassOperation( + ConstantFetch { + comments: CommentGroup { + comments: [], + }, + class: Identifier( + Identifier { + position: 89, + value: "static", + }, + ), + double_colon: 95, + constant: Identifier { + position: 97, + value: "foo", }, - ), - double_colon: 95, - constant: Identifier { - position: 97, - value: "foo", }, - }, - ), - }, - ), - semicolon: 100, - }, - ), - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: ClassOperation( - StaticMethodCall { - comments: CommentGroup { - comments: [], - }, - class: Identifier( - Identifier { - position: 111, - value: "static", - }, - ), - double_colon: 117, - method: Identifier { - position: 119, - value: "foo", + ), }, - generics: None, - arguments: ArgumentListExpression { + ), + semicolon: 100, + }, + ), + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: ClassOperation( + StaticMethodCall { comments: CommentGroup { comments: [], }, - left_parenthesis: 122, - arguments: CommaSeparated { - inner: [], - commas: [], + class: Identifier( + Identifier { + position: 111, + value: "static", + }, + ), + double_colon: 117, + method: Identifier { + position: 119, + value: "foo", + }, + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 122, + arguments: CommaSeparated { + inner: [], + commas: [], + }, + right_parenthesis: 123, }, - right_parenthesis: 123, }, - }, - ), - semicolon: 124, - }, - ), - ], - right_brace: 130, - }, + ), + semicolon: 124, + }, + ), + ], + right_brace: 130, + }, + ), }, ), ], diff --git a/tests/samples/0057/tree.txt b/tests/samples/0057/tree.txt index 35f3264..824e3d1 100644 --- a/tests/samples/0057/tree.txt +++ b/tests/samples/0057/tree.txt @@ -390,7 +390,7 @@ DefinitionTree { }, ), Method( - AbstractMethodDefinition { + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -432,7 +432,7 @@ DefinitionTree { value: "bar", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -443,21 +443,25 @@ DefinitionTree { }, right_parenthesis: 251, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 252, - type_definition: Void( - Keyword { - value: "void", - position: 254, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 252, + type_definition: Void( + Keyword { + value: "void", + position: 254, + }, + ), + }, + ), constraints: None, - semicolon: 258, + body: Abstract( + 258, + ), }, ), Method( - AbstractMethodDefinition { + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -521,7 +525,7 @@ DefinitionTree { value: "baz", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -532,17 +536,21 @@ DefinitionTree { }, right_parenthesis: 310, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 311, - type_definition: Void( - Keyword { - value: "void", - position: 313, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 311, + type_definition: Void( + Keyword { + value: "void", + position: 313, + }, + ), + }, + ), constraints: None, - semicolon: 317, + body: Abstract( + 317, + ), }, ), ], diff --git a/tests/samples/0065/error.txt b/tests/samples/0065/error.txt index c5ecfba..ca14246 100644 --- a/tests/samples/0065/error.txt +++ b/tests/samples/0065/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `[`, expected an expression +error[P0011]: unexpected token `[`, expected an expression --> 0065/code.ara:2:10 | 2 | $a = [1, 2, 3]; diff --git a/tests/samples/0067/error.txt b/tests/samples/0067/error.txt index fc25534..4826008 100644 --- a/tests/samples/0067/error.txt +++ b/tests/samples/0067/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `[`, expected an expression +error[P0011]: unexpected token `[`, expected an expression --> 0067/code.ara:2:10 | 2 | $a = []; diff --git a/tests/samples/0068/error.txt b/tests/samples/0068/error.txt index ab1f0c8..3021000 100644 --- a/tests/samples/0068/error.txt +++ b/tests/samples/0068/error.txt @@ -1,4 +1,4 @@ -error[P0013]: unexpected token `[`, expected an expression +error[P0011]: unexpected token `[`, expected an expression --> 0068/code.ara:2:10 | 2 | $a = []; diff --git a/tests/samples/0071/tree.txt b/tests/samples/0071/tree.txt index e5cab22..6f68cfd 100644 --- a/tests/samples/0071/tree.txt +++ b/tests/samples/0071/tree.txt @@ -812,8 +812,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 391, members: [ - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -837,14 +837,15 @@ DefinitionTree { position: 413, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 424, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -881,14 +882,18 @@ DefinitionTree { }, right_parenthesis: 440, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 442, + statements: [], + right_brace: 443, }, - left_brace: 442, - statements: [], - right_brace: 443, - }, + ), }, ), ], diff --git a/tests/samples/0075/tree.txt b/tests/samples/0075/tree.txt index 4ede127..0f42f9b 100644 --- a/tests/samples/0075/tree.txt +++ b/tests/samples/0075/tree.txt @@ -95,8 +95,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 58, members: [ - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -120,14 +120,15 @@ DefinitionTree { position: 80, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 91, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -205,18 +206,22 @@ DefinitionTree { }, right_parenthesis: 136, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 138, + statements: [], + right_brace: 139, }, - left_brace: 138, - statements: [], - right_brace: 139, - }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -241,18 +246,22 @@ DefinitionTree { value: "filter", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 168, parameters: CommaSeparated { inner: [ - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 169, + modifiers: [], + }, type_definition: Identifier( TemplatedIdentifier { name: Identifier { @@ -313,311 +322,315 @@ DefinitionTree { }, right_parenthesis: 193, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 194, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 196, - value: "Collection", - }, - templates: Some( - TypeTemplateGroupDefinition { - comments: CommentGroup { - comments: [], - }, - less_than: 206, - members: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 207, - value: "T", - }, - templates: None, - }, - ), - ], - commas: [], - }, - greater_than: 208, - }, - ), - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], - }, - left_brace: 210, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 194, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 196, + value: "Collection", }, - expression: AssignmentOperation( - Assignment { + templates: Some( + TypeTemplateGroupDefinition { comments: CommentGroup { comments: [], }, - left: Variable( - Variable { - position: 220, - name: "$result", - }, - ), - equals: 228, - right: Vec( - VecExpression { - comments: CommentGroup { - comments: [], - }, - vec: Keyword { - value: "vec", - position: 230, - }, - left_bracket: 233, - elements: CommaSeparated { - inner: [], - commas: [], - }, - right_bracket: 234, - }, - ), + less_than: 206, + members: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 207, + value: "T", + }, + templates: None, + }, + ), + ], + commas: [], + }, + greater_than: 208, }, ), - semicolon: 235, }, ), - Foreach( - ForeachStatement { - comments: CommentGroup { - comments: [], - }, - foreach: Keyword { - value: "foreach", - position: 245, - }, - iterator: Value { - expression: ObjectOperation( - PropertyFetch { + }, + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 210, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { comments: CommentGroup { comments: [], }, - object: Variable( + left: Variable( Variable { - position: 253, - name: "$this", + position: 220, + name: "$result", + }, + ), + equals: 228, + right: Vec( + VecExpression { + comments: CommentGroup { + comments: [], + }, + vec: Keyword { + value: "vec", + position: 230, + }, + left_bracket: 233, + elements: CommaSeparated { + inner: [], + commas: [], + }, + right_bracket: 234, }, ), - arrow: 258, - property: Identifier { - position: 260, - value: "items", - }, }, ), - as: Keyword { - value: "as", - position: 266, - }, - value: Variable { - position: 269, - name: "$item", - }, + semicolon: 235, }, - block: BlockStatement { + ), + Foreach( + ForeachStatement { comments: CommentGroup { comments: [], }, - left_brace: 275, - statements: [ - If( - IfStatement { + foreach: Keyword { + value: "foreach", + position: 245, + }, + iterator: Value { + expression: ObjectOperation( + PropertyFetch { comments: CommentGroup { comments: [], }, - if: Keyword { - value: "if", - position: 289, + object: Variable( + Variable { + position: 253, + name: "$this", + }, + ), + arrow: 258, + property: Identifier { + position: 260, + value: "items", }, - condition: FunctionOperation( - Call { - comments: CommentGroup { - comments: [], - }, - function: Variable( - Variable { - position: 292, - name: "$func", - }, - ), - generics: None, - arguments: ArgumentListExpression { + }, + ), + as: Keyword { + value: "as", + position: 266, + }, + value: Variable { + position: 269, + name: "$item", + }, + }, + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 275, + statements: [ + If( + IfStatement { + comments: CommentGroup { + comments: [], + }, + if: Keyword { + value: "if", + position: 289, + }, + condition: FunctionOperation( + Call { comments: CommentGroup { comments: [], }, - left_parenthesis: 297, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], + function: Variable( + Variable { + position: 292, + name: "$func", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 297, + arguments: CommaSeparated { + inner: [ + Value { + comments: CommentGroup { + comments: [], + }, + value: Variable( + Variable { + position: 298, + name: "$item", + }, + ), }, - value: Variable( - Variable { - position: 298, - name: "$item", + ], + commas: [], + }, + right_parenthesis: 303, + }, + }, + ), + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 305, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { + comments: CommentGroup { + comments: [], }, - ), + left: ArrayOperation( + Push { + comments: CommentGroup { + comments: [], + }, + array: Variable( + Variable { + position: 323, + name: "$result", + }, + ), + left_bracket: 330, + right_bracket: 331, + }, + ), + equals: 333, + right: Variable( + Variable { + position: 335, + name: "$item", + }, + ), + }, + ), + semicolon: 340, + }, + ), + ], + right_brace: 354, + }, + elseifs: [], + else: None, + }, + ), + ], + right_brace: 364, + }, + }, + ), + Return( + Explicit { + comments: CommentGroup { + comments: [], + }, + return: Keyword { + value: "return", + position: 375, + }, + expression: Some( + ClassOperation( + Initialization { + comments: CommentGroup { + comments: [], + }, + new: Keyword { + value: "new", + position: 382, + }, + class: Identifier( + Identifier { + position: 386, + value: "Collection", + }, + ), + generics: Some( + GenericGroupExpression { + double_colon_less_than: 396, + types: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 399, + value: "T", + }, + templates: None, }, - ], - commas: [], - }, - right_parenthesis: 303, + ), + ], + commas: [], }, + greater_than: 400, }, ), - block: BlockStatement { + arguments: ArgumentListExpression { comments: CommentGroup { comments: [], }, - left_brace: 305, - statements: [ - Expression( - ExpressionStatement { + left_parenthesis: 401, + arguments: CommaSeparated { + inner: [ + Value { comments: CommentGroup { comments: [], }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: ArrayOperation( - Push { - comments: CommentGroup { - comments: [], - }, - array: Variable( - Variable { - position: 323, - name: "$result", - }, - ), - left_bracket: 330, - right_bracket: 331, - }, - ), - equals: 333, - right: Variable( - Variable { - position: 335, - name: "$item", - }, - ), + value: Variable( + Variable { + position: 402, + name: "$result", }, ), - semicolon: 340, }, - ), - ], - right_brace: 354, - }, - elseifs: [], - else: None, - }, - ), - ], - right_brace: 364, - }, - }, - ), - Return( - Explicit { - comments: CommentGroup { - comments: [], - }, - return: Keyword { - value: "return", - position: 375, - }, - expression: Some( - ClassOperation( - Initialization { - comments: CommentGroup { - comments: [], - }, - new: Keyword { - value: "new", - position: 382, - }, - class: Identifier( - Identifier { - position: 386, - value: "Collection", - }, - ), - generics: Some( - GenericGroupExpression { - double_colon_less_than: 396, - types: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 399, - value: "T", - }, - templates: None, - }, - ), ], commas: [], }, - greater_than: 400, - }, - ), - arguments: ArgumentListExpression { - comments: CommentGroup { - comments: [], - }, - left_parenthesis: 401, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], - }, - value: Variable( - Variable { - position: 402, - name: "$result", - }, - ), - }, - ], - commas: [], + right_parenthesis: 409, }, - right_parenthesis: 409, }, - }, + ), ), - ), - semicolon: 410, - }, - ), - ], - right_brace: 416, - }, + semicolon: 410, + }, + ), + ], + right_brace: 416, + }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -663,18 +676,22 @@ DefinitionTree { greater_than: 447, }, ), - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 448, parameters: CommaSeparated { inner: [ - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 449, + modifiers: [], + }, type_definition: Identifier( TemplatedIdentifier { name: Identifier { @@ -738,283 +755,287 @@ DefinitionTree { }, right_parenthesis: 473, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 474, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 476, - value: "Collection", - }, - templates: Some( - TypeTemplateGroupDefinition { - comments: CommentGroup { - comments: [], - }, - less_than: 486, - members: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 487, - value: "Tout", - }, - templates: None, - }, - ), - ], - commas: [], - }, - greater_than: 491, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 474, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 476, + value: "Collection", }, - ), - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], - }, - left_brace: 493, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: AssignmentOperation( - Assignment { + templates: Some( + TypeTemplateGroupDefinition { comments: CommentGroup { comments: [], }, - left: Variable( - Variable { - position: 503, - name: "$result", - }, - ), - equals: 511, - right: Vec( - VecExpression { - comments: CommentGroup { - comments: [], - }, - vec: Keyword { - value: "vec", - position: 513, - }, - left_bracket: 516, - elements: CommaSeparated { - inner: [], - commas: [], - }, - right_bracket: 517, - }, - ), + less_than: 486, + members: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 487, + value: "Tout", + }, + templates: None, + }, + ), + ], + commas: [], + }, + greater_than: 491, }, ), - semicolon: 518, }, ), - Foreach( - ForeachStatement { - comments: CommentGroup { - comments: [], - }, - foreach: Keyword { - value: "foreach", - position: 528, - }, - iterator: Value { - expression: ObjectOperation( - PropertyFetch { + }, + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 493, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { comments: CommentGroup { comments: [], }, - object: Variable( + left: Variable( Variable { - position: 536, - name: "$this", + position: 503, + name: "$result", + }, + ), + equals: 511, + right: Vec( + VecExpression { + comments: CommentGroup { + comments: [], + }, + vec: Keyword { + value: "vec", + position: 513, + }, + left_bracket: 516, + elements: CommaSeparated { + inner: [], + commas: [], + }, + right_bracket: 517, }, ), - arrow: 541, - property: Identifier { - position: 543, - value: "items", - }, }, ), - as: Keyword { - value: "as", - position: 549, - }, - value: Variable { - position: 552, - name: "$item", - }, + semicolon: 518, }, - block: BlockStatement { + ), + Foreach( + ForeachStatement { comments: CommentGroup { comments: [], }, - left_brace: 558, - statements: [ - Expression( - ExpressionStatement { + foreach: Keyword { + value: "foreach", + position: 528, + }, + iterator: Value { + expression: ObjectOperation( + PropertyFetch { comments: CommentGroup { comments: [], }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: ArrayOperation( - Push { - comments: CommentGroup { - comments: [], - }, - array: Variable( - Variable { - position: 572, - name: "$result", - }, - ), - left_bracket: 579, - right_bracket: 580, + object: Variable( + Variable { + position: 536, + name: "$this", + }, + ), + arrow: 541, + property: Identifier { + position: 543, + value: "items", + }, + }, + ), + as: Keyword { + value: "as", + position: 549, + }, + value: Variable { + position: 552, + name: "$item", + }, + }, + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 558, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { + comments: CommentGroup { + comments: [], }, - ), - equals: 582, - right: FunctionOperation( - Call { - comments: CommentGroup { - comments: [], - }, - function: Variable( - Variable { - position: 584, - name: "$func", + left: ArrayOperation( + Push { + comments: CommentGroup { + comments: [], }, - ), - generics: None, - arguments: ArgumentListExpression { + array: Variable( + Variable { + position: 572, + name: "$result", + }, + ), + left_bracket: 579, + right_bracket: 580, + }, + ), + equals: 582, + right: FunctionOperation( + Call { comments: CommentGroup { comments: [], }, - left_parenthesis: 589, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], - }, - value: Variable( - Variable { - position: 590, - name: "$item", + function: Variable( + Variable { + position: 584, + name: "$func", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 589, + arguments: CommaSeparated { + inner: [ + Value { + comments: CommentGroup { + comments: [], }, - ), - }, - ], - commas: [], - }, - right_parenthesis: 595, - }, - }, - ), - }, - ), - semicolon: 596, - }, - ), - ], - right_brace: 606, - }, - }, - ), - Return( - Explicit { - comments: CommentGroup { - comments: [], - }, - return: Keyword { - value: "return", - position: 617, - }, - expression: Some( - ClassOperation( - Initialization { - comments: CommentGroup { - comments: [], - }, - new: Keyword { - value: "new", - position: 624, - }, - class: Identifier( - Identifier { - position: 628, - value: "Collection", - }, - ), - generics: Some( - GenericGroupExpression { - double_colon_less_than: 638, - types: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 641, - value: "Tout", + value: Variable( + Variable { + position: 590, + name: "$item", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 595, }, - templates: None, }, ), - ], - commas: [], - }, - greater_than: 645, + }, + ), + semicolon: 596, }, ), - arguments: ArgumentListExpression { + ], + right_brace: 606, + }, + }, + ), + Return( + Explicit { + comments: CommentGroup { + comments: [], + }, + return: Keyword { + value: "return", + position: 617, + }, + expression: Some( + ClassOperation( + Initialization { comments: CommentGroup { comments: [], }, - left_parenthesis: 646, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], - }, - value: Variable( - Variable { - position: 647, - name: "$result", - }, - ), + new: Keyword { + value: "new", + position: 624, + }, + class: Identifier( + Identifier { + position: 628, + value: "Collection", + }, + ), + generics: Some( + GenericGroupExpression { + double_colon_less_than: 638, + types: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 641, + value: "Tout", + }, + templates: None, + }, + ), + ], + commas: [], }, - ], - commas: [], + greater_than: 645, + }, + ), + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 646, + arguments: CommaSeparated { + inner: [ + Value { + comments: CommentGroup { + comments: [], + }, + value: Variable( + Variable { + position: 647, + name: "$result", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 654, }, - right_parenthesis: 654, }, - }, + ), ), - ), - semicolon: 655, - }, - ), - ], - right_brace: 661, - }, + semicolon: 655, + }, + ), + ], + right_brace: 661, + }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -1039,7 +1060,7 @@ DefinitionTree { value: "sum", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -1050,17 +1071,19 @@ DefinitionTree { }, right_parenthesis: 688, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 689, - type_definition: SignedInteger( - Default( - Keyword { - value: "int", - position: 691, - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 689, + type_definition: SignedInteger( + Default( + Keyword { + value: "int", + position: 691, + }, + ), ), - ), - }, + }, + ), constraints: Some( MethodTypeConstraintGroupDefinition { comments: CommentGroup { @@ -1099,137 +1122,139 @@ DefinitionTree { }, }, ), - body: BlockStatement { - comments: CommentGroup { - comments: [], - }, - left_brace: 710, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: Variable( - Variable { - position: 720, - name: "$result", - }, - ), - equals: 728, - right: Literal( - Integer( - LiteralInteger { - comments: CommentGroup { - comments: [], - }, - value: "0", - position: 730, - }, - ), - ), + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 710, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], }, - ), - semicolon: 731, - }, - ), - Foreach( - ForeachStatement { - comments: CommentGroup { - comments: [], - }, - foreach: Keyword { - value: "foreach", - position: 741, - }, - iterator: Value { - expression: ObjectOperation( - PropertyFetch { + expression: AssignmentOperation( + Assignment { comments: CommentGroup { comments: [], }, - object: Variable( + left: Variable( Variable { - position: 749, - name: "$this", + position: 720, + name: "$result", }, ), - arrow: 754, - property: Identifier { - position: 756, - value: "items", - }, + equals: 728, + right: Literal( + Integer( + LiteralInteger { + comments: CommentGroup { + comments: [], + }, + value: "0", + position: 730, + }, + ), + ), }, ), - as: Keyword { - value: "as", - position: 762, - }, - value: Variable { - position: 765, - name: "$item", - }, + semicolon: 731, }, - block: BlockStatement { + ), + Foreach( + ForeachStatement { comments: CommentGroup { comments: [], }, - left_brace: 771, - statements: [ - Expression( - ExpressionStatement { + foreach: Keyword { + value: "foreach", + position: 741, + }, + iterator: Value { + expression: ObjectOperation( + PropertyFetch { comments: CommentGroup { comments: [], }, - expression: AssignmentOperation( - Addition { - comments: CommentGroup { - comments: [], - }, - left: Variable( - Variable { - position: 785, - name: "$result", - }, - ), - plus_equals: 793, - right: Variable( - Variable { - position: 796, - name: "$item", - }, - ), + object: Variable( + Variable { + position: 749, + name: "$this", }, ), - semicolon: 801, + arrow: 754, + property: Identifier { + position: 756, + value: "items", + }, }, ), - ], - right_brace: 811, - }, - }, - ), - Return( - Implicit { - comments: CommentGroup { - comments: [], + as: Keyword { + value: "as", + position: 762, + }, + value: Variable { + position: 765, + name: "$item", + }, + }, + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 771, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Addition { + comments: CommentGroup { + comments: [], + }, + left: Variable( + Variable { + position: 785, + name: "$result", + }, + ), + plus_equals: 793, + right: Variable( + Variable { + position: 796, + name: "$item", + }, + ), + }, + ), + semicolon: 801, + }, + ), + ], + right_brace: 811, + }, }, - expression: Variable( - Variable { - position: 822, - name: "$result", + ), + Return( + Implicit { + comments: CommentGroup { + comments: [], }, - ), - }, - ), - ], - right_brace: 834, - }, + expression: Variable( + Variable { + position: 822, + name: "$result", + }, + ), + }, + ), + ], + right_brace: 834, + }, + ), }, ), ], diff --git a/tests/samples/0076/tree.txt b/tests/samples/0076/tree.txt index 0fb8f3a..738cf2a 100644 --- a/tests/samples/0076/tree.txt +++ b/tests/samples/0076/tree.txt @@ -143,8 +143,8 @@ DefinitionTree { semicolon: 100, }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -169,7 +169,7 @@ DefinitionTree { value: "where", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -180,24 +180,28 @@ DefinitionTree { }, right_parenthesis: 129, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 130, - type_definition: Void( - Keyword { - value: "void", - position: 132, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 130, + type_definition: Void( + Keyword { + value: "void", + position: 132, + }, + ), + }, + ), constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 137, + statements: [], + right_brace: 138, }, - left_brace: 137, - statements: [], - right_brace: 138, - }, + ), }, ), ], @@ -813,8 +817,8 @@ DefinitionTree { semicolon: 518, }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -839,7 +843,7 @@ DefinitionTree { value: "type", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -850,24 +854,28 @@ DefinitionTree { }, right_parenthesis: 546, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 547, - type_definition: Void( - Keyword { - value: "void", - position: 549, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 547, + type_definition: Void( + Keyword { + value: "void", + position: 549, + }, + ), + }, + ), constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 554, + statements: [], + right_brace: 555, }, - left_brace: 554, - statements: [], - right_brace: 555, - }, + ), }, ), ], diff --git a/tests/samples/0079/tree.txt b/tests/samples/0079/tree.txt index b779e25..f2848c4 100644 --- a/tests/samples/0079/tree.txt +++ b/tests/samples/0079/tree.txt @@ -110,7 +110,7 @@ DefinitionTree { }, }, ), - body: AnonymousClassExpressionBody { + body: ClassDefinitionBody { left_brace: 69, members: [], right_brace: 70, diff --git a/tests/samples/0082/tree.txt b/tests/samples/0082/tree.txt index 67bf7df..863068e 100644 --- a/tests/samples/0082/tree.txt +++ b/tests/samples/0082/tree.txt @@ -95,8 +95,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 58, members: [ - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -120,14 +120,15 @@ DefinitionTree { position: 80, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 91, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -205,18 +206,22 @@ DefinitionTree { }, right_parenthesis: 136, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 138, + statements: [], + right_brace: 139, }, - left_brace: 138, - statements: [], - right_brace: 139, - }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -241,18 +246,22 @@ DefinitionTree { value: "filter", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 168, parameters: CommaSeparated { inner: [ - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 169, + modifiers: [], + }, type_definition: Identifier( TemplatedIdentifier { name: Identifier { @@ -313,311 +322,315 @@ DefinitionTree { }, right_parenthesis: 193, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 194, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 196, - value: "Collection", - }, - templates: Some( - TypeTemplateGroupDefinition { - comments: CommentGroup { - comments: [], - }, - less_than: 206, - members: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 207, - value: "T", - }, - templates: None, - }, - ), - ], - commas: [], - }, - greater_than: 208, - }, - ), - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], - }, - left_brace: 210, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 194, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 196, + value: "Collection", }, - expression: AssignmentOperation( - Assignment { + templates: Some( + TypeTemplateGroupDefinition { comments: CommentGroup { comments: [], }, - left: Variable( - Variable { - position: 220, - name: "$result", - }, - ), - equals: 228, - right: Vec( - VecExpression { - comments: CommentGroup { - comments: [], - }, - vec: Keyword { - value: "vec", - position: 230, - }, - left_bracket: 233, - elements: CommaSeparated { - inner: [], - commas: [], - }, - right_bracket: 234, - }, - ), + less_than: 206, + members: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 207, + value: "T", + }, + templates: None, + }, + ), + ], + commas: [], + }, + greater_than: 208, }, ), - semicolon: 235, }, ), - Foreach( - ForeachStatement { - comments: CommentGroup { - comments: [], - }, - foreach: Keyword { - value: "foreach", - position: 245, - }, - iterator: Value { - expression: ObjectOperation( - PropertyFetch { + }, + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 210, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { comments: CommentGroup { comments: [], }, - object: Variable( + left: Variable( Variable { - position: 253, - name: "$this", + position: 220, + name: "$result", + }, + ), + equals: 228, + right: Vec( + VecExpression { + comments: CommentGroup { + comments: [], + }, + vec: Keyword { + value: "vec", + position: 230, + }, + left_bracket: 233, + elements: CommaSeparated { + inner: [], + commas: [], + }, + right_bracket: 234, }, ), - arrow: 258, - property: Identifier { - position: 260, - value: "items", - }, }, ), - as: Keyword { - value: "as", - position: 266, - }, - value: Variable { - position: 269, - name: "$item", - }, + semicolon: 235, }, - block: BlockStatement { + ), + Foreach( + ForeachStatement { comments: CommentGroup { comments: [], }, - left_brace: 275, - statements: [ - If( - IfStatement { + foreach: Keyword { + value: "foreach", + position: 245, + }, + iterator: Value { + expression: ObjectOperation( + PropertyFetch { comments: CommentGroup { comments: [], }, - if: Keyword { - value: "if", - position: 289, + object: Variable( + Variable { + position: 253, + name: "$this", + }, + ), + arrow: 258, + property: Identifier { + position: 260, + value: "items", }, - condition: FunctionOperation( - Call { - comments: CommentGroup { - comments: [], - }, - function: Variable( - Variable { - position: 292, - name: "$func", - }, - ), - generics: None, - arguments: ArgumentListExpression { + }, + ), + as: Keyword { + value: "as", + position: 266, + }, + value: Variable { + position: 269, + name: "$item", + }, + }, + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 275, + statements: [ + If( + IfStatement { + comments: CommentGroup { + comments: [], + }, + if: Keyword { + value: "if", + position: 289, + }, + condition: FunctionOperation( + Call { comments: CommentGroup { comments: [], }, - left_parenthesis: 297, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], + function: Variable( + Variable { + position: 292, + name: "$func", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 297, + arguments: CommaSeparated { + inner: [ + Value { + comments: CommentGroup { + comments: [], + }, + value: Variable( + Variable { + position: 298, + name: "$item", + }, + ), }, - value: Variable( - Variable { - position: 298, - name: "$item", + ], + commas: [], + }, + right_parenthesis: 303, + }, + }, + ), + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 305, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { + comments: CommentGroup { + comments: [], }, - ), + left: ArrayOperation( + Push { + comments: CommentGroup { + comments: [], + }, + array: Variable( + Variable { + position: 323, + name: "$result", + }, + ), + left_bracket: 330, + right_bracket: 331, + }, + ), + equals: 333, + right: Variable( + Variable { + position: 335, + name: "$item", + }, + ), + }, + ), + semicolon: 340, + }, + ), + ], + right_brace: 354, + }, + elseifs: [], + else: None, + }, + ), + ], + right_brace: 364, + }, + }, + ), + Return( + Explicit { + comments: CommentGroup { + comments: [], + }, + return: Keyword { + value: "return", + position: 375, + }, + expression: Some( + ClassOperation( + Initialization { + comments: CommentGroup { + comments: [], + }, + new: Keyword { + value: "new", + position: 382, + }, + class: Identifier( + Identifier { + position: 386, + value: "Collection", + }, + ), + generics: Some( + GenericGroupExpression { + double_colon_less_than: 396, + types: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 399, + value: "T", + }, + templates: None, }, - ], - commas: [], - }, - right_parenthesis: 303, + ), + ], + commas: [], }, + greater_than: 400, }, ), - block: BlockStatement { + arguments: ArgumentListExpression { comments: CommentGroup { comments: [], }, - left_brace: 305, - statements: [ - Expression( - ExpressionStatement { + left_parenthesis: 401, + arguments: CommaSeparated { + inner: [ + Value { comments: CommentGroup { comments: [], }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: ArrayOperation( - Push { - comments: CommentGroup { - comments: [], - }, - array: Variable( - Variable { - position: 323, - name: "$result", - }, - ), - left_bracket: 330, - right_bracket: 331, - }, - ), - equals: 333, - right: Variable( - Variable { - position: 335, - name: "$item", - }, - ), + value: Variable( + Variable { + position: 402, + name: "$result", }, ), - semicolon: 340, }, - ), - ], - right_brace: 354, - }, - elseifs: [], - else: None, - }, - ), - ], - right_brace: 364, - }, - }, - ), - Return( - Explicit { - comments: CommentGroup { - comments: [], - }, - return: Keyword { - value: "return", - position: 375, - }, - expression: Some( - ClassOperation( - Initialization { - comments: CommentGroup { - comments: [], - }, - new: Keyword { - value: "new", - position: 382, - }, - class: Identifier( - Identifier { - position: 386, - value: "Collection", - }, - ), - generics: Some( - GenericGroupExpression { - double_colon_less_than: 396, - types: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 399, - value: "T", - }, - templates: None, - }, - ), ], commas: [], }, - greater_than: 400, - }, - ), - arguments: ArgumentListExpression { - comments: CommentGroup { - comments: [], - }, - left_parenthesis: 401, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], - }, - value: Variable( - Variable { - position: 402, - name: "$result", - }, - ), - }, - ], - commas: [], + right_parenthesis: 409, }, - right_parenthesis: 409, }, - }, + ), ), - ), - semicolon: 410, - }, - ), - ], - right_brace: 416, - }, + semicolon: 410, + }, + ), + ], + right_brace: 416, + }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -663,18 +676,22 @@ DefinitionTree { greater_than: 447, }, ), - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 448, parameters: CommaSeparated { inner: [ - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 449, + modifiers: [], + }, type_definition: Identifier( TemplatedIdentifier { name: Identifier { @@ -738,283 +755,287 @@ DefinitionTree { }, right_parenthesis: 473, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 474, - type_definition: Identifier( - TemplatedIdentifier { - name: Identifier { - position: 476, - value: "Collection", - }, - templates: Some( - TypeTemplateGroupDefinition { - comments: CommentGroup { - comments: [], - }, - less_than: 486, - members: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 487, - value: "Tout", - }, - templates: None, - }, - ), - ], - commas: [], - }, - greater_than: 491, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 474, + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 476, + value: "Collection", }, - ), - }, - ), - }, - constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], - }, - left_brace: 493, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: AssignmentOperation( - Assignment { + templates: Some( + TypeTemplateGroupDefinition { comments: CommentGroup { comments: [], }, - left: Variable( - Variable { - position: 503, - name: "$result", - }, - ), - equals: 511, - right: Vec( - VecExpression { - comments: CommentGroup { - comments: [], - }, - vec: Keyword { - value: "vec", - position: 513, - }, - left_bracket: 516, - elements: CommaSeparated { - inner: [], - commas: [], - }, - right_bracket: 517, - }, - ), + less_than: 486, + members: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 487, + value: "Tout", + }, + templates: None, + }, + ), + ], + commas: [], + }, + greater_than: 491, }, ), - semicolon: 518, }, ), - Foreach( - ForeachStatement { - comments: CommentGroup { - comments: [], - }, - foreach: Keyword { - value: "foreach", - position: 528, - }, - iterator: Value { - expression: ObjectOperation( - PropertyFetch { + }, + ), + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 493, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { comments: CommentGroup { comments: [], }, - object: Variable( + left: Variable( Variable { - position: 536, - name: "$this", + position: 503, + name: "$result", + }, + ), + equals: 511, + right: Vec( + VecExpression { + comments: CommentGroup { + comments: [], + }, + vec: Keyword { + value: "vec", + position: 513, + }, + left_bracket: 516, + elements: CommaSeparated { + inner: [], + commas: [], + }, + right_bracket: 517, }, ), - arrow: 541, - property: Identifier { - position: 543, - value: "items", - }, }, ), - as: Keyword { - value: "as", - position: 549, - }, - value: Variable { - position: 552, - name: "$item", - }, + semicolon: 518, }, - block: BlockStatement { + ), + Foreach( + ForeachStatement { comments: CommentGroup { comments: [], }, - left_brace: 558, - statements: [ - Expression( - ExpressionStatement { + foreach: Keyword { + value: "foreach", + position: 528, + }, + iterator: Value { + expression: ObjectOperation( + PropertyFetch { comments: CommentGroup { comments: [], }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: ArrayOperation( - Push { - comments: CommentGroup { - comments: [], - }, - array: Variable( - Variable { - position: 572, - name: "$result", - }, - ), - left_bracket: 579, - right_bracket: 580, + object: Variable( + Variable { + position: 536, + name: "$this", + }, + ), + arrow: 541, + property: Identifier { + position: 543, + value: "items", + }, + }, + ), + as: Keyword { + value: "as", + position: 549, + }, + value: Variable { + position: 552, + name: "$item", + }, + }, + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 558, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Assignment { + comments: CommentGroup { + comments: [], }, - ), - equals: 582, - right: FunctionOperation( - Call { - comments: CommentGroup { - comments: [], - }, - function: Variable( - Variable { - position: 584, - name: "$func", + left: ArrayOperation( + Push { + comments: CommentGroup { + comments: [], }, - ), - generics: None, - arguments: ArgumentListExpression { + array: Variable( + Variable { + position: 572, + name: "$result", + }, + ), + left_bracket: 579, + right_bracket: 580, + }, + ), + equals: 582, + right: FunctionOperation( + Call { comments: CommentGroup { comments: [], }, - left_parenthesis: 589, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], - }, - value: Variable( - Variable { - position: 590, - name: "$item", + function: Variable( + Variable { + position: 584, + name: "$func", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 589, + arguments: CommaSeparated { + inner: [ + Value { + comments: CommentGroup { + comments: [], }, - ), - }, - ], - commas: [], - }, - right_parenthesis: 595, - }, - }, - ), - }, - ), - semicolon: 596, - }, - ), - ], - right_brace: 606, - }, - }, - ), - Return( - Explicit { - comments: CommentGroup { - comments: [], - }, - return: Keyword { - value: "return", - position: 617, - }, - expression: Some( - ClassOperation( - Initialization { - comments: CommentGroup { - comments: [], - }, - new: Keyword { - value: "new", - position: 624, - }, - class: Identifier( - Identifier { - position: 628, - value: "Collection", - }, - ), - generics: Some( - GenericGroupExpression { - double_colon_less_than: 638, - types: CommaSeparated { - inner: [ - Identifier( - TemplatedIdentifier { - name: Identifier { - position: 641, - value: "Tout", + value: Variable( + Variable { + position: 590, + name: "$item", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 595, }, - templates: None, }, ), - ], - commas: [], - }, - greater_than: 645, + }, + ), + semicolon: 596, }, ), - arguments: ArgumentListExpression { + ], + right_brace: 606, + }, + }, + ), + Return( + Explicit { + comments: CommentGroup { + comments: [], + }, + return: Keyword { + value: "return", + position: 617, + }, + expression: Some( + ClassOperation( + Initialization { comments: CommentGroup { comments: [], }, - left_parenthesis: 646, - arguments: CommaSeparated { - inner: [ - Value { - comments: CommentGroup { - comments: [], - }, - value: Variable( - Variable { - position: 647, - name: "$result", - }, - ), + new: Keyword { + value: "new", + position: 624, + }, + class: Identifier( + Identifier { + position: 628, + value: "Collection", + }, + ), + generics: Some( + GenericGroupExpression { + double_colon_less_than: 638, + types: CommaSeparated { + inner: [ + Identifier( + TemplatedIdentifier { + name: Identifier { + position: 641, + value: "Tout", + }, + templates: None, + }, + ), + ], + commas: [], }, - ], - commas: [], + greater_than: 645, + }, + ), + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 646, + arguments: CommaSeparated { + inner: [ + Value { + comments: CommentGroup { + comments: [], + }, + value: Variable( + Variable { + position: 647, + name: "$result", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 654, }, - right_parenthesis: 654, }, - }, + ), ), - ), - semicolon: 655, - }, - ), - ], - right_brace: 661, - }, + semicolon: 655, + }, + ), + ], + right_brace: 661, + }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -1039,7 +1060,7 @@ DefinitionTree { value: "sum", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -1050,17 +1071,19 @@ DefinitionTree { }, right_parenthesis: 688, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 689, - type_definition: SignedInteger( - Default( - Keyword { - value: "int", - position: 691, - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 689, + type_definition: SignedInteger( + Default( + Keyword { + value: "int", + position: 691, + }, + ), ), - ), - }, + }, + ), constraints: Some( MethodTypeConstraintGroupDefinition { comments: CommentGroup { @@ -1099,137 +1122,139 @@ DefinitionTree { }, }, ), - body: BlockStatement { - comments: CommentGroup { - comments: [], - }, - left_brace: 710, - statements: [ - Expression( - ExpressionStatement { - comments: CommentGroup { - comments: [], - }, - expression: AssignmentOperation( - Assignment { - comments: CommentGroup { - comments: [], - }, - left: Variable( - Variable { - position: 720, - name: "$result", - }, - ), - equals: 728, - right: Literal( - Integer( - LiteralInteger { - comments: CommentGroup { - comments: [], - }, - value: "0", - position: 730, - }, - ), - ), + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 710, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], }, - ), - semicolon: 731, - }, - ), - Foreach( - ForeachStatement { - comments: CommentGroup { - comments: [], - }, - foreach: Keyword { - value: "foreach", - position: 741, - }, - iterator: Value { - expression: ObjectOperation( - PropertyFetch { + expression: AssignmentOperation( + Assignment { comments: CommentGroup { comments: [], }, - object: Variable( + left: Variable( Variable { - position: 749, - name: "$this", + position: 720, + name: "$result", }, ), - arrow: 754, - property: Identifier { - position: 756, - value: "items", - }, + equals: 728, + right: Literal( + Integer( + LiteralInteger { + comments: CommentGroup { + comments: [], + }, + value: "0", + position: 730, + }, + ), + ), }, ), - as: Keyword { - value: "as", - position: 762, - }, - value: Variable { - position: 765, - name: "$item", - }, + semicolon: 731, }, - block: BlockStatement { + ), + Foreach( + ForeachStatement { comments: CommentGroup { comments: [], }, - left_brace: 771, - statements: [ - Expression( - ExpressionStatement { + foreach: Keyword { + value: "foreach", + position: 741, + }, + iterator: Value { + expression: ObjectOperation( + PropertyFetch { comments: CommentGroup { comments: [], }, - expression: AssignmentOperation( - Addition { - comments: CommentGroup { - comments: [], - }, - left: Variable( - Variable { - position: 785, - name: "$result", - }, - ), - plus_equals: 793, - right: Variable( - Variable { - position: 796, - name: "$item", - }, - ), + object: Variable( + Variable { + position: 749, + name: "$this", }, ), - semicolon: 801, + arrow: 754, + property: Identifier { + position: 756, + value: "items", + }, }, ), - ], - right_brace: 811, - }, - }, - ), - Return( - Implicit { - comments: CommentGroup { - comments: [], + as: Keyword { + value: "as", + position: 762, + }, + value: Variable { + position: 765, + name: "$item", + }, + }, + block: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 771, + statements: [ + Expression( + ExpressionStatement { + comments: CommentGroup { + comments: [], + }, + expression: AssignmentOperation( + Addition { + comments: CommentGroup { + comments: [], + }, + left: Variable( + Variable { + position: 785, + name: "$result", + }, + ), + plus_equals: 793, + right: Variable( + Variable { + position: 796, + name: "$item", + }, + ), + }, + ), + semicolon: 801, + }, + ), + ], + right_brace: 811, + }, }, - expression: Variable( - Variable { - position: 822, - name: "$result", + ), + Return( + Implicit { + comments: CommentGroup { + comments: [], }, - ), - }, - ), - ], - right_brace: 834, - }, + expression: Variable( + Variable { + position: 822, + name: "$result", + }, + ), + }, + ), + ], + right_brace: 834, + }, + ), }, ), ], diff --git a/tests/samples/0083/error.txt b/tests/samples/0083/error.txt index 746c5da..4c01711 100644 --- a/tests/samples/0083/error.txt +++ b/tests/samples/0083/error.txt @@ -12,15 +12,6 @@ error[P0004]: case `Foo::Bar` of backed enum `Foo` must have a value 4 | case Bar; | ^^^^ -error[P0005]: enum `Foo` cannot have constructor - --> 0083/code.ara:6:5 - | -3 | enum Foo: int { - | --- - . -6 | public function __construct() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error[P0003]: case `Bar::Baz` of unit enum `Bar` cannot have a value --> 0083/code.ara:10:10 | @@ -29,23 +20,12 @@ error[P0003]: case `Bar::Baz` of unit enum `Bar` cannot have a value 10 | case Baz = 1; | ^^^^^^^^ -error[P0006]: enum `Bar` cannot have magic method - --> 0083/code.ara:12:5 - | - 9 | enum Bar { - | --- - . -12 | / public function __get(string $name): mixed { -13 | | return get_var($name); -14 | | } - | \-----^ - -error[P0013]: unexpected token `?>`, expected a definition +error[P0011]: unexpected token `?>`, expected a definition --> 0083/code.ara:17:1 | 17 | ?> | ^^ error: failed to parse "0083/code.ara" due to the above issue(s) - = summary: 6 error(s) + = summary: 4 error(s) diff --git a/tests/samples/0085/tree.txt b/tests/samples/0085/tree.txt index e9ee0d8..403a85b 100644 --- a/tests/samples/0085/tree.txt +++ b/tests/samples/0085/tree.txt @@ -5445,8 +5445,8 @@ DefinitionTree { semicolon: 2852, }, ), - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -5470,14 +5470,15 @@ DefinitionTree { position: 2875, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 2886, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -6517,7 +6518,7 @@ DefinitionTree { }, ), }, - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -6676,18 +6677,22 @@ DefinitionTree { }, right_parenthesis: 3708, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 3710, + statements: [], + right_brace: 3711, }, - left_brace: 3710, - statements: [], - right_brace: 3711, - }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -6712,18 +6717,22 @@ DefinitionTree { value: "foo", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 3737, parameters: CommaSeparated { inner: [ - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 3747, + modifiers: [], + }, type_definition: Identifier( TemplatedIdentifier { name: Identifier { @@ -7755,11 +7764,15 @@ DefinitionTree { }, ), }, - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 4447, + modifiers: [], + }, type_definition: Dict( Keyword { value: "dict", @@ -7910,24 +7923,28 @@ DefinitionTree { }, right_parenthesis: 4559, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 4560, - type_definition: Void( - Keyword { - value: "void", - position: 4562, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 4560, + type_definition: Void( + Keyword { + value: "void", + position: 4562, + }, + ), + }, + ), constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 4567, + statements: [], + right_brace: 4568, }, - left_brace: 4567, - statements: [], - right_brace: 4568, - }, + ), }, ), ], diff --git a/tests/samples/0086/error.txt b/tests/samples/0086/error.txt index d103f51..471fa04 100644 --- a/tests/samples/0086/error.txt +++ b/tests/samples/0086/error.txt @@ -1,45 +1,9 @@ -error[P0014]: invalid constant initialization expression - --> 0086/code.ara:9:7 - | -9 | #[Foo(new Bar($bar), new Baz($baz), new Qux(function(): void {}))] - | ^^^^^^^^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0086/code.ara:9:22 - | -9 | #[Foo(new Bar($bar), new Baz($baz), new Qux(function(): void {}))] - | ^^^^^^^^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0086/code.ara:9:37 - | -9 | #[Foo(new Bar($bar), new Baz($baz), new Qux(function(): void {}))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0086/code.ara:11:14 - | -11 | Bar $a = new Bar($bar), - | ^^^^^^^^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0086/code.ara:12:14 - | -12 | Baz $b = new Baz($baz), - | ^^^^^^^^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0086/code.ara:13:14 - | -13 | Qux $c = new Qux(function(): void {}) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[P0013]: unexpected identifier, expected `;` +error[P0011]: unexpected identifier, expected `;` --> 0086/code.ara:25:22 | 25 | private mixed $a FOO = new Foo(); | ^^^ error: failed to parse "0086/code.ara" due to the above issue(s) - = summary: 7 error(s) + = summary: 1 error(s) diff --git a/tests/samples/0087/tree.txt b/tests/samples/0087/tree.txt index 76564c9..984f5de 100644 --- a/tests/samples/0087/tree.txt +++ b/tests/samples/0087/tree.txt @@ -19,8 +19,8 @@ DefinitionTree { body: InterfaceDefinitionBody { left_brace: 15, members: [ - Constructor( - AbstractConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -44,18 +44,23 @@ DefinitionTree { position: 37, value: "__construct", }, - parameters: FunctionLikeParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 48, parameters: CommaSeparated { inner: [ - FunctionLikeParameterDefinition { + MethodParameterDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 49, + modifiers: [], + }, type_definition: String( Keyword { value: "string", @@ -74,11 +79,15 @@ DefinitionTree { }, right_parenthesis: 60, }, - semicolon: 61, + return_type: None, + constraints: None, + body: Abstract( + 61, + ), }, ), Method( - AbstractMethodDefinition { + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -103,7 +112,7 @@ DefinitionTree { value: "doSomething", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -114,17 +123,21 @@ DefinitionTree { }, right_parenthesis: 96, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 97, - type_definition: Void( - Keyword { - value: "void", - position: 99, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 97, + type_definition: Void( + Keyword { + value: "void", + position: 99, + }, + ), + }, + ), constraints: None, - semicolon: 103, + body: Abstract( + 103, + ), }, ), ], @@ -182,8 +195,8 @@ DefinitionTree { body: ClassDefinitionBody { left_brace: 144, members: [ - ConcreteConstructor( - ConcreteConstructorDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -207,14 +220,15 @@ DefinitionTree { position: 166, value: "__construct", }, - parameters: ConstructorParameterListDefinition { + templates: None, + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, left_parenthesis: 177, parameters: CommaSeparated { inner: [ - ConstructorParameterDefinition { + MethodParameterDefinition { attributes: [], comments: CommentGroup { comments: [], @@ -241,18 +255,22 @@ DefinitionTree { }, right_parenthesis: 189, }, - body: BlockStatement { - comments: CommentGroup { - comments: [], + return_type: None, + constraints: None, + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 191, + statements: [], + right_brace: 212, }, - left_brace: 191, - statements: [], - right_brace: 212, - }, + ), }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [ Comment { @@ -283,7 +301,7 @@ DefinitionTree { value: "doSomething", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -294,24 +312,28 @@ DefinitionTree { }, right_parenthesis: 247, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 248, - type_definition: Void( - Keyword { - value: "void", - position: 250, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 248, + type_definition: Void( + Keyword { + value: "void", + position: 250, + }, + ), + }, + ), constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 255, + statements: [], + right_brace: 276, }, - left_brace: 255, - statements: [], - right_brace: 276, - }, + ), }, ), ], diff --git a/tests/samples/0089/tree.txt b/tests/samples/0089/tree.txt index f7a3c62..e150d1e 100644 --- a/tests/samples/0089/tree.txt +++ b/tests/samples/0089/tree.txt @@ -143,8 +143,8 @@ DefinitionTree { semicolon: 85, }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -169,7 +169,7 @@ DefinitionTree { value: "in", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -180,24 +180,28 @@ DefinitionTree { }, right_parenthesis: 111, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 112, - type_definition: Void( - Keyword { - value: "void", - position: 114, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 112, + type_definition: Void( + Keyword { + value: "void", + position: 114, + }, + ), + }, + ), constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 119, + statements: [], + right_brace: 120, }, - left_brace: 119, - statements: [], - right_brace: 120, - }, + ), }, ), ], diff --git a/tests/samples/0093/tree.txt b/tests/samples/0093/tree.txt index 5ee3a45..d9588f0 100644 --- a/tests/samples/0093/tree.txt +++ b/tests/samples/0093/tree.txt @@ -143,8 +143,8 @@ DefinitionTree { semicolon: 100, }, ), - ConcreteMethod( - ConcreteMethodDefinition { + Method( + MethodDefinition { comments: CommentGroup { comments: [], }, @@ -169,7 +169,7 @@ DefinitionTree { value: "using", }, templates: None, - parameters: FunctionLikeParameterListDefinition { + parameters: MethodParameterListDefinition { comments: CommentGroup { comments: [], }, @@ -180,24 +180,28 @@ DefinitionTree { }, right_parenthesis: 129, }, - return_type: FunctionLikeReturnTypeDefinition { - colon: 130, - type_definition: Void( - Keyword { - value: "void", - position: 132, - }, - ), - }, + return_type: Some( + FunctionLikeReturnTypeDefinition { + colon: 130, + type_definition: Void( + Keyword { + value: "void", + position: 132, + }, + ), + }, + ), constraints: None, - body: BlockStatement { - comments: CommentGroup { - comments: [], + body: Concrete( + BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 137, + statements: [], + right_brace: 138, }, - left_brace: 137, - statements: [], - right_brace: 138, - }, + ), }, ), ], diff --git a/tests/samples/0104/error.txt b/tests/samples/0104/error.txt deleted file mode 100644 index 43aaff6..0000000 --- a/tests/samples/0104/error.txt +++ /dev/null @@ -1,27 +0,0 @@ -error[P0014]: invalid constant initialization expression - --> 0104/code.ara:2:7 - | -2 | #[Baz(...BAZ)] - | ^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0104/code.ara:4:16 - | -4 | Bar $bar = new Bar(...BAZ), - | ^^^^^^^^^^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0104/code.ara:7:7 - | -7 | #[Bar(...BAZ)] - | ^^^^^^ - -error[P0014]: invalid constant initialization expression - --> 0104/code.ara:9:16 - | -9 | Bar $bar = new Bar(BAZ...), - | ^^^^^^^^^^^^^^^ - -error: failed to parse "0104/code.ara" due to the above issue(s) - = summary: 4 error(s) - diff --git a/tests/samples/0104/tree.txt b/tests/samples/0104/tree.txt new file mode 100644 index 0000000..d2361f8 --- /dev/null +++ b/tests/samples/0104/tree.txt @@ -0,0 +1,319 @@ +DefinitionTree { + definitions: [ + Function( + FunctionDefinition { + comments: CommentGroup { + comments: [], + }, + attributes: [ + AttributeGroupDefinition { + hash_left_bracket: 1, + members: CommaSeparated { + inner: [ + AttributeDefinition { + name: Identifier { + position: 3, + value: "Baz", + }, + arguments: Some( + ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 6, + arguments: CommaSeparated { + inner: [ + Spread { + comments: CommentGroup { + comments: [], + }, + ellipsis: 7, + value: Identifier( + Identifier { + position: 10, + value: "BAZ", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 13, + }, + ), + }, + ], + commas: [], + }, + right_bracket: 14, + }, + ], + function: Keyword { + value: "function", + position: 16, + }, + name: Identifier { + position: 25, + value: "foo", + }, + templates: None, + parameters: FunctionLikeParameterListDefinition { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 28, + parameters: CommaSeparated { + inner: [ + FunctionLikeParameterDefinition { + comments: CommentGroup { + comments: [], + }, + attributes: [], + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 34, + value: "Bar", + }, + templates: None, + }, + ), + ellipsis: None, + variable: Variable { + position: 38, + name: "$bar", + }, + default: Some( + FunctionLikeParameterDefaultValueDefinition { + equals: 43, + value: ClassOperation( + Initialization { + comments: CommentGroup { + comments: [], + }, + new: Keyword { + value: "new", + position: 45, + }, + class: Identifier( + Identifier { + position: 49, + value: "Bar", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 52, + arguments: CommaSeparated { + inner: [ + Spread { + comments: CommentGroup { + comments: [], + }, + ellipsis: 53, + value: Identifier( + Identifier { + position: 56, + value: "BAZ", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 59, + }, + }, + ), + }, + ), + }, + ], + commas: [ + 60, + ], + }, + right_parenthesis: 62, + }, + return_type: FunctionLikeReturnTypeDefinition { + colon: 63, + type_definition: Void( + Keyword { + value: "void", + position: 65, + }, + ), + }, + body: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 70, + statements: [], + right_brace: 71, + }, + }, + ), + Function( + FunctionDefinition { + comments: CommentGroup { + comments: [], + }, + attributes: [ + AttributeGroupDefinition { + hash_left_bracket: 74, + members: CommaSeparated { + inner: [ + AttributeDefinition { + name: Identifier { + position: 76, + value: "Bar", + }, + arguments: Some( + ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 79, + arguments: CommaSeparated { + inner: [ + Spread { + comments: CommentGroup { + comments: [], + }, + ellipsis: 80, + value: Identifier( + Identifier { + position: 83, + value: "BAZ", + }, + ), + }, + ], + commas: [], + }, + right_parenthesis: 86, + }, + ), + }, + ], + commas: [], + }, + right_bracket: 87, + }, + ], + function: Keyword { + value: "function", + position: 89, + }, + name: Identifier { + position: 98, + value: "qux", + }, + templates: None, + parameters: FunctionLikeParameterListDefinition { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 101, + parameters: CommaSeparated { + inner: [ + FunctionLikeParameterDefinition { + comments: CommentGroup { + comments: [], + }, + attributes: [], + type_definition: Identifier( + TemplatedIdentifier { + name: Identifier { + position: 107, + value: "Bar", + }, + templates: None, + }, + ), + ellipsis: None, + variable: Variable { + position: 111, + name: "$bar", + }, + default: Some( + FunctionLikeParameterDefaultValueDefinition { + equals: 116, + value: ClassOperation( + Initialization { + comments: CommentGroup { + comments: [], + }, + new: Keyword { + value: "new", + position: 118, + }, + class: Identifier( + Identifier { + position: 122, + value: "Bar", + }, + ), + generics: None, + arguments: ArgumentListExpression { + comments: CommentGroup { + comments: [], + }, + left_parenthesis: 125, + arguments: CommaSeparated { + inner: [ + ReverseSpread { + comments: CommentGroup { + comments: [], + }, + value: Identifier( + Identifier { + position: 126, + value: "BAZ", + }, + ), + ellipsis: 129, + }, + ], + commas: [], + }, + right_parenthesis: 132, + }, + }, + ), + }, + ), + }, + ], + commas: [ + 133, + ], + }, + right_parenthesis: 135, + }, + return_type: FunctionLikeReturnTypeDefinition { + colon: 136, + type_definition: Void( + Keyword { + value: "void", + position: 138, + }, + ), + }, + body: BlockStatement { + comments: CommentGroup { + comments: [], + }, + left_brace: 143, + statements: [], + right_brace: 144, + }, + }, + ), + ], + eof: 146, +} \ No newline at end of file diff --git a/tests/test.rs b/tests/test.rs index e7c00b3..476ae2d 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,7 +1,6 @@ use std::env; use std::fs::read_dir; use std::io; -use std::ops::Deref; use std::path::PathBuf; use pretty_assertions::assert_str_eq; @@ -59,7 +58,7 @@ fn test_fixtures() -> io::Result<()> { .with_charset(CharSet::Ascii) .with_colors(ColorChoice::Never); - let error = builder.as_string(report.deref()).unwrap(); + let error = builder.as_string(report.as_ref()).unwrap(); let expected_error = std::fs::read_to_string(&error_filename)?;