{ "info": { "author": "Joe Jevnik", "author_email": "joejev@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", "Natural Language :: English", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Pre-processors" ], "description": "quasiquotes\n===========\n\n|docs|\n\nBlocks of non-python code sprinkled in for extra seasoning.\n\n\nWhat is a ``quasiquote``\n------------------------\n\nAn ``quasiquote`` is a new syntactical element that allows us to embed non\npython code into our existing python code. The basic structure is as follows:\n\n\n.. code-block:: python\n\n\n # coding: quasiquotes\n\n [$name|some code goes here|]\n\n\nThis desuagars to:\n\n.. code-block:: python\n\n name.quote_expr(\"some code goes here\", frame, col_offset)\n\nwhere ``frame`` is the executing stack frame and ``col_offset`` is the column\noffset of the quasiquoter.\n\nThis allows us to use slightly nicer syntax for our code.\nThe ``# coding: quasiquotes`` is needed to enable this extension.\nThe syntax is chosen to match haskell's quasiquote syntax from GHC 6.12. We need\nto use the older syntax (with the ``$``) because python's grammar would be\nambiguous without it at the quote open step. To simplify the tokenizer, we chose\nto use slighly more verbose syntax.\n\nWe may also use statement syntax for quasiquotes in a modified with block:\n\n.. code-block:: python\n\n # coding: quasiquotes\n\n with $name:\n some code goes here\n\nThis desuagars to:\n\n.. code-block:: python\n\n name.quote_stmt(\" some code goes here\", frame, col_offset)\n\n\n\nThe ``c`` quasiquoter\n---------------------\n\nThe builtin ``c`` quasiquoter allows us to inline C code into our python.\nFor example:\n\n.. code-block:: python\n\n >>> from quasiquotes.c import c\n >>> def f(a):\n ... with $c:\n ... printf(\"%ld\\n\", PyLong_AsLong(a));\n ... a = Py_None;\n ... Py_INCREF(a);\n ... print(a)\n ...\n >>> f(0)\n 0\n None\n >>> f(1)\n 1\n None\n\n\nHere we can see that the quasiquoter can read from and write to the local\nscope.\n\n\nWe can also quote C expressions with the quote expression syntax.\n\n.. code-block:: python\n\n >>> def cell_new(n):\n ... return [$c|PyCell_New(n);]\n ...\n >>> cell_new(1)\n \n\n\nHere we can see that the ``c`` quasiquoter is really convenient as a python\ninterface into the C API.\n\n.. warning::\n\n CPython uses a reference counting system to manage the lifetimes of objects.\n Code like:\n\n .. code-block:: python\n\n return [$|Py_None|]\n\n can cause a potential segfault when ``None`` because it will have 1 less\n reference than expected. Instead, be sure to remember to incref your\n expressions with:\n\n .. code-block:: python\n\n return [$|Py_INCREF(Py_None); Py_None|]\n\n You must also incref when reassigning names from the enclosing python scope.\n For more information, see the\n `CPython docs `__.\n\n\nIPython Integration\n-------------------\n\nWe can use the ``c`` quasiquoter in the IPython repl or notebook as a cell or\nline magic. When used as a line magic, it is quoted as an expression. When used\nas a cell magic, it is quoted as a statement.\n\n\n.. code-block:: python\n\n In [1]: import quasiquotes.c\n\n In [2]: a = 5\n\n In [3]: %c PyObject *b = PyLong_FromLong(3); PyObject *ret = PyNumber_Add(a, b); Py_DECRE F(b); ret;\n Out[3]: 8\n\n In [4]: %%c\n ...: printf(\"%ld + %ld = %ld\\n\", 3, PyLong_AsLong(a), PyLong_AsLong(_3));\n ...: puts(\"reassigning 'a'\");\n ...: a = Py_None;\n ...: Py_INCREF(a);\n ...:\n 3 + 5 = 8\n reassigning 'a'\n\n In [5]: a is None\n Out[5]: True\n\n\n.. |docs| image:: https://readthedocs.org/projects/quasiquotes/badge/?version=latest\n :target: http://quasiquotes.readthedocs.org/en/latest/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/llllllllll/quasiquotes", "keywords": null, "license": "GPL-2", "maintainer": null, "maintainer_email": null, "name": "quasiquotes", "package_url": "https://pypi.org/project/quasiquotes/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/quasiquotes/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/llllllllll/quasiquotes" }, "release_url": "https://pypi.org/project/quasiquotes/0.2.0/", "requires_dist": null, "requires_python": null, "summary": "Quasiquotation in python", "version": "0.2.0" }, "last_serial": 1829833, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "756305d616fc0c4cdff748a31ed344f7", "sha256": "a7a3503ac9a9b6e246f64d2dd06c96a71d0eba713d26013ffca86d8cfd02997d" }, "downloads": -1, "filename": "quasiquotes-0.0.1.tar.gz", "has_sig": false, "md5_digest": "756305d616fc0c4cdff748a31ed344f7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7350, "upload_time": "2015-07-11T03:28:09", "url": "https://files.pythonhosted.org/packages/68/c0/6945be5e737b38d1f7569c4bff53e4e22502cc8e20ec5e2316d6236c4001/quasiquotes-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "0a79c3c3552e92a620445cf4444fcd08", "sha256": "a6e15a892302b8f48df25c231da3b21c8d9bfeeea53bd10159249d349f4b12ed" }, "downloads": -1, "filename": "quasiquotes-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0a79c3c3552e92a620445cf4444fcd08", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7404, "upload_time": "2015-07-11T03:42:11", "url": "https://files.pythonhosted.org/packages/67/43/4d8f5a3f3d274f457db14101e8922931f9ec07eb36cd2747f8c62680531a/quasiquotes-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "946c53e9ecda015d66b2b6423355c3b3", "sha256": "579f8880beda026eb27b8c575abd4d5e1021e8be30706491ac5aea2d654ffb9b" }, "downloads": -1, "filename": "quasiquotes-0.2.0.tar.gz", "has_sig": false, "md5_digest": "946c53e9ecda015d66b2b6423355c3b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12380, "upload_time": "2015-11-23T18:17:15", "url": "https://files.pythonhosted.org/packages/bd/22/99bd423313a38d8b29ddd43a716c51b3f5a407f589837a4ebaec6154e840/quasiquotes-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "946c53e9ecda015d66b2b6423355c3b3", "sha256": "579f8880beda026eb27b8c575abd4d5e1021e8be30706491ac5aea2d654ffb9b" }, "downloads": -1, "filename": "quasiquotes-0.2.0.tar.gz", "has_sig": false, "md5_digest": "946c53e9ecda015d66b2b6423355c3b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12380, "upload_time": "2015-11-23T18:17:15", "url": "https://files.pythonhosted.org/packages/bd/22/99bd423313a38d8b29ddd43a716c51b3f5a407f589837a4ebaec6154e840/quasiquotes-0.2.0.tar.gz" } ] }