Skip to content

Repository files navigation

JavaScript

Join the chat at https://gitter.im/SimplePEG/JavaScriptGreenkeeper badgeBuild StatusCoverage Status

JavaScript version ( Browser and Node.js ) of SimplePEG. A very simple implementation of PEG parser generator.

const simplepeg = require('simplepeg');
const parser = new simplepeg.SPEG();
parser.parse_grammar('GRAMMAR test a->"A";');
const ast = parser.parse_text('A');
console.log(JSON.stringify(ast, null, 4));

Grammar example

url.peg

GRAMMAR url
url -> scheme "://" host pathname search hash?;
scheme -> "http" "s"?;
host -> hostname port?;
hostname -> segment ("." segment)*;
segment -> [a-z0-9-]+;
port -> ":" [0-9]+;
pathname -> "/" [^ ?]*;
search -> ("?" [^ #]*)?;
hash -> "#" [^ ]*;

About

JavaScript version ( Browser and Node.js ) of SimplePEG

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages