node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


Regex Parser


Regex parser based on descriptions in

npm install regexp
var regexp = require('regexp')
var res = regexp('[a-z]+')
assert.deepEqual(res, { type: 'match',
  offset: 0,
  text: '[a-z]+',
   [ { type: 'quantified',
       offset: 0,
       text: '[a-z]+',
        { type: 'charset',
          offset: 0,
          text: '[a-z]',
          invert: false,
           [ { type: 'range',
               offset: 1,
               text: 'a-z',
               start: 'a',
               end: 'z' } ] },
        { type: 'quantifier',
          offset: 5,
          text: '+',
          min: 1,
          max: Infinity,
          greedy: true } } ] })

To run tests:

$ npm install
$ npm test

This will also automatically compile index.js.

The key source files are src/grammer.pegjs which is compiled using pegjs and src/index.js which is a CommonJS module with a special additional pseudo import statement.