Skip to main content

Lexit

Lexit is an open source lexer generator written in Python3.6 using new features like NamedTuple, type hinting and __init_subclass__ hook.

JSON lexer example

from lexit import Lexer


class JsonLexer(Lexer):
    NUMBER = r'-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?'
    STRING = r'"(\\\"|\\\\|[^"\n])*?"i?'
    L_BRACE = r'{'
    R_BRACE = r'}'
    L_BRACKET = r'\['
    R_BRACKET = r'\]'
    TRUE = r'true'
    FALSE = r'false'
    NULL = r'null'
    COMMA = r','
    COLON = r':'

    ignore = r'\s+'


tokens = list(JsonLexer.lex('{"hello": "world"}'))

Requirements

  • The only requirement is Python3.6+
  • For testing the pytest library is used

Installation

pip install lexit

Error handling

try:
    tokens = list(JsonLexer.lex('${"hello": "world"}'))
except LexerError as e:
    print(e.pretty())
    exit(1)

# Will produce the following output:

No match for character '$' in line 1 column 1
${"hello": "world"}
^

Design decisions

  • Should be easy to use
  • Longest match priority (++ always wins over + despite of the order in which the tokens are defined in the lexer class)
  • Self-describing errors for humans (it's should be obvious what happened and when)

Metadata

Release files for lexit 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lexit 0.0.1
File Size Uploaded Provenance Actions
lexit-0.0.1.tar.gz 3.3 kB Without provenance Details for lexit-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lexit 0.0.1
File Interpreter ABI Platform Actions
lexit-0.0.1-py3-none-any.whl Python 3 none any Details for lexit-0.0.1-py3-none-any.whl

Total release size: 6.7 kB

Release files / lexit-0.0.1.tar.gz

Download URL lexit-0.0.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
400119d224e272fda8af809100de074f7d81bd292d5a2af3212d8f64b85ee4e7
BLAKE2b-256 checksum
How to use checksums
772deeed45dd47b608d0c1f33b3a2b6f48376df96d100e7836d51b08884bf60f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / lexit-0.0.1-py3-none-any.whl

Download URL lexit-0.0.1-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abf3eff2630d7a440cb222b4db4fd07e04aefb9ef3d7313cd44d7a1e912124df
BLAKE2b-256 checksum
How to use checksums
eaf047d7c907918bac5e2882a2815130a62a447814476e093df412390c487ca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for lexit 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page