-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make an identifier NOT a keyword (dgrammar wrongly rejects keyword as prefix) #147
Comments
Answering my own question: Identifier <~ !(Keyword WordBreak) [a-zA-Z_] [a-zA-Z0-9_]* seems to work. perhaps dgrammar could be updated with this? |
Or I admit not using Pegged for quite some time. Does dgrammar generate OK? At On Mon, Jan 26, 2015 at 7:23 AM, Timothee Cour [email protected]
|
haven't tried rencently, but it'd be useful to fix grammars for correctness |
On Wed, Jan 28, 2015 at 10:57 PM, Timothee Cour [email protected]
None at all. The creator of PEGs needed two ways to create terminals, to be |
I think there is: You can use semantic actions to filter out identifiers that are identical to keywords as I describe in #190 (comment). The actions can of course be defined in their own module that is included through the header instead of being defined in the header string. |
in pegged/examples/dgrammar.d there is:
Identifier <~ !Keyword [a-zA-Z_] [a-zA-Z0-9_]*
Keyword < "abstract" / "alias" ...
This rules out valid identifiers that use a keyword as a prefix (eg: int abstract_val=0), so this is incorrect.
Is there a better way?
Could the following be made to work? (where '\b' represents word break)
Identifier <~ !(Keyword '\b') [a-zA-Z_] [a-zA-Z0-9_]*
Keyword < "abstract" / "alias" ...
Could we generalize this to specify custom 'word breaks' using arbitrary regular expressions?
The text was updated successfully, but these errors were encountered: