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.0.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

nr.parsing.core-1.0.1-py2.py3-none-any.whl (10.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: nr.parsing.core-1.0.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for nr.parsing.core-1.0.1.tar.gz
Algorithm Hash digest
SHA256 68d68e95a818894fa49249e69edb7026f0315f8304577bbe7b2c19f56e4525a2
MD5 f4c19c7648d33772f3a78033bc2aff58
BLAKE2b-256 2576f407ba93b86cfe062e55eadd6b43eae5919173a85263298d26cb770e39f1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nr.parsing.core-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6ac8aefa13490ee322672502b22f2fc8d9b621f53ab7f9cd943dd26b953bd42c
MD5 28978d2eb1c1b2a58d6a999aae46fdcf
BLAKE2b-256 690efb8543c8ae50aacd8bc03567b4c029ca869e8c2abbe0c617ef34aed8b04e

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