Closed tjvr closed 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.)
@nathan You designed most of the Moo API; do you have any suggestions for this? :-)
If token types are gonna be renamed, will this impact error messages? E.g. Expected foo but found bar
in nearley.
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.
Keywords are now explicit.
ignoreCase
option, which is currently missing from Moo (see #46). Note that this can only apply to keyword literals, not RegExps; we can't compile arbitrary regexps to their case-insensitive equivalents! Thevalue
of the emitted token would always be the originally specified literal (i.e. case-normalised).type
of tokens, not their valueswitch
, rather than using a dict)