Skip to main content

PGPC

Overview

PGPC is a parser combinator library. Its name is an acronym, which stands for Python Generator based Parser Combinator library.

The library was heavily influenced by the Parsec monadic parser combinator library, so the transition from Parsec (and other parser combinators) to PGPC should be relatively 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:

  1. install the package: pip install pgpc
  2. save the following code into main.py:
from pgpc.scanner import TextScanner
from pgpc.parser import Parser, topology, char, position, content


@topology
def parse_hello_world():
    start = yield position()

    for c in "Hello":
        yield char(c)

    yield char(",")
    yield char(" ")

    for c in "World":
        yield char(c)

    yield char("!")

    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, World!"

    hw_parser: Parser[str] = parse_hello_world()

    result = hw_parser(TextScanner(text))

    print(result)
  1. run main.py: python main.py

Metadata

Release files for pgpc 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgpc 0.0.4
File Size Uploaded
pgpc-0.0.4.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pgpc 0.0.4
File Interpreter ABI Platform
pgpc-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / pgpc-0.0.4.tar.gz

Download URL pgpc-0.0.4.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0aee1541d06204ca4df60ae939b1603a68c3cd8cde472bc05c00378547234580
BLAKE2b-256 checksum
How to use checksums
e382218dc670b4cd48ef28bcf5b3b9efe418e8072deef884a2ab7705ebd82fba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pgpc-0.0.4-py3-none-any.whl

Download URL pgpc-0.0.4-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a64e35057d5dd8339f98ee0a023737735a1dd5266bf4d9a70a13325825e1630
BLAKE2b-256 checksum
How to use checksums
bc4e55fe0ece125dfe0b28ee8c928b30da5a08ec886aa108bf4856afb14142cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page