A very simple implementation of PEG parser generator.
To use, simply do
fromsimplepegimportSPEGparser=SPEG()
parser.parse_grammar('GRAMMAR test b -> "a";')
ast=parser.parse_text('a')
printast.to_json()or
fromsimplepegimportSPEGparser=SPEG()
ast=parser.parse('GRAMMAR test b -> "a";', 'a')
printast.to_json()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 -> "#" [^ ]*;