Metadata-Version: 2.1
Name: pgpc
Version: 0.0.2
Summary: A Python Generator based Parser Combinator library
Home-page: https://github.com/neshkeev/pgpc
Author: neshkeev
Author-email: neshkeev@yandex.ru
License: Apache 2.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Provides-Extra: dev
License-File: LICENSE
License-File: NOTICE

# PGPC

## Overview

**PGPC** is a parser combinator library. Its name is an acronym, and it stands for **P**ython **G**enerator based **P**arser **C**ombinator library.

The library was heavily influenced by the [Parsec](https://github.com/haskell/parsec) monadic parser combinator library,
so the transition from `Parsec` (and other parser combinators) to `PGPC` should be more or less easy.

The original idea of the library is emulating the `do`-notation with the `yield` Python keyword.

## Quick start

The `@topology` decorator over a function allows the `yield` keyword work with parsers in a `do`-notation-like fashion:

```python
from pgpc.scanner import TextScanner
from pgpc.parser import Parser, topology, char, position, content


@topology
def hello(value: str):
    start = yield position()

    for c in value:
        yield char(c)

    end = yield position()
    source = yield content()

    return f"Parsed {source[start.offset:end.offset]} which started at {start} and ended at {end}"


if __name__ == '__main__':
    text = "HELLO"
    
    par: Parser[str] = hello(text)
    
    result = par(TextScanner(text))
    
    print(result)
```
