PyMeta3
PyMeta3 is a Python 3 compatible fork of PyMeta, an implementation of OMeta, an object-oriented pattern-matching language. It provides a compact syntax based on Parsing Expression Grammars (PEGs) for common lexing, parsing, and tree-transforming activities in a way that's easy to reason about for Python programmers. The current version is 0.5.1, with the last update released in February 2015, suggesting a low release cadence.
Warnings
- breaking PyMeta3 is a fork specifically for Python 3. Attempting to use the original PyMeta (designed for Python 2) with Python 3, or PyMeta3 with Python 2, will lead to compatibility issues and breaking changes. Ensure your environment is Python 3.x.
- gotcha There are multiple Python packages with similar names, which can lead to confusion and incorrect installations. These include `pymeta` (for Rust metaprogramming), `PythonMeta` (for meta-analysis), and `pymeta` (for document metadata extraction). Ensure you are installing `PyMeta3` for the OMeta-based pattern matching library.
- deprecated The library has not seen a release since February 2015. This indicates a low level of active development and maintenance, which might mean unaddressed bugs, lack of support for newer Python features, or security vulnerabilities.
Install
-
pip install PyMeta3
Imports
- OMeta
from pymeta.grammar import OMeta
Quickstart
from pymeta.grammar import OMeta
exampleGrammar = """
ones ::= '1' '1' => 1
twos ::= '2' '2' => 2
stuff ::= (<ones> | <twos>)+
"""
Example = OMeta.makeGrammar(exampleGrammar, {})
g = Example("11221111")
result, error = g.apply("stuff")
print(f"Result: {result}")
print(f"Error: {error}")