Skip to content

tantaman/lexed.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lexed

A trivial lexer for Javascript.

var rules = {
	'<\/[^>]+>': Lexed.IGNORE, // ignore close tags
	'<[^>]+>': Lexed.IGNORE, // ignore open tags
	'[^<>]+': function(text) { return text; } // return matched text content
};
var l = new Lexed('<div class="intro"><b>Hello!</b></div>', rules);

var token;
while ((token = l.lex()) != Lexed.EOF) {
	console.log(token); // writes Hello!
}

It also supports state transitions.

Take a look at the tests and examples folders for more usage examples.

State transitions example: http://tantaman.github.io/lexed.js/examples/stateTransitions.html

Scoping existing CSS: http://tantaman.github.io/lexed.js/examples/scopeCss.html

About

A simple lexer for javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages