accept xml instead of plain Python text?

E

Edward K. Ream

I am wondering whether that has been any discussion of a project like the
following in the Python world:

- jezix http://www.tel.fer.hr/users/mtopol/jezix/
- javaml http://sourceforge.net/projects/javaml/

The general idea is that it would sometimes be nice to be able to feed xml
to the Python parser instead of plain text. I can think of several reasons
why this would be _inconvenient_ for the Python community. Foremost among
them would be that no plain-text tool would work with xml'zed Python.

Has the subject been discussed in the Python community? If so, where? I
suspect this is a bad (or cumbersome) idea, but I'd like to be sure :)
Thanks.

Edward
 
J

John Roth

Edward K. Ream said:
I am wondering whether that has been any discussion of a project like the
following in the Python world:

- jezix http://www.tel.fer.hr/users/mtopol/jezix/
- javaml http://sourceforge.net/projects/javaml/

The general idea is that it would sometimes be nice to be able to feed xml
to the Python parser instead of plain text. I can think of several reasons
why this would be _inconvenient_ for the Python community. Foremost among
them would be that no plain-text tool would work with xml'zed Python.

Has the subject been discussed in the Python community? If so, where? I
suspect this is a bad (or cumbersome) idea, but I'd like to be sure :)
Thanks.

I'm not aware of it being discussed, but as far as I can tell,
it shouldn't be all that hard to do if you're willing to do some
work. Look at Section 19 in the Python Library Reference,
plus the parser writeup in 18.1 and marshal in 3.19 (the section
numbers change when the doc changes.)

You should be able to convert an XML format of your
design to an AST and compile it to bytecodes; likewise
you should be able to generate an XML file from the AST.

The only thing that seems to be missing is a routine to actually
build a .pyc or .pyo file. I'm not sure how much work that
would be, but you might get some clues from 18.10 - dis
(the python disassembler)

While I'm quite skeptical of the utility of XML as a
programming language format, your reference 2 does
make some interesting points. You might also check
out the IO language, where the parse tree is the definitive
form of the language, and the actual text form is represented
as only one way to do it.

As innumerable project managers have discovered,
the best way to find the *real* requirements is to get
something out there and find out what real users say
about it.

John Roth
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Edward said:
I am wondering whether that has been any discussion of a project like the
following in the Python world:

- jezix http://www.tel.fer.hr/users/mtopol/jezix/
- javaml http://sourceforge.net/projects/javaml/

The general idea is that it would sometimes be nice to be able to feed xml
to the Python parser instead of plain text.

This comes up every now and then on the XML SIG, and the responses are
typically reserved. I tend to respond with two observations:
1. What advantage would you get?
2. How exactly should the XML look like? The simplest approach I can
think of is

<python>
def test():
"""Test this module.

A hodge podge of tests collected here, because they have too many
external dependencies for the regular test suite.
"""

import sys
import getopt
opts, args = getopt.getopt(sys.argv[1:], 'd')
dl = 0
for o, a in opts:
if o == '-d': dl = dl + 1
host = 'www.python.org'
</python>

Nice XML; if you use CDATA sections, you don't even need to markup
less-than characters.

Regards,
Martin
 
E

Edward K. Ream

1. What advantage would you get?

Lately there has been discussion in Leo's forums about various different
ways of having Leo represent structure in source files. At present Leo uses
so-called "sentinel" lines, comment lines of the form #@<data>. An xml
format would make embedding structure very easy. OTOH, xml is less readable
than sentinels, and some of Leo's users (or their managers) dislike
sentinels, so arguably xml is a step backwards.

As an alternative, there have been some proposals to separate structure from
content in two separate files. The idea is to script cvs so that the two
files (the content and the structure) are always committed and updated in
synch. All this is blue-sky musing at present.
2. How exactly should the XML look like?

A good question. One thing I didn't say in my original post was that I
envision one would have all sorts of problems deciding on what pythonMl (or
leoPyMl) would be. The situation is a similar to the discussions about
document formats. I suppose one could propose an extensible format: the
Python compiler would ignore the extensions...
The simplest approach I can think of is...

This might sometimes be useful because one could add "annotation" attributes
to the <python> element. Like <python "font="> (or use a style sheet).
However, Leo would probably need more complicated markup, and naturally that
isn't a general approach.

In short, I agree with you, Martin; my first and second responses to this
idea are "reserved". Thanks for taking the time to reply :)

Edward
 
E

Edward K. Ream

You should be able to convert an XML format of your
design to an AST and compile it to bytecodes; likewise
you should be able to generate an XML file from the AST.

Thanks, John. This is a valuable suggestion because it points in a
direction that doesn't require the assent (or participation) of the wider
Python community. As I just said in my reply to Martin, I am pretty dubious
about the whole idea. I suspect though, that if the idea ever goes anywhere
something like what you suggest will be the way to go. I'll keep this
suggestion in the back of my mind...

Thanks again.

Edward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top