Feat: Allow member access on literal expressions such as [1,2,3].length#36
Open
quaaantumdev wants to merge 1 commit intoappsup-dart:masterfrom
Open
Feat: Allow member access on literal expressions such as [1,2,3].length#36quaaantumdev wants to merge 1 commit intoappsup-dart:masterfrom
[1,2,3].length#36quaaantumdev wants to merge 1 commit intoappsup-dart:masterfrom
Conversation
This was referenced Jun 21, 2025
Author
|
@rbellens would be great if you want to take a look at this |
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.
This pull request enhances the expression parser to support member access directly on literal expressions. This change makes the expression syntax more intuitive and aligns it with common patterns found in other programming languages.
The problem
Previously, the parser grammar could not handle expressions like
'hello'.lengthor[1, 2, 3].length. The parser treated literals and member-accessible expressions (like variables or grouped expressions) as mutually exclusive starting points. This forced the unnatural workaround of wrapping literals in parentheses, such as([1, 2, 3]).length, just to make the expression parsable.The Solution
The parser grammar in
lib/src/parser.darthas been refactored to resolve this limitation:These changes make the grammar more flexible while correctly handling the new syntax.
Testing
A new test group, 'literal members', has been added to
test/expressions_test.dart. It includes tests that specifically verify the new capability by accessing the.lengthproperty on list and string literals, confirming that the changes work as expected. This test would fail without the changes made. All other tests are unaffected and work just fine.Fixes #37.