Skip to content
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

Python keywords as rule name #48

Open
38b394ce01 opened this issue Mar 29, 2022 · 3 comments
Open

Python keywords as rule name #48

38b394ce01 opened this issue Mar 29, 2022 · 3 comments

Comments

@38b394ce01
Copy link

38b394ce01 commented Mar 29, 2022

It is not possible to use grammars that contain any Python keywords as rule name.

Consider the following ANTLR grammar:

grammar keyword;
start: False;
False: 'anything';`

This wil procude the keywordGenerator.py with the following function:

    @depthcontrol
    def False(self, parent=None):
        current = UnlexerRule(name='False', parent=parent)
        self._enter_rule(current)
        UnlexerRule(src='anything', parent=current)
        self._exit_rule(current)
        return current
    False.min_depth = 0

Because False is a reserved keyword in Python this is not valid Python code.
The bug occurs with every keyword.

@renatahodovan
Copy link
Owner

@38b394ce01 This is in sync with ANTLR, you cannot generate lexers/parsers from grammars containing keywords of the target language:

error(134): keyword.g4:3:0: symbol False conflicts with generated code in target language or runtime

The only aspect we could improve here is to give a similar error message in our grammar processing step.

@KvanTTT
Copy link

KvanTTT commented Apr 24, 2022

It's probably not actual since ANTLR >= 4.10 since it renames conflicting symbols in corresponding runtimes.

@renatahodovan
Copy link
Owner

@KvanTTT Thanks for pointing it out to me, I was not aware of this new feature. In this case, I'll add it to my TODO list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants