You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Indentation and de-indentation lexer for Moo and Nearley.
Usage - quick
constmoo=require('moo')constIndentationLexer=require('moo-indentation-lexer')// Create a lexer from rulesconstmooLexer=moo.compile({ ... })// Create an indentation-aware lexer using the lexerconstlexer=newIndentationLexer({lexer: mooLexer})// Specify the datalexer.reset('...')// In addition to the normal Moo tokens,// extra indent/dedent tokens will be emitted for matching indentation/unindentation// Indentation levels are also closed off by matching enclosures of {}, () and []// When a separator and newline appears just before a de-indentation, the dedent// will be emitted first, followed by the separator and newline.lexer.next()
Usage - custom
// Create a lexer from rulesconstmooLexer=moo.compile({WS: /[ \t]+/,comment: /\/\/.*?$/,
...,NL: {match: /\n/,lineBreaks: true}})// Create an indentation-aware lexer using the lexerconstlexer=newIndentationLexer({lexer: mooLexer,indentationType: 'WS',newlineType: 'NL',commentType: 'comment',indentName: 'indent',dedentName: 'dedent',enclosingPunctuations: {'[': ']','<': '>'},// defaults {}, () and []separators: [',']// defaults to , : ;})