ore-combinators

 Name ore-combinators JSON Version 0.0.5 JSON download home_page Summary Parser combinator library for Python upload_time 2021-06-10 13:18:21 maintainer docs_url None author Igor Kraglik requires_python ==3.*,>=3.6.0 license MIT keywords VCS bugtrack_url requirements No requirements were recorded. Travis-CI No Travis. coveralls test coverage No coveralls.
```            # 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:
```python3
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:
```python3
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`:

```python3
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.

```

Raw data

```            {
"_id": null,
"home_page": "",
"name": "ore-combinators",
"maintainer": "",
"docs_url": null,
"requires_python": "==3.*,>=3.6.0",
"maintainer_email": "",
"keywords": "parser combinator ore",
"author": "Igor Kraglik",
"author_email": "kraglik.i.d@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ef/ec/0a9cdd91ab93f40ea2bd4eb4a46d9a60c112b60999df418e96bd4dbb5907/ore-combinators-0.0.5.tar.gz",
"platform": "",
"description": "# Ore\n\nA simple WIP pythonic parser combinator library inspired by Haskell's attoparsec.\n\nIt supports two styles: declarative and imperative.\n\nFor example, declarative style looks like the following:\n```python3\nfrom ore_combinators.combinators import alphabet, transform\nfrom ore_combinators.combinators import sequence, take_while_possible\n\njoin = lambda l: ''.join(l)\n\nname = transform(\n    sequence(\n        alphabet,\n        transform(\n            take_while_possible(alphabet),\n            join\n        )\n    ),\n    join\n)\n```\n\nThe very same combinator could be written as function:\n```python3\nfrom typing import Tuple\n\nfrom ore_combinators.combinators import alphabet\nfrom ore_combinators.combinators import take_while_possible\nfrom ore_combinators import combinator_function, ParserState, Result\n\n\n@combinator_function()\ndef name(state: ParserState) -> Tuple[str, ParserState]:\n    first_symbol, state = alphabet(state)\n    other_symbols, state = take_while_possible(alphabet)(state)\n\n    return Result.make_value(\n        first_symbol + ''.join(other_symbols),\n        state\n    )\n```\n\nTo run a parser on a given text, use `run` or `run_safe`:\n\n```python3\nfrom typing import Tuple\n\nfrom ore_combinators.combinators import alphabet\nfrom ore_combinators.combinators import take_while_possible\nfrom ore_combinators import ParserState, Result\nfrom ore_combinators import run_safe, combinator_function\n\n\n@combinator_function()\ndef name(state: ParserState) -> Tuple[str, ParserState]:\n    first_symbol, state = alphabet(state)\n    other_symbols, state = take_while_possible(alphabet)(state)\n\n    return Result.make_value(\n        first_symbol + ''.join(other_symbols),\n        state\n    )\n\nname_result = run_safe(name, \"Ore     \")\n\nassert name_result.value == \"Ore\"\n```\n\nThe difference between `run` and `run_safe` is that `run_safe` returns result without raising exceptions.\nExceptions saved in the result instead.\n`run` just throws exceptions without saving them into result.\n\n# Installation\n\nTo install this library, just type `pip install ore-combinators` in the console.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Parser combinator library for Python",
"version": "0.0.5",
"split_keywords": [
"parser",
"combinator",
"ore"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "d174585d39d8b562ce309acf3d134bc7",
"sha256": "5f3cc7c9ba83ca89c1e705a384e3397b45071e422634d480a4f386ae36ce969f"
},
"downloads": -1,
"filename": "ore_combinators-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d174585d39d8b562ce309acf3d134bc7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "==3.*,>=3.6.0",
"size": 23931,
"upload_time": "2021-06-10T13:18:20",
"upload_time_iso_8601": "2021-06-10T13:18:20.146607Z",
"url": "https://files.pythonhosted.org/packages/74/b9/28d84ce3be3556c1365cffec04029aa4caa303c979b86c0ab31877cd03c3/ore_combinators-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "209435ca4d0ef76c0e2b708de635545c",
"sha256": "650fbbcfb979531b9de55f84eea8234ecdf868ad7ed8cddd83dcd5a575eca357"
},
"downloads": -1,
"filename": "ore-combinators-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "209435ca4d0ef76c0e2b708de635545c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "==3.*,>=3.6.0",
"size": 7485,
"upload_time": "2021-06-10T13:18:21",
"upload_time_iso_8601": "2021-06-10T13:18:21.840026Z",
"url": "https://files.pythonhosted.org/packages/ef/ec/0a9cdd91ab93f40ea2bd4eb4a46d9a60c112b60999df418e96bd4dbb5907/ore-combinators-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-06-10 13:18:21",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "ore-combinators"
}
```
Elapsed time: 0.29036s