You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The linter will produce a warning to use one of the *String parsers, despite this already being the case:
expect(linter(MyGrammar().build()), isEmpty);
Output:
Expected: empty
Actual: [
LinterIssue:LinterIssue(type: LinterType.warning, title: Character repeater, parser: Instance of 'FlattenParser<List<String>>', description: A flattened repeater (Instance of 'PossessiveRepeatingParser<String>'[0..*]) that delegates to a character parser (Instance of 'SingleCharacterParser'[any of " \t" expected]) can be much more efficiently implemented using `starString`, `plusString`, `timesString`, or `repeatString` that directly returns the underlying String instead of an intermediate List.)
]
I think that the cause is that the class of myChars is obscured by the wrapping ReferenceParser so that the type checks in repeatString fail and we end up on this line:
Good observation and analysis. This is indeed a tricky problem that might cause subtle differences in a few other places too, such as when flattening of | / .or(Parser) and & / .seq(Parser) operators.
Another workaround could be to call optimize on the built parser:
Regarding references: This is really up to you. The idea was that if you always use ref you can forget about cycles, but I have written grammars where ref0 was only used between productions and tokens were stored in (constant) variables.
Consider this grammar:
The linter will produce a warning to use one of the *String parsers, despite this already being the case:
Output:
I think that the cause is that the class of
myChars
is obscured by the wrappingReferenceParser
so that the type checks inrepeatString
fail and we end up on this line:dart-petitparser/lib/src/parser/repeater/character.dart
Line 74 in d9b1133
This seems like a difficult problem: the class of the referent is not known until build time, but
repeatString
needs to be called earlier.Is the only solution here "don't use a reference"?
(Bigger question: Should references only be used to break cycles? I was under the impression that it was good practice to use them by default.)
The text was updated successfully, but these errors were encountered: