/gparser

A naive parser combinator library

Primary LanguagePythonMIT LicenseMIT

Gparser

PyPI Build Status codecov

Parsec-like thinking model + Python DSL = an intuitive and easy-to-use parser library ^^

Get Started

  • Install
$ pip install gparser
  • Run
$ python3                                
Python 3.6.7 (default, Oct 25 2018, 09:16:13) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gparser as gp
...

Hello World

A toy parser:

import gparser as gp             # (1) import gparser

dot = gp.char('.')               # (2) define a dot parser 
result, restTxt = dot.run('./')  # (3) run the parser

print(result)                    # (4) print the result
# Success(value=Result('.'))

print(result.get())
# .

print(restTxt)
# (1,2)
# ./
#  ^

Use run_strict to parse the entire input:

...
result, restTxt = dot.run_strict('.foo')

print(result)
# ParseError(msg='Excepted: <EOF>')

print(restTxt)
# (1,2)
# .foo
#  ^

More

For more detailed documentation, see Gparser Document