[IPython-dev] How to parse a domain-specific language on top of Python
Doug Blank
doug.blank at gmail.com
Wed Dec 3 11:47:45 EST 2014
On Wed, Dec 3, 2014 at 11:37 AM, Joachim Wuttke <j.wuttke at fz-juelich.de>
wrote:
> ((cross-posting from http://stackoverflow.com/questions/27274607
> where this question gets close votes for being "too broad":))
>
>
> I want to construct a domain-specific language as a superset of Python.
> Cryptic commands like
>
> f7:10y=x^2
>
> designed to minimize typing shall be parsed into plain Python
>
> for k in range(7,10):
> f[k].set_y( expr='x^2' )
>
> before being executed. Probably, the command-line interface shall be
> IPython.
>
> What would be an appropriate architecture: Shall I implement the
> cryptic-to-plain-Python translation in the IPython command-line shell or in
> its kernel daemon? Are there helpful libraries / tutorials / examples?
>
> Or more generically: Are there examples how to add complex syntactic sugar
> to Python?
>
You could handle this in a number of ways:
1) You could create your own language, parse it, and generate Python AST.
The Hy Lisp kernel (for IPython 3) does this, and turns it back into Python
so that all of the IPython stuff just works. Even shows the actual Python
code in the console history. See https://github.com/bollwyvl/hy_kernel
2) You could do this as a magic. You could use a simple parser to just
output regular Python. This is the least complex, and should be easier to
keep working over time.
3) You could implement your own parser written in Python as its own kernel
(google "wrapper kernel"). You can even have your own magics etc. (see
https://github.com/blink1073/metakernel)
4) I think that there are also syntactic transformers built into IPython...
that may be the way to go, but I don't have any info on that.
Good luck!
-Doug
>
>
> Thanks in advance - Joachim
>
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141203/6c537b6d/attachment.html>
More information about the IPython-dev
mailing list