A small lexer and parser utility library
Project description
ParxeL
A small lexer and parser utility library
Install
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parxel-0.0.22.tar.gz.
File metadata
- Download URL: parxel-0.0.22.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96e3814367b2ad16a93e1a968d4174778678b515b0d9002fdb73d5465c2561a6
|
|
| MD5 |
91895345901c1ec20eb2861b79260126
|
|
| BLAKE2b-256 |
b68a13246ca4b5ecb15d4f138907cafa8063d6ce9620ba8001a9928e32795482
|
File details
Details for the file parxel-0.0.22-py3-none-any.whl.
File metadata
- Download URL: parxel-0.0.22-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1184343de9f7cc602e804ac850a6a279a454e3e7ac6dc315713564db6877dc10
|
|
| MD5 |
d68d159a9ed996b09e07dc5badbcf6b9
|
|
| BLAKE2b-256 |
55ab7c5ee198b0eed3517e2fc98fff63e91a4f6153aa04165fc0f2dba4e12b55
|