diff --git a/src/name_analysis/second_pass.rs b/src/name_analysis/second_pass.rs index 2dd582d..d5787a4 100644 --- a/src/name_analysis/second_pass.rs +++ b/src/name_analysis/second_pass.rs @@ -1,9 +1,10 @@ use crate::ast::node::{ - AssignmentStatement, BacktickString, Call, CompilationUnit, ConcreteUseStatement, - ConcreteUseStatementSuffix, DString, Expression, ExpressionList, ExpressionStatement, Function, - FunctionAliasBody, FunctionBlockBody, FunctionBody, FunctionEqualsBody, GenericParameters, - Identifier, IdentifierExpression, IdentifierOrFqn, LValue, LValueSuffix, Literal, - ModuleLevelDeclaration, ObjectIndex, Parameter, Parameters, PlatformFunction, PrimitiveType, + AnySpaceSuffixOperator, AssignmentStatement, BacktickString, BoundSuffixOperator, Call, + CompilationUnit, ConcreteUseStatement, ConcreteUseStatementSuffix, DString, Expression, + ExpressionList, ExpressionStatement, Function, FunctionAliasBody, FunctionBlockBody, + FunctionBody, FunctionEqualsBody, GenericParameters, Identifier, IdentifierExpression, + IdentifierOrFqn, LValue, LValueSuffix, Literal, ModuleLevelDeclaration, + NoNewlineSuffixOperator, ObjectIndex, Parameter, Parameters, PlatformFunction, PrimitiveType, ReturnType, StarUseStatement, Statement, SuffixExpression, SuffixOperator, TypeUse, TypedArray, UseStatement, UseStatementIdentifier, UseStatementPrefix, VariableDeclaration, }; @@ -676,20 +677,30 @@ fn na_p2_suffix_operator( diagnostics: &mut Vec, ) { match suffix_operator { - SuffixOperator::PlusPlus => { - // no-op + SuffixOperator::BoundSuffixOperator(bound_suffix) => { + match bound_suffix { + BoundSuffixOperator::PlusPlus => { + // no-op + } + BoundSuffixOperator::MinusMinus => { + // no-op + } + } } - SuffixOperator::MinusMinus => { - // no-op - } - SuffixOperator::ObjectProperty(_) => { - // no-op; props checked during type checking - } - SuffixOperator::ObjectIndex(object_index) => { - na_p2_object_index(object_index, symbol_table, diagnostics); - } - SuffixOperator::Call(call) => { - na_p2_call(call, symbol_table, diagnostics); + SuffixOperator::NoNewlineSuffixOperator(no_newline_suffix) => match no_newline_suffix { + NoNewlineSuffixOperator::ObjectIndex(object_index) => { + na_p2_object_index(object_index, symbol_table, diagnostics); + } + NoNewlineSuffixOperator::Call(call) => { + na_p2_call(call, symbol_table, diagnostics); + } + }, + SuffixOperator::AnySpaceSuffixOperator(any_space_suffix) => { + match any_space_suffix { + AnySpaceSuffixOperator::ObjectProperty(_) => { + // no-op; this is checked during type checking + } + } } } } diff --git a/src/parser/ast.yaml b/src/parser/ast.yaml index af47676..26891c6 100644 --- a/src/parser/ast.yaml +++ b/src/parser/ast.yaml @@ -1160,13 +1160,23 @@ SuffixExpression: SuffixOperator: tree_enum: rules: - - PlusPlus: - child: false - - MinusMinus: - child: false - - ObjectProperty + - BoundSuffixOperator + - NoNewlineSuffixOperator + - AnySpaceSuffixOperator +BoundSuffixOperator: + leaf_enum: + rules: + - PlusPlus + - MinusMinus +NoNewlineSuffixOperator: + tree_enum: + rules: - ObjectIndex - Call +AnySpaceSuffixOperator: + tree_enum: + rules: + - ObjectProperty ObjectProperty: struct: children: diff --git a/src/parser/deimos.pest b/src/parser/deimos.pest index 753be0e..31abcf5 100644 --- a/src/parser/deimos.pest +++ b/src/parser/deimos.pest @@ -260,7 +260,7 @@ FunctionTypeUse = { // Generic Arguments -GenericArguments = { +GenericArguments = !{ "<" ~ TypeUseList ~ ">" @@ -735,7 +735,8 @@ MultiplicativeOperator = { | Modulo } -PrefixExpression = { +// Compound-atomic because all prefix operators are bound immediately (i.e., no spaces). +PrefixExpression = ${ PrefixOperator* ~ SuffixExpression } @@ -746,19 +747,31 @@ PrefixOperator = { | Negative } -SuffixExpression = { +SuffixExpression = ${ PrimaryExpression ~ SuffixOperator* } -SuffixOperator = { +SuffixOperator = ${ + BoundSuffixOperator + | ( " " | "\t" )* ~ NoNewlineSuffixOperator ~ ( " " | "\t" )* + | WHITESPACE* ~ AnySpaceSuffixOperator ~ WHITESPACE* +} + +BoundSuffixOperator = { PlusPlus | MinusMinus - | ObjectProperty - | ObjectIndex +} + +NoNewlineSuffixOperator = { + ObjectIndex | Call } +AnySpaceSuffixOperator = { + ObjectProperty +} + ObjectProperty = { "." ~ Identifier @@ -770,10 +783,10 @@ ObjectIndex = { ~ "]" } -PrimaryExpression = { +PrimaryExpression = !{ Literal - | IdentifierExpression | FullyQualifiedName + | IdentifierExpression | Closure | ListExpression | ParenthesizedExpression @@ -810,28 +823,29 @@ ParenthesesCall = { ~ Closure? } -NonParenthesesCall = { +NonParenthesesCall = ${ TurboFish? + ~ ( " " | "\t" )* ~ ( Closure | ExpressionList - | ExpressionList ~ Closure + | ExpressionList ~ ( " " | "\t" )* ~ Closure ) } -TurboFish = { +TurboFish = ${ "::" ~ GenericArguments } -ExpressionList = { +ExpressionList = !{ Expression ~ ( "," ~ Expression )* } // Closure -Closure = { +Closure = !{ "{" ~ ( ClosureParameters? ~ "->" )? ~ Statement*