Skip to main content

A small lexer and parser utility library

Project description

ParxeL

A small lexer and parser utility library

Install

PyPi

pip install parxel

Usage

# Import lexer and tokens
from parxel.lexer import Lexer
from parxel.token import Token, TK

# Initialize via file name, path object, file object, or stream
lexer = Lexer(filename=filename, filepath=filepath, file=file, stream=stream)
# List of tokens depends on the defined token types defined in TK
tokens : list[Token] = lexer.tokenize()  # ['token', ' ', 'stream', ';', '...']

# Import parser
from parxel.parser import Parser

# Initialize via tokens, file name, path object, file object, or stream
parser = Parser(tokens=tokens, filename=filename, filepath=filepath, file=file, stream=stream)
parser.parse()  # has to be implemented by the concrete format

# Import nodes to represent the AST
from parxel.nodes import Document

# Sample from md.py
from md import MD

markdown = MD('README.md')
root : Document = markdown.parse()

Sample

Calling: python -m md README.md

Will produce the following AST:

MD
 Heading
  Text                bytearray(b' ParxeL')
 Text                bytearray(b'A small lexer and parser utility library')
 Heading
  Text                bytearray(b' Install')
 Reference           bytearray(b'[PyPi](https://pypi.org/project/parxel/0.0.1/)')
 Code                bytearray(b'`pip install parxel`')
 Heading
  Text                bytearray(b' Usage')
 Code                bytearray(b"```python\n# Import lexer and tokens\n [...] root : Document = markdown.parse()\n```")

The tokens of LexicalNode's should be processed. In the above example the raw token stream of the Text b' Usage' will be stripped of whitespaces and stored in the text property. Likewise the Heading node will contain the indentation level (1, 2, 3, ...) of the heading.

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

parxel-0.0.20.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parxel-0.0.20-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file parxel-0.0.20.tar.gz.

File metadata

  • Download URL: parxel-0.0.20.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for parxel-0.0.20.tar.gz
Algorithm Hash digest
SHA256 a89381b74dcb0b68e774bbe7bb59d16d2cd759f0d3d16f929e61ebe6cc61461f
MD5 59a1ba12a14fc978a93d01907f2c07c0
BLAKE2b-256 b25cb052bf455b49f0708fb58f37037635d3b34bf57523f62c5748d0864a22bc

See more details on using hashes here.

File details

Details for the file parxel-0.0.20-py3-none-any.whl.

File metadata

  • Download URL: parxel-0.0.20-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for parxel-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 de9f5e83dbdbd00cffe169df6a0e89f786fdd7a43f9ba69c0e7f25f4e3dea191
MD5 002ad5915f2ad8bcaecf57a0ba6e4b6b
BLAKE2b-256 3afa55b96952906901761ad277a7d7884280806d43bb74a52e73094df1ca7099

See more details on using hashes here.

Supported by

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