Syntax ideas

2 views
Skip to first unread message

Rick Copeland

unread,
Mar 31, 2009, 5:59:55 PM3/31/09
to metapython
I was considering whether it would be preferable/possible to remove
the Jinja2 dependency in MetaPython. You could use macros and import-
time expressions "$(...)" to do nearly everything Jinja2 does inside a
defcode:... block. One outstanding issue, I suppose, is how to to
token pasting would work. Right now, the following creates a class
with a custom name:

defcode result:
class $name$Class:
pass

Maybe we could use $ as a token-paster (kind of like the C
preprocessor uses ##).

Also, if Jinja2 goes away, it might be nice to have some special
syntax for import-time control structures (if, while, and for) so
that, for instance,

?for x in [ 1, 2, 3 ]:
print x

Would yield :

print 1
print 2
print 3

Any thoughts?

Rick Copeland

unread,
Mar 31, 2009, 6:13:01 PM3/31/09
to metapython
Oh, by using $ as a token-paster, I meant that you could do the custom-
named class like this:

defcode result:
class ?(name)$Class:
pass

or even this:

defcode result:
class ?name$Class:
pass

Another idea is to change macros just a bit so that they're just
another case of an import-time construct. The macro caller would then
be responsible for specifying which arguments should be evaluated and
which should be passed "as-is" (by using the ${...} for as-is
arguments) Macros would just be compile-time expressions. So we'd
have

?<expr> - replaced with the result of evaluating the expr
?{...} - replaced with a code object containing the contained tokens

as well as import-time statements

?import, ?from...import
?for, ?if, ?while

What do you think?
Reply all
Reply to author
Forward
0 new messages