Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1.43 KB

README.rst

File metadata and controls

49 lines (37 loc) · 1.43 KB

Python version of SimplePEG

A very simple implementation of PEG parser generator.

Join the chat at https://gitter.im/SimplePEG/Python https://travis-ci.org/SimplePEG/Python.svg?branch=master https://coveralls.io/repos/github/SimplePEG/Python/badge.svg?branch=master

To use, simply do

from simplepeg import SPEG
parser = SPEG()
parser.parse_grammar('GRAMMAR test b -> "a";')
ast = parser.parse_text('a')
print ast.to_json()

or

from simplepeg import SPEG
parser = SPEG()
ast = parser.parse('GRAMMAR test b -> "a";', 'a')
print ast.to_json()

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