Skip to main content

Simple library to scan or tokenize text.

Project description

nr.parsing.core

A simple library for scanning and lexing text which makes it easy to implement new DSLs (domain specific languages).

Example (Scanning)

from nr.parsing.core import Scanner

sc = Scanner('abc + 42.0')
assert sc.getmatch(r'\w+') == 'abc'
sc.match('\s*')
assert sc.char == '+'; sc.next()
sc.match('\s*')
assert sc.getmatch(r'\d+(?:\.\d*)') == '42.0'
assert sc.char == ''  # eof

Example (Lexing)

from nr.parsing.core import Scanner, Lexer, Regex, Charset

rules = [
  Charset('ws', ' ', skip=True),
  Charset('op', '+'),
  Regex('num', r'\d+(?:\.\d*)', group=0),
  Regex('id', r'\w+', group=0),
]

for tok in Lexer(Scanner('abc + 42.0'), rules):
  print(tok.type, tok.value)

Copyright © 2020 Niklas Rosenstein

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

nr.parsing.core-1.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

nr.parsing.core-1.1.0-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nr.parsing.core-1.1.0.tar.gz.

File metadata

  • Download URL: nr.parsing.core-1.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for nr.parsing.core-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d2744fc861c7c4c16357aa60ba88288e99504c2fa3fb83a4e1fec43c4a137d91
MD5 1cd8c5dd897bde2294fd3d3a745b5107
BLAKE2b-256 432d961f4ab1f9929887ac44479f63d820d357a977e0000bc6d207aeb32a2db5

See more details on using hashes here.

File details

Details for the file nr.parsing.core-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: nr.parsing.core-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for nr.parsing.core-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d0432e1f74b6edf163f1247e7d54e3aebe34d4101f7b11790011f320fe92ec8
MD5 6f9056101a1061c698f4257b7f2cf146
BLAKE2b-256 a003681655fdee0808ad729ffad761eb7803829155f179d74be4a7f1037646d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page