no-context / moo

Optimised tokenizer/lexer generator! 🐄 Uses /y for performance. Moo.
BSD 3-Clause "New" or "Revised" License
821 stars 65 forks source link

Keywords design #53

Closed tjvr closed 7 years ago

tjvr commented 7 years ago
tjvr commented 7 years ago

Specifying keywords should probably look like this, to match the { tokenType: matchPattern } convention moo uses for specifying lexers.

{
    'kw-while': 'while',
    'kw-else': 'else',
}

(With an accompanying public helper function for generating such dicts, from a naming function and a list of keyword literals.)

tjvr commented 7 years ago

@nathan You designed most of the Moo API; do you have any suggestions for this? :-)

deltaidea commented 7 years ago

If token types are gonna be renamed, will this impact error messages? E.g. Expected foo but found bar in nearley.

nathan commented 7 years ago

we can't compile arbitrary regexps to their case-insensitive equivalents!

Well…

Maybe you shouldn't

Consider making keywords explicit, rather than implicit. Currently it's not obvious that the keyword transform is happening!

Perhaps just make it an error for keywords (i.e. literal string matches) to appear after a non-keyword rule. Then it's obvious that they take precedence.

tjvr commented 7 years ago

Keywords are now explicit.