Parse value EITHER as <float> OR as <integer with percentage sign> - grammar or validator? #1800
-
I am trying to implement a rule to parse a value either as a float value (e.g., '.75) or as an integer percentage (e.g.: '80%'). I am able to disambiguate a percentage value from a float value:
However I don't know how I can impose an integer percentage value OR a float value (without percentage). Should the grammar disambiguate this, or should I leave this to the validation checks registered in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @shutterfreak, usually those restrictions shouldn't be enforced by the parser, as they usually lead to obscure lexer/parser error that aren't helpful for most users to identify the error. Like you said, this should be something ideally done via the validator. Aside from that, here is your fixed grammar that correctly makes use of the predicate. |
Beta Was this translation helpful? Give feedback.
Hey @shutterfreak,
usually those restrictions shouldn't be enforced by the parser, as they usually lead to obscure lexer/parser error that aren't helpful for most users to identify the error. Like you said, this should be something ideally done via the validator. Aside from that, here is your fixed grammar that correctly makes use of the predicate.