5

What template engines / template languages are turing complete? I heard about these so far:

  • FreeMarker (implemented in java)
  • MovableTypes template language (in perl)
  • xslt :-(
  • Cheetah (in Python)
  • Smarty (in PHP)

Any others (especially implemented with perl)?

Ps: Don't waste time with clarifying me MVC, and why turing complete templates are bad, and why this is not a useful comparison point :)

sawa
  • 165,429
  • 45
  • 277
  • 381
clt60
  • 62,119
  • 17
  • 107
  • 194

4 Answers4

3

eRuby lets you embed arbitrary Ruby into your templates:

$ echo "Hello <%= 'dlrow'.reverse() %> from eRuby" | erb
Hello world from eRuby
sarnold
  • 102,305
  • 22
  • 181
  • 238
3

Perl's Template::Toolkit allows for inlining of Perl if the EVAL_PERL flag is set. Within the template, PERL and RAWPERL blocks allow inlining, to the extent (in the case of RAWPERL) that the internals are exposed, and inlined code is evaluated through eval() (the quoted eval). This provides full access to the Perl interpreter.

Perl is itself considered to have a Turing Complete grammar. So given that Template::Toolkit does provide access to Perl itself, the templating system inherits that characteristic.

Though setting EVAL_PERL to allow for inlined Perl within a template is considered an advanced (and presumably seldom-used) feature, it is available for the strong-hearted (and questionably-sane).

DavidO
  • 13,812
  • 3
  • 38
  • 66
  • 1
    Template::Toolkit looks close to Turing-complete by itself to me. I cannot prove or disprove that right now, but having `[%while%]` and `[%set something = "$some$thing"%]` looks suspicious for me. At least I could solve (small) prime numbers. – Dallaylaen Jun 15 '11 at 06:40
  • Never underestimate the power of CPAN. – DavidO Jun 15 '11 at 07:05
  • 1
    In fact, I managed to get it to work on large numbers and it says `undef error - WHILE loop terminated (> 1000 iterations)`. So looks like it's artifically prevented from being TC. – Dallaylaen Jun 15 '11 at 07:12
0

Virtually anything that allows procedural code to compute the template result.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
0

Most meta-programming language features support arbitrary evaluation and splicing of code into a running program. Thus most support Turing-complete computations as part of execution of the splices and substitution.

On the other end, simple string interpolation meta-programming systems are usually heavily restricted (no recursion, for example).

Community
  • 1
  • 1
Don Stewart
  • 137,316
  • 36
  • 365
  • 468