https://github.com/zhongzc/gparser
A naive parser combinator library
https://github.com/zhongzc/gparser
functional-programming parser parser-combinators parser-library python python3
Last synced: 8 months ago
JSON representation
A naive parser combinator library
- Host: GitHub
- URL: https://github.com/zhongzc/gparser
- Owner: zhongzc
- License: mit
- Created: 2018-09-12T10:23:08.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-15T18:42:01.000Z (over 3 years ago)
- Last Synced: 2025-02-28T09:10:01.452Z (9 months ago)
- Topics: functional-programming, parser, parser-combinators, parser-library, python, python3
- Language: Python
- Homepage: https://gaufoo.com/gparser/
- Size: 39.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gparser
[](https://pypi.python.org/pypi)
[](https://travis-ci.com/zhongzc/gparser)
[](https://codecov.io/gh/zhongzc/gparser)
Parsec-like thinking model + Python DSL = an intuitive and easy-to-use parser library ^^
## Get Started
- Install
```sh
$ pip install gparser
```
- Run
```sh
$ 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:
```python
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:
```python
...
result, restTxt = dot.run_strict('.foo')
print(result)
# ParseError(msg='Excepted: ')
print(restTxt)
# (1,2)
# .foo
# ^
```
## More
For more detailed documentation, see [Gparser Document](https://gaufoo.com/gparser/)