no-context / moo

Optimised tokenizer/lexer generator! 🐄 Uses /y for performance. Moo.
BSD 3-Clause "New" or "Revised" License
823 stars 65 forks source link

Accept non-Array objects as compile() ruleset #9

Closed nathan closed 7 years ago

nathan commented 7 years ago

Property names are token names, and property values are regular expressions, e.g.:

{ word: /[a-z]+/, space: / +/ } <==> [ ['word', /[a-z]+/], ['space', / +/] ]

Closes tjvr/moo#7.

tjvr commented 7 years ago

Love it. Thanks Nathan!

EDIT: Actually, for ordinary objects [[OwnPropertyKeys]] returns non-integer own property String keys in creation order. So when you call Reflect.ownKeys or Object.getOwnPropertyNames (but not Object.keys) you get the correct order. for-in loops are terrible anyway.

I'd have thought it follows that we should be using Object.getOwnPropertyNames instead of Object.keys here. But I trust you to do the right thing. :)

nathan commented 7 years ago

I'd have thought it follows that we should be using Object.getOwnPropertyNames instead of Object.keys here. But I trust you to do the right thing. :)

Um, no, you're right, it should definitely be Object.getOwnPropertyNames. Sorry about that. #10.