neogeny / TatSu

竜 TatSu generates Python parsers from grammars in a variation of EBNF
https://tatsu.readthedocs.io/
Other
403 stars 48 forks source link

@@keyword + @name directives fail if keyword is "True" or "False" #335

Closed KrzysztofT closed 5 months ago

KrzysztofT commented 5 months ago

After a few years I revisited my old project which uses TatSu. I upgraded the library to version 5.11.3 (I'm using Python 3.12). I had to fix a few things - but no matter what I did, I couldn't make my booleans working properly. Diving with debugger into TatSu code showed that there might be some issue with keyword handling.

If the keyword declarations contains "True" or "False" spelled exactly like this - with first letter being capital:

@@keyword :: True False

Then the ModelContext.keywords set will contain these two words - not as strings, but as regular Python booleans instead. Consequently, _check_name will not match with a string "False" nor "True".

Changing these keywords to lowercase is a quick workaround.

apalala commented 5 months ago

This is a result of recent changes to make literals map to Python basic types.

It looks like something easy to fix in the grammar, by making keyword only match strings and words.

It's an obnoxious bug that merits a new release.