diff options
-rw-r--r-- | Transcompiler.php | 15 | ||||
-rw-r--r-- | docu/language_definition.html | 3 | ||||
-rw-r--r-- | tests/test_scoping/test.tpl | 16 | ||||
-rw-r--r-- | tests/test_scoping/want | 9 |
4 files changed, 41 insertions, 2 deletions
diff --git a/Transcompiler.php b/Transcompiler.php index b92663c..8f3213b 100644 --- a/Transcompiler.php +++ b/Transcompiler.php @@ -336,6 +336,21 @@ class Transcompiler { return $code; }, + "setlocal" => function($ast) { + if(empty($ast->params["var"])) { + throw new ParseCompileError("self::Transcompile Error: var missing in <ste:set>.", $ast->tpl, $ast->offset); + } + + $code = "\$outputstack[] = '';\n\$outputstack_i++;\n"; + $code .= self::_transcompile($ast->sub); + $code .= "\$outputstack_i--;\n"; + + list($val, $pre) = self::_transcompile($ast->params["var"], true); + $code .= $pre; + $code .= "\$ste->set_local_var(" . $val . ", array_pop(\$outputstack));\n"; + + return $code; + }, "get" => function($ast) { if(empty($ast->params["var"])) { throw new ParseCompileError("self::Transcompile Error: var missing in <ste:get>.", $ast->tpl, $ast->offset); diff --git a/docu/language_definition.html b/docu/language_definition.html index 84232de..a296395 100644 --- a/docu/language_definition.html +++ b/docu/language_definition.html @@ -445,6 +445,9 @@ <code><pre><ste:set var="temp"><ste:foo /></ste:set><br /><ste:bar baz="$temp" /></pre></code> </p> + <h3 id="builtin_setlocal">ste:set</h3> + <p>ste:setlocal is used like <a href="#builtin_set">ste:set</a>, but only a local variable will be set (ste:set would overwrite a variable, if it was declared in a parent scope). + <h3 id="builtin_get">ste:get</h3> <p>ste:get will return the content of a variable. The parameter <code>var</code> takes the name of the variable to get. Useful, if you want to get a variable which name is stored in a variable.</p> <p> diff --git a/tests/test_scoping/test.tpl b/tests/test_scoping/test.tpl index 25a46e7..e8a5cf2 100644 --- a/tests/test_scoping/test.tpl +++ b/tests/test_scoping/test.tpl @@ -1,6 +1,18 @@ +<ste:set var="a">A</ste:set> +<ste:set var="b">B</ste:set> <ste:mktag name="foo"> - <ste:set var="bla">!</ste:set> + in foo: \$a = $a + in foo: \$b = $b + in foo: \$c = $c + <ste:set var="a">X</ste:set> + <ste:setlocal var="b">Y</ste:setlocal> + <ste:set var="c">Z</ste:set> + in foo (after set): \$a = $a + in foo (after set): \$b = $b + in foo (after set): \$c = $c </ste:mktag> <ste:foo /> -$bla
\ No newline at end of file +\$a = $a +\$b = $b +\$c = $c
\ No newline at end of file diff --git a/tests/test_scoping/want b/tests/test_scoping/want index e69de29..6e7a154 100644 --- a/tests/test_scoping/want +++ b/tests/test_scoping/want @@ -0,0 +1,9 @@ +in foo: $a = A +in foo: $b = B +in foo: $c = +in foo (after set): $a = X +in foo (after set): $b = Y +in foo (after set): $c = Z +$a = X +$b = B +$c = |