Skip to main content

Ore

A simple WIP pythonic parser combinator library inspired by Haskell's attoparsec.

It supports two styles: declarative and imperative.

For example, declarative style looks like the following:

from ore_combinators.combinators import alphabet, transform
from ore_combinators.combinators import sequence, take_while_possible

join = lambda l: ''.join(l)

name = transform(
    sequence(
        alphabet,
        transform(
            take_while_possible(alphabet),
            join
        )
    ),
    join
)

The very same combinator could be written as function:

from typing import Tuple

from ore_combinators.combinators import alphabet
from ore_combinators.combinators import take_while_possible
from ore_combinators import combinator_function, ParserState, Result


@combinator_function()
def name(state: ParserState) -> Tuple[str, ParserState]:
    first_symbol, state = alphabet(state)
    other_symbols, state = take_while_possible(alphabet)(state)

    return Result.make_value(
        first_symbol + ''.join(other_symbols),
        state
    )

To run a parser on a given text, use run or run_safe:

from typing import Tuple

from ore_combinators.combinators import alphabet
from ore_combinators.combinators import take_while_possible
from ore_combinators import ParserState, Result
from ore_combinators import run_safe, combinator_function


@combinator_function()
def name(state: ParserState) -> Tuple[str, ParserState]:
    first_symbol, state = alphabet(state)
    other_symbols, state = take_while_possible(alphabet)(state)

    return Result.make_value(
        first_symbol + ''.join(other_symbols),
        state
    )

name_result = run_safe(name, "Ore     ")

assert name_result.value == "Ore"

The difference between run and run_safe is that run_safe returns result without raising exceptions. Exceptions saved in the result instead. run just throws exceptions without saving them into result.

Installation

To install this library, just type pip install ore-combinators in the console.

Release files for ore-combinators 0.0.5

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

Source distribution (sdist)

Source distribution for ore-combinators 0.0.5
File Size Uploaded
ore-combinators-0.0.5.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ore-combinators 0.0.5
File Interpreter ABI Platform
ore_combinators-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / ore-combinators-0.0.5.tar.gz

Download URL ore-combinators-0.0.5.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
650fbbcfb979531b9de55f84eea8234ecdf868ad7ed8cddd83dcd5a575eca357
BLAKE2b-256 checksum
How to use checksums
efec0a9cdd91ab93f40ea2bd4eb4a46d9a60c112b60999df418e96bd4dbb5907
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.0

Release files / ore_combinators-0.0.5-py3-none-any.whl

Download URL ore_combinators-0.0.5-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f3cc7c9ba83ca89c1e705a384e3397b45071e422634d480a4f386ae36ce969f
BLAKE2b-256 checksum
How to use checksums
74b928d84ce3be3556c1365cffec04029aa4caa303c979b86c0ab31877cd03c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

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