The pluggable JavaScript lexer. Limon = Lemon. :lemon:
This is not finished yet, but go to examples directory and look deeply there. :tada:
We have few initial examples:
.tokenize
method using plugin.a > (b + 2)
)And finally, after all, benchmarking.
npm i limon --save
For more use-cases see the tests
const limon = require('limon')
const prevNext = require('limon-prev-next')
limon
.use(prevNext())
.use(function (app) {
return function (ch, i, input) {
// console.log('prev is:', this.prev())
// console.log('next is:', this.next())
if (/\s/.test(ch)) {
this.tokens.push(['whitespace', ch, i])
return
}
if (/\W/.test(ch)) {
this.tokens.push(['symbol', ch, i])
return
}
if (/\d/.test(ch)) {
this.tokens.push(['digit', ch, i])
return
}
this.tokens.push(['letter', ch, i])
}
})
var tokens = limon.tokenize('a > (b + 2)')
console.log(tokens)
// =>
// [ [ 'letter', 'a', 0 ],
// [ 'whitespace', ' ', 1 ],
// [ 'symbol', '>', 2 ],
// [ 'whitespace', ' ', 3 ],
// [ 'symbol', '(', 4 ],
// [ 'letter', 'b', 5 ],
// [ 'whitespace', ' ', 6 ],
// [ 'symbol', '+', 7 ],
// [ 'whitespace', ' ', 8 ],
// [ 'digit', '2', 9 ],
// [ 'symbol', ')', 10 ] ]
Initialize
Limon
withinput
andoptions
. Both are completely optional. You can pass plugins and tokens tooptions
.
Params
input
{String}: String value to tokenize, or if object it is assumed options
. options
{Object}: Optional options, use it to pass plugins or tokens. Example
var Limon = require('limon').Limon
var lexer = new Limon('foo bar')
// or pass only options
var limon = new Limon({ foo: 'bar' })
var tokens = limon.tokenize('baz qux')
prev
and next
methods. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.