Skip to content

parser: parse member access as a postfix operator - #79

Merged
rameel merged 2 commits into
mainfrom
parser/unify-postfix-operators
Nov 24, 2026
Merged

rameel merged 2 commits into
mainfrom
parser/unify-postfix-operators

Conversation

@rameel

@rameel rameel commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Member access was parsed one level above calls and indexers, so the part after a dot arrived as a finished chain such as b(1)[2], and HijackMemberExpression rebuilt it recursively to put the member access at its bottom. The recursion also needed a separate depth check before the rebuild.

member_expression
  = call_or_indexer_expression ("." S !keyword call_or_indexer_expression)*
  ;

call_or_indexer_expression
  = primary_expression (call_expression / indexer_expression)*
  ;

Parse member access, calls, and indexers as postfix operators of one level, each applied to the expression on its left, as in the C# grammar.

postfix_expression
  = primary_expression (call / indexer / member_access)*
  ;

member_access
  = "." S !keyword identifier S
  ;

Only an identifier is now accepted after a dot. single.10 and "abc".(Length) fail with a syntax error at the position of the member instead of "Identifier expected" when the expression is built. The checks in ExpressionBuilder stay for trees built directly.

A keyword after a dot, as in int.true, now also reports "Expected identifier" past the dot instead of listing the operators that can follow int. The member name is labeled with As rather than guarded with Fail, so Subparser still stops before a dot that starts no member access, as in a..b.

Member access was parsed one level above calls and indexers:

    member_expression
      = call_or_indexer_expression
        ("." S !keyword call_or_indexer_expression)*
      ;

    call_or_indexer_expression
      = primary_expression (call_expression / indexer_expression)*
      ;

The part after a dot arrived as a finished chain such as b(1)[2], and
HijackMemberExpression rebuilt it recursively to put the member access
at its bottom.

Parse member access, calls, and indexers as postfix operators of one
level, each applied to the expression on its left, as in the C#
grammar:

    postfix_expression
      = primary_expression (call / indexer / member_access)*
      ;

    member_access
      = "." S !keyword identifier S
      ;

The chain is built in a loop, so the depth check before the rebuild is
no longer needed; the final check still limits the depth.

Only an identifier is accepted after a dot now. single.10 and
"abc".(Length) fail with "Expected identifier" at the position of the
member instead of "Identifier expected" when the expression is built.
The checks in ExpressionBuilder stay for trees built directly.
A keyword after a dot, as in int.true, was rejected by !keyword, which
reports no expected token, so the error pointed at the dot and listed
the operators that can follow int:

    (1:4) Expected '(', '[', ':>', [%*/], [+-], '<<', '>>', ...

Label the member name "identifier" with As, so the error points past
the dot and reads "(1:5) Expected identifier", as for a.10 or a dot at
the end. Unlike Fail, a labeled parser fails without stopping the
parse, so Subparser still stops before a dot that starts no member
access, as in a..b.
@rameel
rameel merged commit 7d6a5df into main Nov 24, 2026
1 check passed
@rameel
rameel deleted the parser/unify-postfix-operators branch November 24, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant