Define keywords using moo.keywords()
mainTo ensure the 'longest match' principle (e.g., preventing className from being lexed as class + Name), use the moo.keywords() helper. This helper checks matches against a list of keywords and assigns them a specific type if they match, otherwise falling back to the base type of the rule.
Individual Keyword Types: You can also map specific keywords to unique types by passing an object to moo.keywords() instead of an array.
// Using an array for shared type 'keyword'
moo.compile({
IDEN: {match: /[a-zA-Z]+/, type: moo.keywords(['while', 'if', 'else'])}
})
// Using an object for individual types
moo.compile({
name: {match: /[a-zA-Z]+/, type: moo.keywords({
'kw-class': 'class',
'kw-def': 'def',
})}
})