dabeaz / sly

Sly Lex Yacc
Other
816 stars 107 forks source link

Sly documentation for regular expression flags doesn't match Lexer implementation #94

Closed ricilake closed 2 years ago

ricilake commented 2 years ago

At https://github.com/dabeaz/sly/blob/master/docs/sly.rst?plain=1#L141 the documentation says:

Regular expression patterns are compiled using the re.VERBOSE flag which can be used to help readability.

That matches the Ply documentation and practice. But the Sly Lexer class sets reflags to 0 at construction, so that the patterns are actually compiled with no flags set.

I don't know what the intention was, and really it doesn't much matter to me whether or not the re.VERBOSE flag is the default, but I do think that the documentation should match the behaviour. Otherwise, it's confusing, particularly when the behaviour is a change from Ply.

Noticed while responding to a question on SO; it's not relevant to the question, which is about Ply, but it did confuse another responder: https://stackoverflow.com/a/71369713/1566221.

jpsnyder commented 2 years ago

I think it should default to no flags like it is. So perhaps just update the documentation?

dabeaz commented 2 years ago

This is probably a documentation hold-over from the days of PLY. Fixed the docs. If different reflags are desired, they can be specified on the Lexer class itself.

class MyLexer(Lexer):
    reflags = re.VERBOSE
    ...