looking for tips on how to implement "ruby-style" Domain Specific Language in Python
mark.fink1 at googlemail.com
Thu Jan 8 20:43:43 CET 2009
> So you can't make an internal DSL like this that uses Python's built-
> in grammar. You'd have to hack the parser or settle for an external
This time it is really hard for me but I begin accepting the fact that
I will have to build an external DSL. I experimented some weeks ago
with ANTLR and the tools work fine but I do not like the extra effort
to learn and maintain the extra tooling. I think that in the beginning
the DSL language will have to change a very often as new features are
added. To implement a standardized rock solid language like SQL ANTLR
might be the perfect tool but to develop something from scratch that
will be expanded interactively a internal DSL has huge benefits.
Please not that I really like ANTLR. It is just the first tool I used
for this task and I want to double check if other tools fit better to
I will look into Ply and Pyparsing over the next weeks unless someone
points out that there is some special tool that makes growing a new
"fast evolving" language as easy as building an internal DSL. Maybe
this is all overkill and there is a hacking ruby-style DSLs with
regular expressions recipe out there? So far I could not find one.
> However, the gist of it seems to be that you want to be able to write
> files in your DSL that can be imported just like a regular Python
> module. Yes, that can be done.
> See PEP 302, Import Hooks:
> Python's standard importer looks for files with *.py, *.pyc, *.pyd, or
> *.so extensions. You could write an importer that looks for *.dsl
> files, and, instead of loading it as a Python file, invokes your DSL
This is really helpful. Thanks for giving me directions.
More information about the Python-list