simplepeg
v1.2.0
Published
JavaScript version ( Browser and Node.js ) of SimplePEG
Downloads
8
Readme
JavaScript
JavaScript version ( Browser and Node.js ) of SimplePEG
import {SPEG} from 'simplepeg';
const parser = new SPEG();
parser.parse_grammar('GRAMMAR test a->"A";);
const ast = parser.parse_text('A');
console.log(JSON.strinfigy(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 -> "#" [^ ]*;