0.7.5 • Published 7 years ago

bluesocks v0.7.5

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

bluesocks

Bluesocks is a lightweight lexer in Javascript

let { lexer, rule } = require('bluesocks');

let rules = {
	default: [
		rule("PERIOD1", /\./, "othercontext"), //push othercontext
		rule("NOTPERIOD1", /[^\.]+/)
	],
	othercontext: [
		rule("PERIOD2", /\./, "<"), //pop othercontext
		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();
}
0.7.5

7 years ago

0.7.3

7 years ago

0.7.1

7 years ago

0.5.0

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago