Neologism
A dynamically modifiable context-free grammar library for Python.
Neologism loads bison-style yacc files directly, exposes the grammar as a
DCFG object you can mutate (add or remove rules, promote nonterminals to
terminals, substitute symbols, and so on), and enumerates the sentences the
resulting grammar produces.
When to reach for it
The need that motivated neologism: you have a real bison grammar, one that
is partly machine-generated, or whose canonical form is a .y file, and
you want to programmatically transform it and then enumerate every sentence
the transformed grammar accepts.
Existing libraries cover one or two of those three pieces:
- ply / lark / parsimonious / ANTLR parse input using a grammar; the grammar itself is not a mutable object you can manipulate after loading.
- NLTK models CFGs as data, including sentence generation, but does not ingest bison.
- bison itself generates a parser, not a manipulable model.
Neologism is the cross-section.
Installing
pip install neologism
Bison must be available on PATH. It is invoked at runtime to convert
.y files to the XML form neologism consumes.
Example
from neologism import DCFG, Rule
dcfg = DCFG.from_yacc_file("my-grammar.y")
# Substitute the opaque terminal LL_NUMBER with a pretty placeholder
dcfg.make_symbol_terminal("LL_NUMBER")
dcfg.add_rule(Rule("LL_NUMBER", ("<number>",)))
# Stream every sentence the transformed grammar produces
for sentence in dcfg.iter_sentences():
print(" ".join(sentence))
The mutation-after-load workflow is the distinguishing feature. axosyslog-cfg-helper is a substantial real-world consumer: it walks the AxoSyslog bison grammar, applies module-specific transformations, and enumerates every driver invocation to build a configuration-option database.
Documentation
Full API reference: https://neologism.readthedocs.io/
License
GPL-3.0-or-later
Metadata
Release files for neologism 1.1.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 |
|---|---|---|---|---|
| neologism-1.1.0.tar.gz | 21.8 kB | Without provenance | Details for neologism-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neologism-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for neologism-1.1.0-py3-none-any.whl |
Total release size: 57.2 kB
Release files / neologism-1.1.0.tar.gz
| Download URL | neologism-1.1.0.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd8c633636d1568bce6ce88025153087bf59c0550b2ed8a21f190e2f927ea850
|
|
BLAKE2b-256 checksum How to use checksums |
14979c1b563a308f99cdcfd68656056b13b5fde3c1932072a2ec1e8b5777ecea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1013-azure
|
Release files / neologism-1.1.0-py3-none-any.whl
| Download URL | neologism-1.1.0-py3-none-any.whl |
|---|---|
| Size | 35.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6807774fab69d01abd09bd40e11ae014bfac38e81ad87fb0fbe71883eb3dab3
|
|
BLAKE2b-256 checksum How to use checksums |
931936fc953bba3207ad6ed1b50066a92e5d1011fc573b9efb6be98edc1a8b7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1013-azure
|
Security for neologism 1.1.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.
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.