Skip to main content

A Python Generator based Parser Combinator library

Project description

PGPC

Overview

PGPC is a parser combinator library. Its name is an acronym, and it 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 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:

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgpc-0.0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

pgpc-0.0.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file pgpc-0.0.2.tar.gz.

File metadata

  • Download URL: pgpc-0.0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pgpc-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f3c4f3741bcc3f0a46d6cfe1a768fa69b1cb8281d0e213beb3cd5b139fd7d727
MD5 8232ee9f25444d7f840f685f3ae7b837
BLAKE2b-256 3124b3c7dc43b8ef93b831c8ba5ad2586ecff4e5fd46759850a5d1ade3aca83d

See more details on using hashes here.

File details

Details for the file pgpc-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pgpc-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pgpc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2fa013c44e45b2da536a5098d63a3e2a1b41beb53ee7dcb8588858b8c23ae0b6
MD5 45459393de9e41bf3b94e0c3499579f7
BLAKE2b-256 ebee2d1aa3ed24640581b0fce0f07302118b257528bd65f9adb36fa5b67cc234

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page