bluesocks
![NPM Downloads](https://img.shields.io/npm/dm/bluesocks.svg)
Bluesocks is a lightweight lexer in Javascript
let { lexer, rule } = require('bluesocks');
let rules = {
default: [
rule("PERIOD1", /\./, "othercontext"),
rule("NOTPERIOD1", /[^\.]+/)
],
othercontext: [
rule("PERIOD2", /\./, "<"),
rule("NOTPERIOD2", /[^\.]+/)
]
}
lex = lexer("This is a test. This is a test. This is a test.", "test", rules);
let token = lex.next();
while(!token.done) {
switch (token.value.type) {
case "PERIOD1":
console.log("We switched to default context");
break;
case "NOTPERIOD1":
console.log(`We found a non-period token: "${token.value.data}"`);
break;
case "PERIOD2":
console.log("We switched to othercontext");
break;
case "NOTPERIOD2":
console.log(`We found a non-period token: "${token.value.data}"`);
break;
}
token = lex.next();
}