libparsing is a parsing element grammar (PEG) library written in C with Python bindings. It offers good performance while allowing for a lot of flexibility. It is mainly intended to be used to create programming languages and software engineering tools.
As opposed to more traditional parsing techniques, the grammar is not compiled but constructed using an API that allows for the dynamic update of the grammar.
The parser does not do any tokeninzation, instead, an input stream is consumed and parsing elements are dynamically asked to match the next element of it. Once parsing elements match, the resulting matched input is processed and an action is triggered.
libparsing supports the following features:
backtracking, ie. going back in the input stream if a match is not found
cherry-picking, ie. skipping unrecognized input
contextual rules, ie. a rule that will match or not depending on external variables
Parsing elements are usually slower than compiled or FSM-based parsers as they trade performance for flexibility. It’s probably not a great idea to use libparsing if the parsing has to happen as fast as possible (ie. a protocol implementation), but it is a great use for programming languages, as it opens up the door to dynamic syntax plug-ins and multiple language embedding.
If you’re interested in PEG, you can start reading Brian Ford’s original article. Projects such as PEG/LEG by Ian Piumarta http://piumarta.com/software/peg/ ,OMeta by Alessandro Warth http://www.tinlizzie.org/ometa/ or Haskell’s Parsec library https://www.haskell.org/haskellwiki/Parsec are of particular interest in the field.
Here is a short example of what creating a simple grammar looks like in Python:
g = Grammar()
s = g.symbols
g.token("WS", "\s+")
g.token("NUMBER", "\d+(\.\d+)?")
g.token("VARIABLE", "\w+")
g.token("OPERATOR", "[\/\+\-\*]")
g.group("Value", s.NUMBER, s.VARIABLE)
g.rule("Suffix", s.OPERATOR._as("operator"), s.Value._as("value"))
g.rule("Expression", s.Value, s.Suffix.zeroOrMore())
g.axiom(s.Expression)
g.skip(s.WS)
match = g.parseString("10 + 20 / 5")
and the equivalent code in C
Grammar* g = Grammar_new()
SYMBOL(WS, TOKEN("\\s+"))
SYMBOL(NUMBER, TOKEN("\\d+(\\.\\d+)?"))
SYMBOL(VARIABLE, TOKEN("\\w+"))
SYMBOL(OPERATOR, GROUP("[\\/\\+\\-\\*]"))
SYMBOL(Value, GOUP(_S(NUMBER), _S(VARIABLE)))
SYMBOL(Suffix, RULE(_AS(_S(OPERATOR), "operator"), _AS(_S(Value), "value")))
SYMBOL(Expression, RULE(_S(Value), _MO(Suffix))
g->axiom = s_Expression;
g->skip(s_WS);
Grammar_prepare(g);
Match* match = Grammar_parseString(g, "10 + 20 / 5")
Metadata
Release files for libparsing 0.9.2
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 | |
|---|---|---|---|---|
| libparsing-0.9.2.tar.gz | 33.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| libparsing-0.9.2.linux-x86_64.tar.gz | Details |
Total release size: 313.3 kB
Release files / libparsing-0.9.2.tar.gz
| Download URL | libparsing-0.9.2.tar.gz |
|---|---|
| Size | 33.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b841ac1aced0b395bdab1f193792b156a538073093cd84f96fa0f7c95fa02c89
|
|
BLAKE2b-256 checksum How to use checksums |
06be1459ca3bfb8b12b8eaf35924744fe5d7ed6deaec2cd315e1078975331bee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / libparsing-0.9.2.linux-x86_64.tar.gz
| Download URL | libparsing-0.9.2.linux-x86_64.tar.gz |
|---|---|
| Size | 280.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02ba3aa42da78677962e51e7c1dae04f0e842ee04c88b78ac5948fcaca1bbb3e
|
|
BLAKE2b-256 checksum How to use checksums |
bf4872e4ffadd58801ebd617656a63755c6bf31c6cde1b3dc831cbee85580628
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for libparsing 0.9.2
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.