dabeaz / sly

Sly Lex Yacc
Other
817 stars 108 forks source link

How to extend a Lexer #37

Closed hadware closed 5 years ago

hadware commented 5 years ago

This may be related in lots of ways to #12 : is there a simple way to extend a Lexer?

I have this AbstractLexer class that has many rules that should be shared by child classes, and it would be very inelegant to have to copy these rules in all the "child" lexers.

hadware commented 5 years ago

Nevermind, it works fine as it should, for those who'd like to do the same:

class BaseLexer(Lexer):
    tokens = ()
    A = r"pattern_A"
    B = r"pattern_B"

class MyLexer(BaseLexer):
    tokens = (A, B)
    # other rules

This should work fine.

Closing the issue