M
mark
I want to implement a internal DSL in Python. I would like the syntax
as human readable as possible. This means no disturbing '.;()\'
characters. I like to have the power of the hosting language as well.
Thats why I want to build it as an internal DSL and NOT as a external
DSL.
I want the DSL as human readable as possiblepen_browser
navigate_to 'www.openstreetmap.org' website
search 'Von-Gumppenberg-Strasse, Schmiechen'
verify search_result
zoom in
<<<
Martin Fowler recommends "Method Chaining" to build internal DSLs: Browser("http://www.openstreetmap.org/") \
.search("Von-Gumppenberg-Strasse, Schmiechen") \
.zoom_in()
<<<
I guess that it is possible to argue that this means the same.
Nevertheless I do not like all the parentheses and punctuation
necessary to satisfy the Python interpreter.
The reason why I need this is that I want to have non technical people
review the files written in the DSL.
I already know that there are parser frameworks available but I want
to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and
whatnot).
How would one approach this in Python? Do I need to build a custom
loader which compiles *.dsl files to *.pyc files? Is it possible to
switch between the custom DSL and the standard Python interpreter?
as human readable as possible. This means no disturbing '.;()\'
characters. I like to have the power of the hosting language as well.
Thats why I want to build it as an internal DSL and NOT as a external
DSL.
I want the DSL as human readable as possiblepen_browser
navigate_to 'www.openstreetmap.org' website
search 'Von-Gumppenberg-Strasse, Schmiechen'
verify search_result
zoom in
<<<
Martin Fowler recommends "Method Chaining" to build internal DSLs: Browser("http://www.openstreetmap.org/") \
.search("Von-Gumppenberg-Strasse, Schmiechen") \
.zoom_in()
<<<
I guess that it is possible to argue that this means the same.
Nevertheless I do not like all the parentheses and punctuation
necessary to satisfy the Python interpreter.
The reason why I need this is that I want to have non technical people
review the files written in the DSL.
I already know that there are parser frameworks available but I want
to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and
whatnot).
How would one approach this in Python? Do I need to build a custom
loader which compiles *.dsl files to *.pyc files? Is it possible to
switch between the custom DSL and the standard Python interpreter?