Repository navigation
parser: parse member access as a postfix operator - #79
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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], andHijackMemberExpressionrebuilt it recursively to put the member access at its bottom. The recursion also needed a separate depth check before the rebuild.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.
Only an identifier is now accepted after a dot.
single.10and"abc".(Length)fail with a syntax error at the position of the member instead of "Identifier expected" when the expression is built. The checks inExpressionBuilderstay 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 followint. The member name is labeled withAsrather than guarded withFail, soSubparserstill stops before a dot that starts no member access, as ina..b.