Skip to main content

Functions and classes for recursive descent parsing.

Project description

inkparse

This is an utility library for making hand written recursive descent parsers.

It is very early in development, so expect breaking changes.

Usage is somewhat verbose, and I'm not happy with it yet. I'll probably rewrite a lot of it before further development.

Usage

(See the inkparse.general module for general purpose parsers you can use as examples. The classes also have some docstrings.)

Defining parsers:

def foo(si: StringIterator, ...) -> Result[int, Literal["token_type"]] | ParseFailure:
    with si() as c:
        si.literal("abc")
        # etc.
        return c.result(10, "token_type")       # success
        return c.fail("Fail reason here.")      # fail
        raise c.error("Error reason here.")     # error

Using parsers:

si = StringIterator("blablabla")

result = foo(si)
if result:
    ... # `result` is a `Result` or `Token` object
else:
    ... # `result` is a `ParseFailure` object

x = result.unwrap().data    # raises an error if x is a `ParseFailure`

String positions are between characters and start from 0. (The same as how python string slices work.)

In the string: "abcdef"

 a b c d e f
^ ^ ^ ^ ^ ^ ^
0 1 2 3 4 5 6

(Line numbers and column numbers shown in error messages start from 1 instead of 0.)

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

inkparse-0.3.2.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inkparse-0.3.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file inkparse-0.3.2.tar.gz.

File metadata

  • Download URL: inkparse-0.3.2.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for inkparse-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d04532fb1b9c4319ba50252c831034decd413ba48930da0d6ed504fea36f9e76
MD5 204517246452c5a60428d3b2bdd7615c
BLAKE2b-256 9e7c85737a69e48367c39ce601d87be593f3f7c9cda9aa1ae1723fb23459d4af

See more details on using hashes here.

File details

Details for the file inkparse-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: inkparse-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for inkparse-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 62cd821c2105431dbdfdd426092aff34d4fe9041d43dd055e5449aec5e2dba25
MD5 c122d6f4878e53fe419c6b2fe7ccae32
BLAKE2b-256 273886c57596b8fdb142014a6c41cc6ce416d4c50849384995618a23362b9ced

See more details on using hashes here.

Supported by

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