On 07/22/2011 06:04 PM, Stefan Behnel wrote:
Dag Sverre Seljebotn, 22.07.2011 17:49:
On 07/22/2011 05:46 PM, Dag Sverre Seljebotn wrote:
On 07/22/2011 03:07 PM, Stefan Behnel wrote:
Stefan Behnel, 22.07.2011 15:04:
Dag Sverre Seljebotn, 22.07.2011 13:54:
On 07/22/2011 01:10 PM, Stefan Behnel wrote:
I'm fine with using a template engine for the more involved cases
(which
are rare enough). However, I'd prefer not adding a new
dependency, but
just shipping a tiny single-module engine with Cython, e.g.
Templite or
pyratemp (just found them, never used them).

BTW, I don't think anybody is suggesting having an *external*
dependency
that users would need to go fetch themselves....that would be insane.

Sure. I also don't mind having a small engine in a package, but just
putting a single file in the source tree (and overwriting it with a
new
version at need) would be a perfectly small and nonintrusive addition.
And
given that there really are engines of that size (one file, <500
lines),
it's not so unrealistic either.

That being said, if you can recommend Tempita (which IMHO qualifies as
"small enough"), I won't object to it.

... although, isn't it unfortunate that it uses "{{...}}" for template
code? How well readable is that when used in C code?

At least in emacs, pretty much any template syntax will mess up things
pretty badly, especially automatic indentation and so on.

What I do is using mmm-mode, so that everything within {{ and }} is
highlighted with python-mode, and the rest with c-mode. I'll share my
configuration later.

I'm merely stating why this has never been an issue for me, I'm NOT
suggesting everyone should use emacs (or that plain text editing isn't
convenient); you do have a point.

Keep in mind that a syntax must work well with utility code written in
Cython as well.

OTOH one *might* want to have

code.put_tempita(..) # or similar

in Python code, and in that case plain text readability is very
important.

Of course, hacking Tempita to make it %[ ]% instead is a five minute job.
But I'm happy with any other engine that somebody have actually tried out
extensively.

Tempita has a syntax for comments - what about using the regular C and
Cython comments as template syntax delimiters? That way, you'd write

/*# some comment */

to get an actual comment in C code, and

/* for x in y */

for template code. For Cython code, we could use "##", or maybe "#<" and
">#". That should work pretty well with editors.

I really like the idea of making use of comments, but I don't think we should "overload" the C comments; both for human parsing and because it is helpful with comments in generated Cython code as well (at least I would like to see much more of that!)

For Cython code, this doesn't work well for inline expressions:

variable#<idx># = 34

So I propose

C: /*$  $*/

Cython: "$  $"

Or some other character than $ that we can have in common between C and Cython (! is taken by documentation systems, but : is an option...).

Using a string in Cython should play better with at least some syntax highlighters, and we can simply make sure to use ' for all actual strings.

Dag Sverre
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to