Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keywords design #53

Closed
tjvr opened this issue Jun 25, 2017 · 5 comments
Closed

Keywords design #53

tjvr opened this issue Jun 25, 2017 · 5 comments

Comments

@tjvr
Copy link
Collaborator

tjvr commented Jun 25, 2017

  • Consider making keywords explicit, rather than implicit. Currently it's not obvious that the keyword transform is happening!
  • Consider adding an ignoreCase option, which is currently missing from Moo (see Case insensitive keywords? #46). Note that this can only apply to keyword literals, not RegExps; we can't compile arbitrary regexps to their case-insensitive equivalents! The value of the emitted token would always be the originally specified literal (i.e. case-normalised).
  • Allow renaming token types based on their keyword—this would allow writing parsers which switch only on the type of tokens, not their value
  • Optimise recognition of keywords (generate a switch, rather than using a dict)
@tjvr
Copy link
Collaborator Author

tjvr commented Jun 25, 2017

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
Copy link
Collaborator Author

tjvr commented Jun 25, 2017

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

@deltaidea
Copy link
Contributor

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

@nathan
Copy link
Collaborator

nathan commented Jun 27, 2017

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.

This was referenced Jul 19, 2017
@tjvr
Copy link
Collaborator Author

tjvr commented Jul 27, 2017

Keywords are now explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants