Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 8, 7:25 am, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: It seems we're defining DSL in two different ways. You can't write a DSL in Python because you can't change the syntax and you don't have macros. You can write a compiler in Python that will compile your DSL. Yes, that's what I'm saying. You can get the same results even thought you can't manipulate the Python language itself as it's compiling Python because you can feed it Python code that you've generated. As another poster mentioned, eventually PyPy will be done and then you'll get more of an in-Python DSL. Of course, such a language wouldn't be Python anymore because Python doesn't have such features. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 8, 8:03 am, Kay Schluehr kay.schlu...@gmx.net wrote: On 8 Jan., 16:25, J Kenneth King ja...@agentultra.com wrote: As another poster mentioned, eventually PyPy will be done and then you'll get more of an in-Python DSL. May I ask why you consider it as important that the interpreter is written in Python? I see no connection between PyPy and syntactical Python extensions and the latter isn't an objective of PyPy. You can write Python extensions with virtually any Python aware parser. M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then there is ANTLR which provides a Python grammar. I also know about two other Python aware parsers. One of them was written by myself. If you're going to manipulate the Python compiler/interpreter from the Python program itself, it's only reasonable that the Python compiler/ interpreter be written in Python so that it can be manipulated. If you haven't already made it through SICP, you really should. It will help you understand why being able to write a language in itself is a big deal and why having the language around to be manipulated from within the language is very useful. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 7, 9:16 am, Chris Mellon arka...@gmail.com wrote: The OP wants a Ruby-style DSL by which he means something that lets me write words instead of expressions. The ruby syntax is amenable to this, python (and lisp, for that matter) syntax is not and you can't implement that style of internal DSL in those languages. The answer to the OP is you can't - use Ruby or modify your requirements. As far as putting the code into Python, yeah, you can't put it in Python. The best you can do is store it in a string and then interpret the string with some function later on. That's what I'm saying. It seems we're defining DSL in two different ways. You can't write a DSL in Python because you can't change the syntax and you don't have macros. You can write a compiler in Python that will compile your DSL. As another poster mentioned, eventually PyPy will be done and then you'll get more of an in-Python DSL. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On 8 Jan., 16:25, J Kenneth King ja...@agentultra.com wrote: As another poster mentioned, eventually PyPy will be done and then you'll get more of an in-Python DSL. May I ask why you consider it as important that the interpreter is written in Python? I see no connection between PyPy and syntactical Python extensions and the latter isn't an objective of PyPy. You can write Python extensions with virtually any Python aware parser. M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then there is ANTLR which provides a Python grammar. I also know about two other Python aware parsers. One of them was written by myself. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
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 preprocessor. 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 my needs. 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: http://www.python.org/dev/peps/pep-0302/ 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 parser. This is really helpful. Thanks for giving me directions. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
Kay Schluehr kay.schlu...@gmx.net writes: On 8 Jan., 16:25, J Kenneth King ja...@agentultra.com wrote: As another poster mentioned, eventually PyPy will be done and then you'll get more of an in-Python DSL. May I ask why you consider it as important that the interpreter is written in Python? I don't think it's important for Python to have a meta-circular interpreter (though it can't hurt). I see no connection between PyPy and syntactical Python extensions and the latter isn't an objective of PyPy. You can write Python extensions with virtually any Python aware parser. M.A.Lemburg already mentioned PLY and PLY is used for Cython. Then there is ANTLR which provides a Python grammar. I also know about two other Python aware parsers. One of them was written by myself. Because... there is no connection to see? I never mentioned any such relation. DSL's tend to be a natural side-effect of languages which can manipulate their own expressions without extensive parsing. Creating a new parser that can generate Python AST's is certainly a valid approach (and probably the easiest one). It's not the only one. It depends on your definition of a DSL. My definition isn't satisfied with creating a parser, and so my answers reflect that. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
O.K. Mark. Since you seem to accept the basic requirement to build an *external* DSL I can provide some help. I'm the author of EasyExtend ( EE ) which is a system to build external DSLs for Python. http://www.fiber-space.de/EasyExtend/doc/EE.html EE is very much work in progress and in the last year I was more engaged with increasing power than enhance accessibility for beginners. So be warned. A DSL in EE is called a *langlet*. Download the EE package and import it in a Python shell. A langlet can then be built this way: import EasyExtend EasyExtend.new_langlet(my_langlet, prompt = myl , source_ext = .dsl) This creates a bunch of files in a directory site-packages-path/EasyExtend/langlets/my_langlet Among them is run_my_langet.py and langlet.py. You can cd to the directory and apply $python run_my_langlet.py which opens a console with prompt 'myl'. Each langlet is immediatly interactive. A user can also run a langlet specific module like $python run_my_langlet.py mod.dsl with the suffix .dsl defined in the langlet builder function. Each module xxx.dsl can be imported from other modules of the my_langlet langlet. EE provides a generic import hook for user defined suffixes. In order to do anything meaningful one has to implement langlet transformations in the langlet.py module. The main transformations are defined in a class called LangletTransformer. It defines a set of visitor methods that are marked by a decorator called @trans. Each @trans method is named like a terminal/non-terminal in a grammar file and responds to a terminal or non-terminal node of the parse tree which is traversed. The structure of the parse tree is the same as those you'd get from Pythons builtin parser. It is entirely determined by 4 files: - Grammar which is precisely the Python grammar found in the Python source distribution. - Grammar.ext which defines new non-terminals and overwrites old ones. - Token which defines Pythons token. - Token.ext which is the analog of Grammar.ext for token definitions. The Grammar.ext file is in the directory my_langlet/parsedef. There is also an analog lexdef directory for Token.ext. A possible Grammar.ext extension of the Python grammar that overwrites two non-terminals of looks like this: Grammar.ext --- trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME | NAME | NUMBER | STRING atom: ('(' [yield_expr|testlist_gexp] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | '`' testlist1 '`' | NAME | NUMBER | STRING) --- Once this has been defined you can start a new my_langlet session and type myl navigate_to 'www.openstreetmap.org' website Traceback (most recent call last): File C:\lang\Python25\lib\site-packages\EasyExtend\eeconsole.py, line 270, in compile_cst _code = compile(src,input,single, COMPILER_FLAGS) File input, line 1 navigate_to 'www.openstreetmap.org' website ^ SyntaxError: invalid syntax myl It will raise a SyntaxError but notice that this error stems from the *compiler*, not the parser. The parser perfectly accepts the modified non-terminals and produces a parse tree. This parse tree has to be transformed into a valid Python parse tree that can be accepted by Pythons bytecode compiler. I'm not going into detail here but recommend to read the tutorial http://www.fiber-space.de/EasyExtend/doc/tutorial/EETutorial.html that walks through a complete example that defines a few terminals, non-terminals and the transformations accordingly. It also shows how to use command line options to display parse tree properties, unparse parse trees back into source code ( you can eliminate DSL code from the code base entirely and replace it by equivalent Python code ), do some validation on transformed parse trees etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 12:24 pm, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 8:18 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. I get that Lisp is special because you can hack on the reader as it is reading the file in. This is strongly discouraged behavior, as far as I know, despite the number of cute hacks you can accomplish with it. It is generally discouraged unless there's a reason for it. But consider that this really isn't different than having a program read in the lisp-with-modification source and spitting out pure lisp, to be read by an honest-to-gosh lisp program later. If that's the case, then Lisp and Python really aren't that different in this regard, except that you don't have the option of modifying the reader as it reads in the file. I think you are missing the distinction. Lisp expressions are also data structures. A Lisp expression can be passed to functions and macros to be operated on before being executed. When you're writing Lisp source, you're basically looking at the AST on one level and when you start writing macros for your program, you're creating a DSL or interface to that AST. Lisp source is eventually expanded to a giant list that is consed by the evaluator (as far as I understand it. I'm just getting into the compiler stuff myself). Consider: (my-func 1 2 3) This is just a list, the primitive data-type in Lisp! This piece of data can be operated on by other bits of Lisp code because it is just a list as far as Lisp is concerned. In contrast, Python source is a string that needs to be parsed into bytecode which is then run through the interpreter. The AST is completely hidden from the source author. Python expressions are not data types either and hence no macros -- I can't write a python function that generates python code at compile time. I can only write a python program that parses some other string and generates code that can be run by another interpreter. Consider: for i in range(0, 100): do_something_interesting(i) That's a pretty straight forward Python expression, but I can't do anything with it -- it's not a unit of data, it's a string. The distinction is not subtle by any means. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On 7 Jan., 16:50, J Kenneth King ja...@agentultra.com wrote: Python expressions are not data types either and hence no macros -- I can't write a python function that generates python code at compile time. Have you ever considered there are languages providing macros other than Lisp? Macros have nothing to do with homoiconcity. I can only write a python program that parses some other string and generates code that can be run by another interpreter. No, it is the same interpreter and it is also possible to modify python parsers on the fly. This is just not possible with Pythons builtin parser. Consider: for i in range(0, 100): do_something_interesting(i) That's a pretty straight forward Python expression, but I can't do anything with it -- it's not a unit of data, it's a string. The distinction is not subtle by any means. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Wed, Jan 7, 2009 at 9:50 AM, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 12:24 pm, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 8:18 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. I get that Lisp is special because you can hack on the reader as it is reading the file in. This is strongly discouraged behavior, as far as I know, despite the number of cute hacks you can accomplish with it. It is generally discouraged unless there's a reason for it. But consider that this really isn't different than having a program read in the lisp-with-modification source and spitting out pure lisp, to be read by an honest-to-gosh lisp program later. If that's the case, then Lisp and Python really aren't that different in this regard, except that you don't have the option of modifying the reader as it reads in the file. I think you are missing the distinction. Lisp expressions are also data structures. A Lisp expression can be passed to functions and macros to be operated on before being executed. When you're writing Lisp source, you're basically looking at the AST on one level and when you start writing macros for your program, you're creating a DSL or interface to that AST. Lisp source is eventually expanded to a giant list that is consed by the evaluator (as far as I understand it. I'm just getting into the compiler stuff myself). Consider: (my-func 1 2 3) This is just a list, the primitive data-type in Lisp! This piece of data can be operated on by other bits of Lisp code because it is just a list as far as Lisp is concerned. In contrast, Python source is a string that needs to be parsed into bytecode which is then run through the interpreter. The AST is completely hidden from the source author. Python expressions are not data types either and hence no macros -- I can't write a python function that generates python code at compile time. I can only write a python program that parses some other string and generates code that can be run by another interpreter. Consider: for i in range(0, 100): do_something_interesting(i) That's a pretty straight forward Python expression, but I can't do anything with it -- it's not a unit of data, it's a string. The distinction is not subtle by any means. Ignoring reader macros for a moment, there is no way in either lisp, ruby, or python to change the syntax that the compiler understands, and the ability to work with your code directly as a data structure (which is what makes lisp macros powerful) isn't directly relevant to the idea of an internal' DSL. The OP wants a Ruby-style DSL by which he means something that lets me write words instead of expressions. The ruby syntax is amenable to this, python (and lisp, for that matter) syntax is not and you can't implement that style of internal DSL in those languages. The answer to the OP is you can't - use Ruby or modify your requirements. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
Kay Schluehr kay.schlu...@gmx.net writes: On 7 Jan., 16:50, J Kenneth King ja...@agentultra.com wrote: Python expressions are not data types either and hence no macros -- I can't write a python function that generates python code at compile time. Have you ever considered there are languages providing macros other than Lisp? Of course. Macros have nothing to do with homoiconcity. Not directly, no. I can only write a python program that parses some other string and generates code that can be run by another interpreter. No, it is the same interpreter and it is also possible to modify python parsers on the fly. This is just not possible with Pythons builtin parser. PyPy is probably the best bet when/if it gets finished. Consider: for i in range(0, 100): do_something_interesting(i) That's a pretty straight forward Python expression, but I can't do anything with it -- it's not a unit of data, it's a string. The distinction is not subtle by any means. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 6, 9:32 am, mark mark.fi...@googlemail.com wrote: 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 possible: open_browser navigate_to 'www.openstreetmap.org'website search 'Von-Gumppenberg-Strasse, Schmiechen' verify search_result zoom in In the Python grammar, there are no non-trivial situations where two expressions can be separated by whitespace and not punctuation. (The trivial exception is string concatentation.) String constants like 'www.openstreetmap.org' and identifiers like open_browser are expressions, and if you try to separate them with whitespace you get a syntax error. 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 preprocessor. 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? I don't know specifically what you mean my custom loader, or switching between the custom DSL and the standard Python interpreter. 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: http://www.python.org/dev/peps/pep-0302/ 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 parser. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 7, 7:50 am, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 12:24 pm, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 8:18 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. I get that Lisp is special because you can hack on the reader as it is reading the file in. This is strongly discouraged behavior, as far as I know, despite the number of cute hacks you can accomplish with it. It is generally discouraged unless there's a reason for it. But consider that this really isn't different than having a program read in the lisp-with-modification source and spitting out pure lisp, to be read by an honest-to-gosh lisp program later. If that's the case, then Lisp and Python really aren't that different in this regard, except that you don't have the option of modifying the reader as it reads in the file. I think you are missing the distinction. Lisp expressions are also data structures. A Lisp expression can be passed to functions and macros to be operated on before being executed. When you're writing Lisp source, you're basically looking at the AST on one level and when you start writing macros for your program, you're creating a DSL or interface to that AST. Lisp source is eventually expanded to a giant list that is consed by the evaluator (as far as I understand it. I'm just getting into the compiler stuff myself). I think you misunderstood what I was trying to explain. Yes, you can do those wonderful things with Lisp. You can also do wonderful things with Python. Consider programs that take some text written in some other language besides Python. Those programs interpret and translate the text to Python. Then the programs feed the translations to the Python interpreter. Tada! You have a DSL in Python. No, it's not built in, nor is there any standard, but it is entirely possible and people are doing it today. That's how the variety of templating solutions work in the Python world. It's why I can write ${x +y} in Mako and get a Python program that will do the right thing. Alternatively, you can skip the Python interpreter altogether, and write your own interpreter for the language. If it's a simple language (like the original poster hinted at), this is very easy to do. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 7, 9:16 am, Chris Mellon arka...@gmail.com wrote: The OP wants a Ruby-style DSL by which he means something that lets me write words instead of expressions. The ruby syntax is amenable to this, python (and lisp, for that matter) syntax is not and you can't implement that style of internal DSL in those languages. The answer to the OP is you can't - use Ruby or modify your requirements. As far as putting the code into Python, yeah, you can't put it in Python. The best you can do is store it in a string and then interpret the string with some function later on. -- http://mail.python.org/mailman/listinfo/python-list
looking for tips on how to implement ruby-style Domain Specific Language in Python
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 possible: open_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? -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: Is it possible to switch between the custom DSL and the standard Python interpreter? As far as I can tell, there are three different options: - Embed a Python and DSL interpreter in the same executable. - Write the DSL interpreter in Python. - Expose the DSL interpreter as a Python extension module. I don't know which you prefer, but I would try to avoid the first. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 6, 8:13 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: Is it possible to switch between the custom DSL and the standard Python interpreter? - Write the DSL interpreter in Python. There are Python modules out there that make writing a language interpreter almost trivial, provided you are familiar with tools like Bison and the theories about parsing in general. I suggest PLY, but there are other really good solution out there. If you are familiar enough with parsing and the syntax is simple enough, you can write your own parser. The syntax you describe above is really simple, so using str.split and then calling a function based on the first item is probably enough. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 6, 8:18 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
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? Sure, but there is no way to avoid extending the Python parser and then your DSL becomes external. I remember having had a similar discussion a while ago with Kevin Dangoor the original TurboGears developer who has also written Paver [1]. In the end DSL syntax wasn't worth the hassle and Kevin developed Paver entirely in Python. Kay [1] http://www.blueskyonmars.com/projects/paver/ -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On 2009-01-06 20:42, Kay Schluehr wrote: 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? Sure, but there is no way to avoid extending the Python parser and then your DSL becomes external. Try python4ply: http://dalkescientific.com/Python/python4ply.html ...much easier to work with than extending the Python parser by hand. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 06 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 8:18 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
J Kenneth King wrote: [...] I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. a) How is Google going to know if he's really interested? b) Put a space after the -- in your sig, please; that way my mailer won't yto to quote your signature as part of the message. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement ruby-style Domain Specific Language in Python
On Jan 6, 12:24 pm, J Kenneth King ja...@agentultra.com wrote: Jonathan Gardner jgard...@jonathangardner.net writes: On Jan 6, 8:18 am, sturlamolden sturlamol...@yahoo.no wrote: On Jan 6, 4:32 pm, mark mark.fi...@googlemail.com wrote: I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. Also beware that Python is not Lisp. You cannot define new syntax (yes I've seen the goto joke). This isn't really true. You can, for instance, write a program (in Python) that takes your pseudo-Python and converts it into Python. This is what a number of templating libraries such as Mako do. Which is not even close to being the same. Lisp - the program source is also the data format Python - the program source is a string I could go on a really long rant about how the two are worlds apart, but I'll let Google tell you if you're really interested. I get that Lisp is special because you can hack on the reader as it is reading the file in. This is strongly discouraged behavior, as far as I know, despite the number of cute hacks you can accomplish with it. But consider that this really isn't different than having a program read in the lisp-with-modification source and spitting out pure lisp, to be read by an honest-to-gosh lisp program later. If that's the case, then Lisp and Python really aren't that different in this regard, except that you don't have the option of modifying the reader as it reads in the file. -- http://mail.python.org/mailman/listinfo/python-list