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));
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 -> "#" [^ ]*;