-
Notifications
You must be signed in to change notification settings - Fork 110
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
Undeclared identifiers in tokens assignment? #40
Comments
Many magical behaviors can be achieved through the questionable use of metaclasses. |
So if the mechanism itself requires a level of understanding of the Python data model beyond what I would be able to muster, is it reasonable (if imprecise) to say that where the derived lexer is concerned, the required For example, the |
The primary purpose of tokens is to precisely specify the set of terminals needed for constructing parsers. If you were to add an attribute not listed in tokens, there would be no way for the parser to know about it. As for the underlying magic, it's not connected to tokens so much as the entire enclosing environment defined when you inherit from the Lexer base class. |
@dabeaz may you explain how this works a bit more please? I read the |
The mechanism is metaclasses. |
Please pardon my ignorance, but I'm having a very difficult time understanding what happens when I assign the
tokens
attribute of aLexer
instance.I see in the documentation
and some testing confirms that any identifier seems to be legal so long as its name is capitalized, but I don't understand what happens in Python when these identifiers are provided; nor do I recognize anything in
lex.py
that enables this behavior.What is so special about
tokens
that allows it to accept previously undeclared names?The text was updated successfully, but these errors were encountered: