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.15.tar.gz (8.6 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.15-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: parxel-0.0.15.tar.gz
  • Upload date:
  • Size: 8.6 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.15.tar.gz
Algorithm Hash digest
SHA256 b8f841b7fde9af2c0d29cd60528f9198d04dfe6927c2a44c0a35e81d916b9858
MD5 31987349c6ea1880b423cbe50c78b2b7
BLAKE2b-256 3fd95197d9ea9c954c91c19ccbdabc19ac6841ff5059e3eb58844e3fac9aea59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parxel-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.15-py3-none-any.whl
Algorithm Hash digest
SHA256 92beb5de4be45d973ce2ce58b01793d7520b2acd67232e576605bb9c5058746d
MD5 b48d710eb7e6b8b88c0e98cd73baee56
BLAKE2b-256 792bc7d8e28e382f1fc57528f1ac42805fbc6e4ca4d8ab4e78897729b2c9f0e4

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