Plare
A lexer/parser framework for Python 3.12+. Plare lets you define a tokeniser and an LALR(1) parser using plain Python classes and dictionaries — no code generation, no external grammar files.
Features
- Stateful lexer — regex-driven, named states let you switch tokenisation modes mid-stream (e.g., to skip comments)
- LALR(1) parser — efficient shift/reduce parser with automatic conflict detection
- Persistent parse-table cache — automatically skip repeated LALR table construction
- Operator precedence — resolve shift/reduce conflicts by setting
precedenceandassociativeclass variables on token classes - No build step — install and import
Installation
pip install plare
Quick Example
from plare.lexer import Lexer
from plare.parser import Parser
from plare.token import Token
class NUM(Token):
def __init__(self, value: str, *, lineno: int, offset: int) -> None:
super().__init__(value, lineno=lineno, offset=offset)
self.value = int(value)
class PLUS(Token):
pass
class Exp:
value: int
class Const(Exp):
def __init__(self, number: NUM) -> None:
self.value = number.value
class Add(Exp):
def __init__(self, left: Exp, right: Exp) -> None:
self.value = left.value + right.value
lexer: Lexer[None] = Lexer({"start": [(r"\d+", NUM), (r"\+", PLUS), (r" +", "start")]})
parser: Parser[Exp] = Parser(
{"exp": [(["exp", PLUS, "exp"], Add, [0, 2]), ([NUM], Const, [0])]}
)
result = parser.parse("exp", lexer.lex("start", "1 + 2"))
assert isinstance(result, Exp)
print(result.value) # 3
Examples
examples/calc/— integer arithmetic with operator precedenceexamples/sum_of_list/— list parsing with recursive grammar
Metadata
Release files for plare 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| plare-2.0.0.tar.gz | 21.6 kB | With provenance | Details for plare-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| plare-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for plare-2.0.0-py3-none-any.whl |
Total release size: 44.8 kB
Release files / plare-2.0.0.tar.gz
| Download URL | plare-2.0.0.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd49edce87235e4f06ee276b6c0c4cf8c27327a6f3927637e7900e130af4abe4
|
|
BLAKE2b-256 checksum How to use checksums |
8710635e21f16993ffbb1b5fcfd98a643564716d6f3df74b5ec0a238a6c6abb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / plare-2.0.0-py3-none-any.whl
| Download URL | plare-2.0.0-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbd4d93a63a614b171460e90a9358511d067ac636dfd76c5a41bdbfb955f4ff9
|
|
BLAKE2b-256 checksum How to use checksums |
4131032357cf9102ae8a6930ff8f7804babc51d0573ab789f615b03f4f0b1370
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for plare 2.0.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for plare-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA 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.