diff --git a/template.lime b/template.lime index 300749b..b68c635 100644 --- a/template.lime +++ b/template.lime @@ -81,21 +81,7 @@ # Директивы template = chunks { - $cs = $1; - $r = ''; - foreach ($cs as $a) - { - if (is_array($a)) - { - $r .= "\$t .= '".addcslashes($a[0], "'\\")."';\n"; - $this->template->track_dom($a[0], strlen($r)); - } - else - { - $r .= $a; - } - } - $this->template->st->functions['main']['body'] = "function fn_main() {\$stack = array();\n\$t = '';\n".$r."\nreturn \$t;\n}\n"; + $this->template->st->AST = $1; $$ = ''; } . @@ -103,95 +89,72 @@ chunks = { $$ = []; } | chunks chunk { - $$ = array_merge($1, $2); + $$ = $1; + if ($2) { + $$[] = $2; + } } . chunk = literal { - $$ = [ ($1 !== '' ? [ $1 ] : '') ]; + $$ = [ 'literal', $1 ]; } | "" { $$ = $c; } | "{{" exp/e "}}" { - $$ = [ '$t .= ' . ($e[1] || !$this->template->options->auto_escape ? $e[0] : $this->template->compile_function($this->template->options->auto_escape, [ $e ])[0]) . ";\n" ]; + $$ = [ 'subst', $e ]; } | error/e { - $$ = []; + $$ = false; } . code_chunk = c_if/$ | c_set/$ | c_fn/$ | c_for/$ | exp/e { - $$ = [ '$t .= ' . ($e[1] || !$this->template->options->auto_escape ? $e[0] : $this->template->compile_function($this->template->options->auto_escape, [ $e ])[0]) . ";\n" ]; + $$ = [ 'subst', $e ]; } . c_if = "IF" exp/e "-->" chunks/if "" chunks/if "" chunks/else "" chunks/if c_elseifs/ei chunks/ec "" chunks/if c_elseifs/ei chunks/ec "" chunks/else "" { - $$ = [ "} elseif (" . $e[0] . ") {\n" ]; + $$ = [ [ $e ] ]; } | c_elseifs/p chunks/cs "" { - $$ = array_merge($p, $cs, [ "} elseif (" . $e[0] . ") {\n" ]); + $$ = $p; + $$[count($$)-1][] = $cs; + $$[] = [ $e ]; } . c_set = "SET" varref/v "=" exp/e { - $$ = [ $v[0] . ' = ' . $e[0] . ";\n" ]; + $$ = [ 'set', $v, [ 'subst', $e ] ]; } | "SET" varref/v "-->" chunks/cs "" chunks/cs "" chunks/cs " selected="selected">{o.name} +{v.end('x', 'y')['z'].begin()}