{ "info": { "author": "thautwarm", "author_email": "twshere@outlook.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython" ], "description": "# Frist of All\n\n\n> The awareness of low-level implementation details brings the appreciation of an abstraction and the intuitive explanation for it.\n\nThis is a saying from my idol in the field of [Programming Language](https://en.wikipedia.org/wiki/Programming_language).\n\nI present it here, in case anyone prejudging the reliability of this project.\n\n**THIS PROJECT SHOULD WORK PERFECTLY UNDER ANY SUPPPORTED PYTHON VERSION(>=3.5), FOR ALL 3-RD PARTY LIBRARIES SUPPORTED IN ANY RELIABLE CPYTHON DISTRIBUTION**.\n\nThere is no hack but simple static code analyses and ast transformations, and a hack usually contains `inspect.*` that I'll never use in this project.\n\n# Moshmosh\n\n[![Build](https://travis-ci.com/thautwarm/moshmosh.svg?branch=master)](https://travis-ci.com/thautwarm/moshmosh) [![Support](https://img.shields.io/badge/PyPI- 3\\.5~3\\.7-Orange.svg?style=flat)](https://pypi.org/project/moshmosh-base) [![codecov](https://codecov.io/gh/thautwarm/moshmosh/branch/master/graph/badge.svg)](https://codecov.io/gh/thautwarm/moshmosh)\n\nAn advanced syntax extension system implemented in pure python.\n\n```\npip install -U moshmosh-base --no-compile\n```\n\nNote that `--no-compile` is required.\n\n# Preview\n\n## Working with IPython\n\nYou should copy [moshmosh_ipy.py](https://raw.githubusercontent.com/thautwarm/moshmosh/master/moshmosh_ipy.py)\nto `$USER/.ipython/profile_default/startup/`.\n\nIf this directory does not exist, use command `ipython profile create` to instantiate.\n\nSome examples about pattern matching, pipelines and quick lambdas:\n\n![IPython example 1](https://raw.githubusercontent.com/thautwarm/moshmosh/master/static/img1.png)\n\nSome examples about the scoped operators:\n\n![IPython example 2](https://raw.githubusercontent.com/thautwarm/moshmosh/master/static/img2.png)\n\n## Working with regular Python files\n\nImport `moshmosh` in your main module:\n\n![Main.py](https://raw.githubusercontent.com/thautwarm/moshmosh/master/static/main.png)\n\nThen, in `mypackage.py`, start coding with a pragma comment `# moshmosh?`, then you can use moshmosh extension system.\n\n![Upack.py](https://raw.githubusercontent.com/thautwarm/moshmosh/master/static/upack.png)\n\n## Case Study : Pattern Matching\n\nThe matching protocol which stems from Python-ideas mailing list is introduced in,\nwhich means you can define your own patterns conveniently.\nThe link is [here](https://mail.python.org/pipermail/python-ideas/2015-April/032920.html).\n\n```python\n# moshmosh?\n# +pattern-matching\n\nclass GreaterThan:\n def __init__(self, v):\n self.v = v\n\n def __match__(self, cnt: int, to_match):\n if isinstance(to_match, int) and cnt is 0 and to_match > self.v:\n return () # matched\n # 'return None' indicates 'unmatched'\n\nwith match(114, 514):\n if (GreaterThan(42)() and a, b):\n print(b, a)\n# 514 114\n```\n\nNote that the matching clauses should be exhaustive,\notherwise, a `moshmosh.extensions.pattern_matching.runtime.NotExhaustive`\nmight get raised.\n\nThe supported Patterns are listed here, which is\nof course much more powerful than most programming languages.\n\n- And pattern: `pat1 and pat2 and pat3 ...`\n- Or pattern: `pat1 or pat2 or pat3...`\n- Pin pattern: `pin(value)`, this is quite useful. See [Elixir Pin Operator](https://elixir-lang.org/getting-started/pattern-matching.html#the-pin-operator)\n- Literal pattern: `1, \"str\", 1+2j, (1, 2)`\n- As pattern: `a, var`\n- Wildcard: `_`\n- Guard: `when(cond1, cond2, cond3)`\n- Nested patterns:\n - Tuple: `(pat1, pat2, pat3), (pat1, *pat2, pat3)`\n - List: `[pat1, pat2, pat3], [pat1, *pat2, pat3]`\n - Recogniser: `Cons(pat1, pat2, pat3)`, note that,\n the function `Cons.__match__(, value_to_match)` is exact the protocol.\n\nThe pattern matching should be more efficient than those hand-written codes without\nugly optimizations.\n\nBesides, Moshmosh's pattern matching is orders of magnitude faster than\nany other alternatives.\n\n## Case Study : Template-Python\n\nThis is relatively a simple quasiquote implementation, inspired by MetaOCaml.\nIt does not support manual splices or nested quotations, but the function arguments\nare automatically spliced.\n\n```python\n# moshmosh?\n# +template-python\n\n@quote\ndef f(x):\n x + 1\n x = y + 1\n\nfrom moshmosh.ast_compat import ast\nfrom astpretty import pprint\n\nstmts = f(ast.Name(\"a\"))\npprint(ast.fix_missing_locations(stmts[0]))\npprint(ast.fix_missing_locations(stmts[1]))\n\n# =>\nExpr(\n lineno=7,\n col_offset=4,\n value=BinOp(\n lineno=7,\n col_offset=4,\n left=Name(lineno=7, col_offset=4, id='a', ctx=Load()),\n op=Add(),\n right=Num(lineno=7, col_offset=8, n=1),\n ),\n)\nAssign(\n lineno=8,\n col_offset=4,\n targets=[Name(lineno=8, col_offset=4, id='a', ctx=Store())],\n value=BinOp(\n lineno=8,\n col_offset=8,\n left=Name(lineno=8, col_offset=8, id='y', ctx=Load()),\n op=Add(),\n right=Num(lineno=8, col_offset=12, n=1),\n ),\n)\n```\n\n## Case Study: Lazy Import\n\n```python\n# moshmosh?\n# +lazy-import\nimport numpy as np\n# -lazy-import\n\n# in fact numpy is not imported here,\n# and once you use it, it gets imported.\n\ndef arr10():\n # The first time call\n # arr10 will enforce the import of numpy.\n return np.zeros(10)\n```\n\nAfter the lazy modules are actually imported, there's\nno overhead to access their members.\n\nHowever, please only import modules when using `lazy-import`.\n\nThe use case is about the necessary cross-import when you want to\norganise your codebase in a more fine-grained way.\n\n\n## Acknowledgements\n\n- [future-fstrings](https://github.com/asottile/future-fstrings)\n- Pattern matching in Python\n - [older implementations](http://www.grantjenks.com/docs/patternmatching/#alternative-packages)\n - search \"pattern matching\" at [Python-ideas](https://mail.python.org/archives/list/python-ideas@python.org/).", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/thautwarm/moshmosh", "keywords": "syntax,semantics,extension,macro,pattern matching", "license": "mit", "maintainer": "", "maintainer_email": "", "name": "moshmosh-base", "package_url": "https://pypi.org/project/moshmosh-base/", "platform": "any", "project_url": "https://pypi.org/project/moshmosh-base/", "project_urls": { "Homepage": "https://github.com/thautwarm/moshmosh" }, "release_url": "https://pypi.org/project/moshmosh-base/0.3.3/", "requires_dist": null, "requires_python": ">=3.5", "summary": "advanced syntax&semantics extension system for Python", "version": "0.3.3" }, "last_serial": 5976150, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "7baa558bd54f27bfd1705a2ab0be1600", "sha256": "6d58d1442664e3e5e69996424723a4e3f372988da14c066453bcddd344bbf8cd" }, "downloads": -1, "filename": "moshmosh_base-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7baa558bd54f27bfd1705a2ab0be1600", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 27393, "upload_time": "2019-10-13T16:41:04", "url": "https://files.pythonhosted.org/packages/61/44/dbc2e0a2e26e8d01f023ea3221a870ad9188f0932b5fb08a2c7302130500/moshmosh_base-0.2-py3-none-any.whl" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "2a6707fc848dc4ea9b056f609ad9ff08", "sha256": "27e14ec3c8006da8f05ca8ed10af4c2cb4ed88503b47522e11b9f3bfdbfa2982" }, "downloads": -1, "filename": "moshmosh-base-0.3.tar.gz", "has_sig": false, "md5_digest": "2a6707fc848dc4ea9b056f609ad9ff08", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 24424, "upload_time": "2019-10-14T16:49:11", "url": "https://files.pythonhosted.org/packages/a6/d3/6ac448e913df99a649ce294c5919a3c9093d9c32922bbe7f3e4a23634399/moshmosh-base-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "a0270e9d414dbd58a2352cbd07147e98", "sha256": "f5792432468a916d3839bf4de9026506df8e8ddfde6f7ef3a714f3e49616c64c" }, "downloads": -1, "filename": "moshmosh-base-0.3.1.tar.gz", "has_sig": false, "md5_digest": "a0270e9d414dbd58a2352cbd07147e98", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 24422, "upload_time": "2019-10-14T16:49:49", "url": "https://files.pythonhosted.org/packages/48/93/88d168128894f460de93076315191508cafea406e470b6e71e2f4f7e9fb9/moshmosh-base-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "aa4e060e0a0256dc88f3e0db2f23d03e", "sha256": "3d46293df0a9d1ffe83da0aa211d9e14881e24904b278dd4f7f324bd8bf82193" }, "downloads": -1, "filename": "moshmosh-base-0.3.2.tar.gz", "has_sig": false, "md5_digest": "aa4e060e0a0256dc88f3e0db2f23d03e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 24489, "upload_time": "2019-10-14T18:04:20", "url": "https://files.pythonhosted.org/packages/4c/de/8d6220f4b43a68e522439687f64283b4e9d33a0490536f853a6e4f80a09c/moshmosh-base-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "6b8323b84f5d22737706b9edcf006bcd", "sha256": "a480a8392d67737867a867fb1d310e497a2d374bb56fb6e993c7a358d7965ac2" }, "downloads": -1, "filename": "moshmosh-base-0.3.3.tar.gz", "has_sig": false, "md5_digest": "6b8323b84f5d22737706b9edcf006bcd", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 26123, "upload_time": "2019-10-15T10:41:32", "url": "https://files.pythonhosted.org/packages/72/de/993ee938c860648dc8747cccc842b3107a821b353fab6a9a081711a1051a/moshmosh-base-0.3.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6b8323b84f5d22737706b9edcf006bcd", "sha256": "a480a8392d67737867a867fb1d310e497a2d374bb56fb6e993c7a358d7965ac2" }, "downloads": -1, "filename": "moshmosh-base-0.3.3.tar.gz", "has_sig": false, "md5_digest": "6b8323b84f5d22737706b9edcf006bcd", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 26123, "upload_time": "2019-10-15T10:41:32", "url": "https://files.pythonhosted.org/packages/72/de/993ee938c860648dc8747cccc842b3107a821b353fab6a9a081711a1051a/moshmosh-base-0.3.3.tar.gz" } ] }