6.0.0 • Published 4 years ago

moo-indentation-lexer v6.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

moo-indentation-lexer

Usage

Quick

const moo = require('moo')
const IndentationLexer = require('moo-indentation-lexer')

// Create a lexer from rules
const mooLexer = moo.compile({ ... })
// Create an indentation-aware lexer using the lexer
const lexer = new IndentationLexer({ lexer: mooLexer })

// Specify the data
lexer.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()

Custom

// Create a lexer from rules
const mooLexer = moo.compile({
    WS: /[ \t]+/,
    comment: /\/\/.*?$/,
    ...,
    NL: { match: /\n/, lineBreaks: true }
})
// Create an indentation-aware lexer using the lexer
const lexer = new IndentationLexer({
    lexer: mooLexer,
    indentationType: 'WS',
    newlineType: 'NL',
    commentType: 'comment',
    indentName: 'indent',
    dedentName: 'dedent',
    enclosingPunctuations: { '[': ']', '<': '>' },   // defaults {}, () and []
    separators: [',']
})
6.0.0

4 years ago

5.0.0

4 years ago

3.3.2

4 years ago

4.0.0

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.4

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago