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.1.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.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: inkparse-0.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e528cc73b32b52776d1bacf09f154d83ab8cbfca56a12b99d177f6883493b7a9
MD5 40acba3b356ed725d4faf02332b35c29
BLAKE2b-256 0dc2656f3daf83f4694dfbd153a7d1d9c8b327344ca9ec329b5f3ef7c8099083

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for inkparse-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb99c6a7097d9c88d6c95aa6aec8e4f86377a0fae063b45027540e1bf5e26e64
MD5 dcb1775afec7cd748b37b35d14524385
BLAKE2b-256 dfbd46a8228ab0420a55481341ba339636d667ca86f3964babc86198c891f8ce

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