Optional algol syntax style

S

Sokolov Yura

I think, allowing to specify blocks with algol style (for-end, if-end,
etc) will allow to write easy php-like templates
and would attract new web developers to python (as php and ruby do).
It can be straight compilled into Python bytecode cause there is
one-to-one transformation.
So this:
# -*- syntax-style: algol -*-
class asd:
def __init__(self,a):
if a:
for i in xrange(100):
pass
else:
while false:
pass
else:
pass
end
end
else:
self.a=None
end
end
end
is equivalent for:
class asd:
def __init__(self,a):
if a:
for i in xrange(100):
pass
else:
while false:
pass
else:
pass
else:
self.a=None
but could be written as:

# -*- syntax-style: algol -*-
class asd: def __init__(self,a): if a: for i in xrange(100): pass; else:
while false: pass; else: pass; end; end; end; end;

which is easier to embed into http template (php and ruby shows it).

And, maybe, there can web syntax - equivalent for php and ruby template:
<%# -*- syntax: web -*-%>
<%# -*- command: print -*- %>
<%
def print_all(l):%>
<table><%
for k in l:%>
<tr><td>#{k.name}</td><td>#{k.surname}</td></tr>
<%end%>
</table>
<%end
# -*- command: yield -*-
def yield_all(l):%>
<table><%
for k in l:%>
<tr><td>#{k.name}</td><td>#{k.surname}</td></tr>
<%end%>
</table>
<%end
# -*- command: S.write -*-
def write_all(S,l):%>
<table><%
for k in l:%>
<tr><td>#{k.name}</td><td>#{k.surname}</td></tr>
<%end%>
</table>
<%end%>

will be translated as it were written:
def print_all(l):
print (r"<table>")
for k in l:
print (r"<tr><td>"+`k.name`+ r"</td><td>"+`k.surname`+ r"</td></tr>")
# or print (r"<tr><td>"+str(k.name)+ r"</td><td>"+str(k.surname)+
r"</td></tr>")
print (r"</table>")
def yield_all(l):
yield (r"<table>")
for k in l:
yield (r"<tr><td>"+`k.name`+ r"</td><td>"+`k.surname`+ r"</td></tr>")
yield (r"</table>")
def write_all(S.l):
S.write (r"<table>")
for k in l:
S.write (r"<tr><td>"+`k.name`+ r"</td><td>"+`k.surname`+
r"</td></tr>")
S.write (r"</table>")

I offer to include it into iterpretter, so we can leave another
compilation stage, as it exists with popular
template libraries, which compile their template files into bytecode (or
python source)
 
M

Mikael Olofsson

Sokolov said:
I think, allowing to specify blocks with algol style (for-end, if-end,
etc) will allow to write easy php-like templates
and would attract new web developers to python (as php and ruby do).
It can be straight compilled into Python bytecode cause there is
one-to-one transformation.
> [snip details]

Standard answer to this kind of question:

You can already do that in Python. It's spelled #end.

/MiO
 
C

Christoph Rackwitz

You didn't quite get the OP's intention, I guess.

The OP wanted Python to be a bit more freeform by adding "end" tags.
That might be an improvement for web scripting, but I haven't seen the
solutions of the existing frameworks and won't dare to compare.
 
M

Mike Meyer

Christoph Rackwitz said:
You didn't quite get the OP's intention, I guess.

The OP wanted Python to be a bit more freeform by adding "end" tags.
That might be an improvement for web scripting, but I haven't seen the
solutions of the existing frameworks and won't dare to compare.

Existing frameworks (the one's I've looked at anyway) tend to replace
indents with end tags of some kind. Doing anything else tends to get
ugly unless the language you are templating for treats whitespace the
same way Python does.

I'd argue that you're better off using a real templating system than
trying to mangle Python into becoming a more acceptable templating
system. For templates, you tend to want to access multiple different
names spaces that are only vaguelly related to the Python contextual
name spaces. For example, you may want CGI (or whatever variables)
available directly in the template, rather than as
CGI["foobar"].value. However, you don't want them showing up in front
of your templat variables; you want to be able to say "add CGI
variables foo, bar and foobar to the current name space" in a short
manner.

Templating systems (well, the better ones, anyway) let you manipulate
those name spaces in ways you can't do in python. Cheeta and
ClearSilver come to mind as systems that will let you do this.

<mike
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top