========
PyMeta3
========
--------------------------------------------
A Pattern-Matching Language Based on Python
--------------------------------------------
This is a fork of PyMeta 0.5.0 that supports Python 2 and 3.
Installation
============
pip install PyMeta3
Summary
=======
PyMeta is an implementation of OMeta, an object-oriented pattern-matching
language developed by Alessandro Warth
(http://www.cs.ucla.edu/~awarth/ometa/). PyMeta 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.
How It Works
============
PyMeta compiles a grammar to a Python class, with the rules as methods. The
rules specify parsing expressions, which consume input and return values if
they succeed in matching.
Basic syntax
~~~~~~~~~~~~~~~~
``foo ::= ....``
Define a rule named foo.
``expr1 expr2``
Match expr1, and then match expr2 if it succeeds, returning the value of
expr2. Like Python's ``and``.
``expr1 | expr2``
Try to match expr1 --- if it fails, match expr2 instead. Like Python's
``or``.
``expr*``
Match expr zero or more times, returning a list of matches.
``expr+``
Match expr one or more times, returning a list of matches.
``expr?``
Try to match expr. Returns None if it fails to match.
``~expr``
Fail if the next item in the input matches expr.
``<ruleName>``
Call the rule ``ruleName``.
``'x'``
Match the literal character 'x'.
``expr:name``
Bind the result of expr to the local variable ``name``.
``=> pythonExpression``
Evaluate the given Python expression and return its result.
Comments like Python comments are supported as well, starting with #
and extending to the end of the line.
Interface
=========
The starting point for defining a new grammar is
``pymeta.grammar.OMeta.makeGrammar``, which takes a grammar definition and a
dict of variable bindings for its embedded expressions and produces a Python
class. Grammars can be subclassed as usual, and makeGrammar can be called on
these classes to override rules and provide new ones. To invoke a grammar rule,
call ``grammarObject.apply()`` with its name.
Example Usage
=============
>>> 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")
>>> result
[1, 2, 1, 1]
Raw data
{
"_id": null,
"home_page": "https://github.com/wbond/pymeta3",
"name": "PyMeta3-wheel",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "wbond",
"author_email": "will@wbond.net",
"download_url": "https://files.pythonhosted.org/packages/85/06/9b339f8396e9bfeaa977cae4765405959e4f7097eb9993ff900c0e9f8cbb/pymeta3_wheel-0.5.1.tar.gz",
"platform": null,
"description": "========\nPyMeta3\n========\n\n--------------------------------------------\nA Pattern-Matching Language Based on Python\n--------------------------------------------\n\nThis is a fork of PyMeta 0.5.0 that supports Python 2 and 3.\n\n\nInstallation\n============\n\npip install PyMeta3\n\n\nSummary\n=======\n\nPyMeta is an implementation of OMeta, an object-oriented pattern-matching\nlanguage developed by Alessandro Warth\n(http://www.cs.ucla.edu/~awarth/ometa/). PyMeta provides a compact syntax based\non Parsing Expression Grammars (PEGs) for common lexing, parsing and\ntree-transforming activities in a way that's easy to reason about for Python\nprogrammers.\n\n\nHow It Works\n============\n\nPyMeta compiles a grammar to a Python class, with the rules as methods. The\nrules specify parsing expressions, which consume input and return values if\nthey succeed in matching.\n\nBasic syntax\n~~~~~~~~~~~~~~~~\n\n``foo ::= ....``\n Define a rule named foo.\n``expr1 expr2``\n Match expr1, and then match expr2 if it succeeds, returning the value of\n expr2. Like Python's ``and``.\n``expr1 | expr2``\n Try to match expr1 --- if it fails, match expr2 instead. Like Python's\n ``or``.\n``expr*``\n Match expr zero or more times, returning a list of matches.\n``expr+``\n Match expr one or more times, returning a list of matches.\n``expr?``\n Try to match expr. Returns None if it fails to match.\n``~expr``\n Fail if the next item in the input matches expr.\n``<ruleName>``\n Call the rule ``ruleName``.\n``'x'``\n Match the literal character 'x'.\n``expr:name``\n Bind the result of expr to the local variable ``name``.\n``=> pythonExpression``\n Evaluate the given Python expression and return its result.\n\nComments like Python comments are supported as well, starting with #\nand extending to the end of the line.\n\nInterface\n=========\n\nThe starting point for defining a new grammar is\n``pymeta.grammar.OMeta.makeGrammar``, which takes a grammar definition and a\ndict of variable bindings for its embedded expressions and produces a Python\nclass. Grammars can be subclassed as usual, and makeGrammar can be called on\nthese classes to override rules and provide new ones. To invoke a grammar rule,\ncall ``grammarObject.apply()`` with its name.\n\nExample Usage\n=============\n\n>>> from pymeta.grammar import OMeta\n>>> exampleGrammar = \"\"\"\nones ::= '1' '1' => 1\ntwos ::= '2' '2' => 2\nstuff ::= (<ones> | <twos>)+\n\"\"\"\n>>> Example = OMeta.makeGrammar(exampleGrammar, {})\n>>> g = Example(\"11221111\")\n>>> result, error = g.apply(\"stuff\")\n>>> result\n[1, 2, 1, 1]\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Pattern-matching language based on OMeta for Python 3 and 2",
"version": "0.5.1",
"project_urls": {
"Homepage": "https://github.com/wbond/pymeta3"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c84413bd18fa4c349a747081cc7ad17c05b2c6c6ac7b187e8b5de00fce95d068",
"md5": "73caa0273c97c849e682fa9c85e0f35f",
"sha256": "d52cf9e4f4a3ba61ba23a80043e75c0f36820f0db4cf84546a8d6a02c6ceaba2"
},
"downloads": -1,
"filename": "PyMeta3_wheel-0.5.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "73caa0273c97c849e682fa9c85e0f35f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 16519,
"upload_time": "2024-10-27T11:09:42",
"upload_time_iso_8601": "2024-10-27T11:09:42.241224Z",
"url": "https://files.pythonhosted.org/packages/c8/44/13bd18fa4c349a747081cc7ad17c05b2c6c6ac7b187e8b5de00fce95d068/PyMeta3_wheel-0.5.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "85069b339f8396e9bfeaa977cae4765405959e4f7097eb9993ff900c0e9f8cbb",
"md5": "73e18a2a055c51a6bfeb99b8b9084732",
"sha256": "c1261fdf83ac0ef8e42ebde6c10de4ca657ed52e7414bb1a07353076e90db673"
},
"downloads": -1,
"filename": "pymeta3_wheel-0.5.1.tar.gz",
"has_sig": false,
"md5_digest": "73e18a2a055c51a6bfeb99b8b9084732",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 29920,
"upload_time": "2024-10-27T11:09:44",
"upload_time_iso_8601": "2024-10-27T11:09:44.125919Z",
"url": "https://files.pythonhosted.org/packages/85/06/9b339f8396e9bfeaa977cae4765405959e4f7097eb9993ff900c0e9f8cbb/pymeta3_wheel-0.5.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-27 11:09:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wbond",
"github_project": "pymeta3",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pymeta3-wheel"
}