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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ore-combinators-0.0.5.tar.gz | 7.5 kB | Without provenance | Details for ore-combinators-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ore_combinators-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for ore_combinators-0.0.5-py3-none-any.whl |
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
|
Security for ore-combinators 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.