-
Notifications
You must be signed in to change notification settings - Fork 65
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
Explicit keywords #57
Conversation
I think making the keyword behaviour explicit is probably a good idea. I'm not sure about this API, though. Perhaps it should be a nested object? moo.compile({
identifier: {match: /[a-zA-Z]+/, keywords: {keyword: ['moo', 'cow']}},
}) Or with individual types: moo.compile({
identifier: {
match: /[a-zA-Z]+/,
keywords: {
'kw-class': 'class',
'kw-def': 'def',
'kw-if': 'if',
},
},
}) |
itt(['class', 'def', 'if'])
.map(k => ['kw-' + k, k])
.toObject() (Iterator adaptors solve every* problem!) |
moo.js
Outdated
(byLength[keyword.length] = byLength[keyword.length] || []).push(keyword) | ||
}) | ||
|
||
// fast string lookup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you profiled this as being faster than a plain old switch
on the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not personally, but I've read that switching on the length first is faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! :-) |
I'm also not convinced having the object "backwards" like this, for consistency with the outer |
Let's do this. |
Some thoughts on #53.
See the updated readme.