dabeaz / ply

Python Lex-Yacc
http://www.dabeaz.com/ply/index.html
2.79k stars 465 forks source link

Configuring ID #265

Closed masics closed 1 year ago

masics commented 2 years ago

I have a following simple format: BLOCK ID { SUBBLOCK ID { SUBSUBBLOCK ID { SOME STATEMENTS; }; }; };

I configured ply to work with this format. But the issue is that ID could be any string including "BLOCK", "SUBBLOCK", etc. In the lexer I define ID as:

    @TOKEN(r'[a-zA-Z_][a-zA-Z_0-9]*')
    def t_ID(self, t):
        t.type = self.keyword_map.get(t.value, "ID")
        return t

But it means that BLOCK word will not be allowed as a block name.

How I can overcome this issue?