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

Explicit keywords #57

Closed tjvr closed 7 years ago

tjvr commented 7 years ago

Some thoughts on #53.

See the updated readme.

tjvr commented 7 years ago

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',
    },
  },
})
nathan commented 7 years ago

Or with individual types:

itt(['class', 'def', 'if'])
.map(k => ['kw-' + k, k])
.toObject()

(Iterator adaptors solve every* problem!)

tjvr commented 7 years ago

Iterator adaptors solve every* problem!

Nice! :-)

tjvr commented 7 years ago
      keywords: {
        'kw-class': 'class',

I'm also not convinced having the object "backwards" like this, for consistency with the outer moo.compile, is correct.

tjvr commented 7 years ago

Let's do this.