nr.parsing.core
The nr.parsing.core package provides a simple API to scan and tokenize text for the purpose of
structured langauge processing.
Example
from nr.parsing.core import RuleSet, Tokenizer, rules
ruleset = RuleSet()
ruleset.rule('number', rules.regex_extract(r'\-?(0|[1-9]\d*)', 0))
ruleset.rule('operator', rules.regex_extract(r'[\-\+]', 0))
ruleset.rule('whitespace', rules.regex(r'\s+'), skip=True)
def calculate(expr: str) -> int:
tokenizer = Tokenizer(ruleset, expr)
result = 0
sign: t.Optional[int] = 1
while tokenizer:
if tokenizer.current.type != 'number':
raise ValueError(f'unexpected token {tokenizer.current}')
assert sign is not None
result += sign * int(tokenizer.current.value)
tokenizer.next()
if tokenizer.current.type == 'operator':
sign = -1 if tokenizer.current.value == '-' else 1
tokenizer.next()
else:
sign = None
if sign is not None:
raise ValueError(f'unexpected trailing operator')
return result
assert calculate('3 + 5 - 1') == 7
Copyright © 2020 Niklas Rosenstein
Metadata
Release files for nr.parsing.core 2.0.4
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 |
|---|---|---|---|---|
| nr.parsing.core-2.0.4.tar.gz | 11.7 kB | Without provenance | Details for nr.parsing.core-2.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nr.parsing.core-2.0.4-py3-none-any.whl | Python 3 | none | any | Details for nr.parsing.core-2.0.4-py3-none-any.whl |
Total release size: 24.6 kB
Release files / nr.parsing.core-2.0.4.tar.gz
| Download URL | nr.parsing.core-2.0.4.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1115c0dc52c96ab77403ae7e20fea2e4db14a71c84dc4735ac3de04af5b43de5
|
|
BLAKE2b-256 checksum How to use checksums |
0a1ac9200b9cf76ecf02e86f4f3cd81054e209000485843a93bcd789ee9d7ef9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1
|
Release files / nr.parsing.core-2.0.4-py3-none-any.whl
| Download URL | nr.parsing.core-2.0.4-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c2eb6f045dbce3e716882e41f882bf4a224324719687abb5f1c34d79437e116
|
|
BLAKE2b-256 checksum How to use checksums |
cf8611d7a7aacd7f8805022235128c39fa492812a254ff08ad06b01990e08fe3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1
|
Security for nr.parsing.core 2.0.4
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.