Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A lexing library for javascript.
JavaScript
branch: master

This branch is 2 commits behind ekiru:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README
jslex.js
jslex_test.js

README

jslex is a lexing library for JavaScript/ECMAscript.

It serves a similar purpose to utilities in other languages such as lex or flex. However, instead of requiring the user to learn another language for the purpose of formatting the grammar and to run an extra compilation pass, jslex is implemented purely as a JavaScript/ECMAscript library.

To use jslex, load the "jslex.js" file, create a list of TokenDef objects for each token types, and call the jsLex function.

The TokenDef constructor takes two arguments: a regular expression and a function taking the string matched by the regular expression and producing the appropriate token.

For example, this could be used to recognize a natural number:

new TokenDef(/[0-9]+/, function (string) {
  return ["int", parseInt(string)];
})
Something went wrong with that request. Please try again.