Skip to content

JavaScript version ( Browser and Node.js ) of SimplePEG

License

Notifications You must be signed in to change notification settings

vov32/JavaScript

 
 

Repository files navigation

JavaScript

Join the chat at https://gitter.im/SimplePEG/JavaScript Greenkeeper badge Build Status Coverage 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

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.3%
  • TypeScript 1.7%