Smarty: Improved tokenization (#3268)

This commit is contained in:
Michael Schmidt 2021-12-18 13:19:36 +01:00 committed by GitHub
parent 7bcc5da08f
commit acc0bc0944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 885 additions and 140 deletions

File diff suppressed because one or more lines are too long

View File

@ -1219,6 +1219,7 @@
"smarty": {
"title": "Smarty",
"require": "markup-templating",
"optional": "php",
"owner": "Golmote"
},
"sml": {

View File

@ -1,23 +1,67 @@
/* TODO
Add support for variables inside double quoted strings
Add support for {php}
*/
(function (Prism) {
Prism.languages.smarty = {
'comment': /\{\*[\s\S]*?\*\}/,
'comment': {
pattern: /^\{\*[\s\S]*?\*\}/,
greedy: true
},
'embedded-php': {
pattern: /^\{php\}[\s\S]*?\{\/php\}/,
greedy: true,
inside: {
'smarty': {
pattern: /^\{php\}|\{\/php\}$/,
inside: null // see below
},
'php': {
pattern: /[\s\S]+/,
alias: 'language-php',
inside: Prism.languages.php
}
}
},
'string': [
{
pattern: /"(?:\\.|[^"\\\r\n])*"/,
greedy: true,
inside: {
'interpolation': {
pattern: /\{[^{}]*\}|`[^`]*`/,
inside: {
'interpolation-punctuation': {
pattern: /^[{`]|[`}]$/,
alias: 'punctuation'
},
'expression': {
pattern: /[\s\S]+/,
inside: null // see below
}
}
},
'variable': /\$\w+/
}
},
{
pattern: /'(?:\\.|[^'\\\r\n])*'/,
greedy: true
},
],
'keyword': {
pattern: /(^\{\/?)[a-z_]\w*\b(?!\()/i,
lookbehind: true,
greedy: true
},
'delimiter': {
pattern: /^\{|\}$/,
pattern: /^\{\/?|\}$/,
greedy: true,
alias: 'punctuation'
},
'string': /(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,
'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/,
'variable': [
/\$(?!\d)\w+/,
/#(?!\d)\w+#/,
{
pattern: /(\.|->)(?!\d)\w+/,
pattern: /(\.|->|\w\s*=)(?!\d)\w+\b(?!\()/,
lookbehind: true
},
{
@ -25,52 +69,52 @@
lookbehind: true
}
],
'function': [
{
pattern: /(\|\s*)@?(?!\d)\w+/,
lookbehind: true
},
/^\/?(?!\d)\w+/,
/(?!\d)\w+(?=\()/
],
'attr-name': {
// Value is made optional because it may have already been tokenized
pattern: /\w+\s*=\s*(?:(?!\d)\w+)?/,
inside: {
'variable': {
pattern: /(=\s*)(?!\d)\w+/,
lookbehind: true
},
'operator': /=/
}
'function': {
pattern: /(\|\s*)@?[a-z_]\w*|\b[a-z_]\w*(?=\()/i,
lookbehind: true
},
'punctuation': [
/[\[\]().,:`]|->/
],
'attr-name': /\b[a-z_]\w*(?=\s*=)/i,
'boolean': /\b(?:false|no|off|on|true|yes)\b/,
'punctuation': /[\[\](){}.,:`]|->/,
'operator': [
/[+\-*\/%]|==?=?|[!<>]=?|&&|\|\|?/,
/\bis\s+(?:not\s+)?(?:div|even|odd)(?:\s+by)?\b/,
/\b(?:and|eq|gt?e|gt|lt?e|lt|mod|neq?|not|or)\b/
],
'keyword': /\b(?:false|no|off|on|true|yes)\b/
]
};
Prism.languages.smarty['embedded-php'].inside.smarty.inside = Prism.languages.smarty;
Prism.languages.smarty.string[0].inside.interpolation.inside.expression.inside = Prism.languages.smarty;
var string = /"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'/;
var smartyPattern = RegExp(
// comments
/\{\*[\s\S]*?\*\}/.source +
'|' +
// php tags
/\{php\}[\s\S]*?\{\/php\}/.source +
'|' +
// smarty blocks
/\{(?:[^{}"']|<str>|\{(?:[^{}"']|<str>|\{(?:[^{}"']|<str>)*\})*\})*\}/.source
.replace(/<str>/g, function () { return string.source; }),
'g'
);
// Tokenize all inline Smarty expressions
Prism.hooks.add('before-tokenize', function (env) {
var smartyPattern = /\{\*[\s\S]*?\*\}|\{[\s\S]+?\}/g;
var smartyLitteralStart = '{literal}';
var smartyLitteralEnd = '{/literal}';
var smartyLitteralMode = false;
var smartyLiteralStart = '{literal}';
var smartyLiteralEnd = '{/literal}';
var smartyLiteralMode = false;
Prism.languages['markup-templating'].buildPlaceholders(env, 'smarty', smartyPattern, function (match) {
// Smarty tags inside {literal} block are ignored
if (match === smartyLitteralEnd) {
smartyLitteralMode = false;
if (match === smartyLiteralEnd) {
smartyLiteralMode = false;
}
if (!smartyLitteralMode) {
if (match === smartyLitteralStart) {
smartyLitteralMode = true;
if (!smartyLiteralMode) {
if (match === smartyLiteralStart) {
smartyLiteralMode = true;
}
return true;

View File

@ -1 +1 @@
!function(n){n.languages.smarty={comment:/\{\*[\s\S]*?\*\}/,delimiter:{pattern:/^\{|\}$/,alias:"punctuation"},string:/(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,number:/\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/,variable:[/\$(?!\d)\w+/,/#(?!\d)\w+#/,{pattern:/(\.|->)(?!\d)\w+/,lookbehind:!0},{pattern:/(\[)(?!\d)\w+(?=\])/,lookbehind:!0}],function:[{pattern:/(\|\s*)@?(?!\d)\w+/,lookbehind:!0},/^\/?(?!\d)\w+/,/(?!\d)\w+(?=\()/],"attr-name":{pattern:/\w+\s*=\s*(?:(?!\d)\w+)?/,inside:{variable:{pattern:/(=\s*)(?!\d)\w+/,lookbehind:!0},operator:/=/}},punctuation:[/[\[\]().,:`]|->/],operator:[/[+\-*\/%]|==?=?|[!<>]=?|&&|\|\|?/,/\bis\s+(?:not\s+)?(?:div|even|odd)(?:\s+by)?\b/,/\b(?:and|eq|gt?e|gt|lt?e|lt|mod|neq?|not|or)\b/],keyword:/\b(?:false|no|off|on|true|yes)\b/},n.hooks.add("before-tokenize",function(e){var t=!1;n.languages["markup-templating"].buildPlaceholders(e,"smarty",/\{\*[\s\S]*?\*\}|\{[\s\S]+?\}/g,function(e){return"{/literal}"===e&&(t=!1),!t&&("{literal}"===e&&(t=!0),!0)})}),n.hooks.add("after-tokenize",function(e){n.languages["markup-templating"].tokenizePlaceholders(e,"smarty")})}(Prism);
!function(t){t.languages.smarty={comment:{pattern:/^\{\*[\s\S]*?\*\}/,greedy:!0},"embedded-php":{pattern:/^\{php\}[\s\S]*?\{\/php\}/,greedy:!0,inside:{smarty:{pattern:/^\{php\}|\{\/php\}$/,inside:null},php:{pattern:/[\s\S]+/,alias:"language-php",inside:t.languages.php}}},string:[{pattern:/"(?:\\.|[^"\\\r\n])*"/,greedy:!0,inside:{interpolation:{pattern:/\{[^{}]*\}|`[^`]*`/,inside:{"interpolation-punctuation":{pattern:/^[{`]|[`}]$/,alias:"punctuation"},expression:{pattern:/[\s\S]+/,inside:null}}},variable:/\$\w+/}},{pattern:/'(?:\\.|[^'\\\r\n])*'/,greedy:!0}],keyword:{pattern:/(^\{\/?)[a-z_]\w*\b(?!\()/i,lookbehind:!0,greedy:!0},delimiter:{pattern:/^\{\/?|\}$/,greedy:!0,alias:"punctuation"},number:/\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/,variable:[/\$(?!\d)\w+/,/#(?!\d)\w+#/,{pattern:/(\.|->|\w\s*=)(?!\d)\w+\b(?!\()/,lookbehind:!0},{pattern:/(\[)(?!\d)\w+(?=\])/,lookbehind:!0}],function:{pattern:/(\|\s*)@?[a-z_]\w*|\b[a-z_]\w*(?=\()/i,lookbehind:!0},"attr-name":/\b[a-z_]\w*(?=\s*=)/i,boolean:/\b(?:false|no|off|on|true|yes)\b/,punctuation:/[\[\](){}.,:`]|->/,operator:[/[+\-*\/%]|==?=?|[!<>]=?|&&|\|\|?/,/\bis\s+(?:not\s+)?(?:div|even|odd)(?:\s+by)?\b/,/\b(?:and|eq|gt?e|gt|lt?e|lt|mod|neq?|not|or)\b/]},t.languages.smarty["embedded-php"].inside.smarty.inside=t.languages.smarty,t.languages.smarty.string[0].inside.interpolation.inside.expression.inside=t.languages.smarty;var e=/"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'/,a=RegExp("\\{\\*[^]*?\\*\\}|\\{php\\}[^]*?\\{/php\\}|"+"\\{(?:[^{}\"']|<str>|\\{(?:[^{}\"']|<str>|\\{(?:[^{}\"']|<str>)*\\})*\\})*\\}".replace(/<str>/g,function(){return e.source}),"g");t.hooks.add("before-tokenize",function(e){var n=!1;t.languages["markup-templating"].buildPlaceholders(e,"smarty",a,function(e){return"{/literal}"===e&&(n=!1),!n&&("{literal}"===e&&(n=!0),!0)})}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"smarty")})}(Prism);

View File

@ -0,0 +1,121 @@
{php}
// including a php script directly from the template.
include('/path/to/display_weather.php');
{/php}
{* this template includes a {php} block that assign's the variable $varX *}
{php}
global $foo, $bar;
if($foo == $bar){
echo 'This will be sent to browser';
}
// assign a variable to Smarty
$this->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong> is my fav ice cream :-)
----------------------------------------------------
[
["smarty", [
["embedded-php", [
["smarty", [
["delimiter", "{"],
["keyword", "php"],
["delimiter", "}"]
]],
["php", [
["comment", "// including a php script directly from the template."],
["keyword", "include"],
["punctuation", "("],
["string", "'/path/to/display_weather.php'"],
["punctuation", ")"],
["punctuation", ";"]
]],
["smarty", [
["delimiter", "{/"],
["keyword", "php"],
["delimiter", "}"]
]]
]]
]],
["smarty", [
["comment", "{* this template includes a {php} block that assign's the variable $varX *}"]
]],
["smarty", [
["embedded-php", [
["smarty", [
["delimiter", "{"],
["keyword", "php"],
["delimiter", "}"]
]],
["php", [
["keyword", "global"],
["variable", "$foo"],
["punctuation", ","],
["variable", "$bar"],
["punctuation", ";"],
["keyword", "if"],
["punctuation", "("],
["variable", "$foo"],
["operator", "=="],
["variable", "$bar"],
["punctuation", ")"],
["punctuation", "{"],
["keyword", "echo"],
["string", "'This will be sent to browser'"],
["punctuation", ";"],
["punctuation", "}"],
["comment", "// assign a variable to Smarty"],
["variable", "$this"],
["operator", "->"],
["function", ["assign"]],
["punctuation", "("],
["string", "'varX'"],
["punctuation", ","],
["string", "'Toffee'"],
["punctuation", ")"],
["punctuation", ";"]
]],
["smarty", [
["delimiter", "{/"],
["keyword", "php"],
["delimiter", "}"]
]]
]]
]],
["smarty", [
["comment", "{* output the variable *}"]
]],
["tag", [
["tag", [
["punctuation", "<"],
"strong"
]],
["punctuation", ">"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$varX"],
["delimiter", "}"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"strong"
]],
["punctuation", ">"]
]],
" is my fav ice cream :-)"
]

View File

@ -6,26 +6,20 @@
[
["smarty", [
["delimiter", "{"],
["function", "assign"],
["attr-name", [
"var",
["operator", "="],
["variable", "foo"]
]],
["attr-name", [
"value",
["operator", "="]
]],
["string", "\"bar\""],
["keyword", "assign"],
["attr-name", "var"],
["operator", "="],
["variable", "foo"],
["attr-name", "value"],
["operator", "="],
["string", ["\"bar\""]],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "foo"],
["attr-name", [
"bar ",
["operator", "="]
]],
["keyword", "foo"],
["attr-name", "bar"],
["operator", "="],
["number", "40"],
["delimiter", "}"]
]]
@ -33,4 +27,4 @@
----------------------------------------------------
Checks for attributes.
Checks for attributes.

View File

@ -0,0 +1,51 @@
{if false}
{if off}
{if on}
{if no}
{if true}
{if yes}
----------------------------------------------------
[
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["boolean", "false"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["boolean", "off"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["boolean", "on"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["boolean", "no"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["boolean", "true"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["boolean", "yes"],
["delimiter", "}"]
]]
]
----------------------------------------------------
Checks for keywords.

View File

@ -2,13 +2,29 @@
{* foo
bar *}
{* you cannot nest comments *}
{* {* foo *} *}
----------------------------------------------------
[
["smarty", [["comment", "{**}"]]],
["smarty", [["comment", "{* foo\r\nbar *}"]]]
["smarty", [
["comment", "{**}"]
]],
["smarty", [
["comment", "{* foo\r\nbar *}"]
]],
["smarty", [
["comment", "{* you cannot nest comments *}"]
]],
["smarty", [
["comment", "{* {* foo *}"]
]],
" *}"
]
----------------------------------------------------
Checks for comments.
Checks for comments.

View File

@ -8,7 +8,7 @@
[
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["function", "count"],
["punctuation", "("],
["variable", "$foo"],
@ -30,12 +30,12 @@
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "/if"],
["delimiter", "{/"],
["keyword", "if"],
["delimiter", "}"]
]]
]
----------------------------------------------------
Checks for tags, filters and functions.
Checks for tags, filters and functions.

View File

@ -1,51 +1,35 @@
{if false}
{if off}
{if on}
{if no}
{if true}
{if yes}
----------------------------------------------------
[
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "false"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "off"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "on"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "no"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "true"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "yes"],
["delimiter", "}"]
]]
]
----------------------------------------------------
Checks for keywords.
{if count($foo)}
{/if}
{* PHP function *}
{time()}
----------------------------------------------------
[
["smarty", [
["delimiter", "{"],
["keyword", "if"],
["function", "count"],
["punctuation", "("],
["variable", "$foo"],
["punctuation", ")"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{/"],
["keyword", "if"],
["delimiter", "}"]
]],
["smarty", [
["comment", "{* PHP function *}"]
]],
["smarty", [
["delimiter", "{"],
["function", "time"],
["punctuation", "("],
["punctuation", ")"],
["delimiter", "}"]
]]
]

View File

@ -17,7 +17,7 @@
[
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$a"],
["operator", "+"],
["variable", "$b"],
@ -29,7 +29,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$e"],
["operator", "*"],
["variable", "$f"],
@ -43,7 +43,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$j"],
["operator", "<"],
["variable", "$k"],
@ -63,7 +63,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["operator", "!"],
["variable", "$r"],
["operator", "!="],
@ -76,7 +76,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$v"],
["operator", "is not even by"],
["number", "3"],
@ -87,7 +87,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$w"],
["operator", "is div by"],
["number", "2"],
@ -99,7 +99,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$x"],
["operator", "is not odd"],
["operator", "or"],
@ -110,7 +110,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$y"],
["operator", "ne"],
["variable", "$z"],
@ -122,7 +122,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$c"],
["operator", "gt"],
["variable", "$d"],
@ -134,7 +134,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["variable", "$g"],
["operator", "gte"],
["variable", "$h"],
@ -154,7 +154,7 @@
]],
["smarty", [
["delimiter", "{"],
["function", "if"],
["keyword", "if"],
["operator", "not"],
["variable", "$o"],
["operator", "and"],
@ -165,12 +165,10 @@
]],
["smarty", [
["delimiter", "{"],
["function", "foo"],
["attr-name", [
"bar",
["operator", "="],
["variable", "baz"]
]],
["keyword", "foo"],
["attr-name", "bar"],
["operator", "="],
["variable", "baz"],
["delimiter", "}"]
]],
["smarty", [
@ -184,4 +182,4 @@
----------------------------------------------------
Checks for all operators.
Checks for all operators.

View File

@ -0,0 +1,81 @@
{php}
// including a php script directly from the template.
include('/path/to/display_weather.php');
{/php}
{* this template includes a {php} block that assign's the variable $varX *}
{php}
global $foo, $bar;
if($foo == $bar){
echo 'This will be sent to browser';
}
// assign a variable to Smarty
$this->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong> is my fav ice cream :-)
----------------------------------------------------
[
["smarty", [
["embedded-php", [
["smarty", [
["delimiter", "{"],
["keyword", "php"],
["delimiter", "}"]
]],
["php", "\r\n // including a php script directly from the template.\r\n include('/path/to/display_weather.php');\r\n"],
["smarty", [
["delimiter", "{/"],
["keyword", "php"],
["delimiter", "}"]
]]
]]
]],
["smarty", [
["comment", "{* this template includes a {php} block that assign's the variable $varX *}"]
]],
["smarty", [
["embedded-php", [
["smarty", [
["delimiter", "{"],
["keyword", "php"],
["delimiter", "}"]
]],
["php", "\r\n global $foo, $bar;\r\n if($foo == $bar){\r\n echo 'This will be sent to browser';\r\n }\r\n // assign a variable to Smarty\r\n $this->assign('varX','Toffee');\r\n"],
["smarty", [
["delimiter", "{/"],
["keyword", "php"],
["delimiter", "}"]
]]
]]
]],
["smarty", [
["comment", "{* output the variable *}"]
]],
["tag", [
["tag", [
["punctuation", "<"],
"strong"
]],
["punctuation", ">"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$varX"],
["delimiter", "}"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"strong"
]],
["punctuation", ">"]
]],
" is my fav ice cream :-)"
]

View File

@ -0,0 +1,33 @@
{foo
( ) [ ] { }
. : ,
`
->
}
----------------------------------------------------
[
["smarty", [
["delimiter", "{"], ["keyword", "foo"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],
["punctuation", "."],
["punctuation", ":"],
["punctuation", ","],
["punctuation", "`"],
["punctuation", "->"],
["delimiter", "}"]
]]
]

View File

@ -2,18 +2,45 @@
{"fo\"obar"}
{''}
{'fo\'obar'}
{$foo="this is message {counter}"}
{func var="test $foo test"} // sees $foo
{func var="test $foo_bar test"} // sees $foo_bar
{func var="test `$foo[0]` test"} // sees $foo[0]
{func var="test `$foo[bar]` test"} // sees $foo[bar]
{func var="test $foo.bar test"} // sees $foo (not $foo.bar)
{func var="test `$foo.bar` test"} // sees $foo.bar
{func var="test `$foo.bar` test"|escape} // modifiers outside quotes!
{func var="test {$foo|escape} test"} // modifiers inside quotes!
{func var="test {time()} test"} // PHP function result
{func var="test {counter} test"} // plugin result
{* will replace $tpl_name with value *}
{include file="subdir/$tpl_name.tpl"}
{* does NOT replace $tpl_name *}
{include file='subdir/$tpl_name.tpl'} // vars require double quotes!
{* must have backticks as it contains a dot "." *}
{cycle values="one,two,`$smarty.config.myval`"}
{* must have backticks as it contains a dot "." *}
{include file="`$module.contact`.tpl"}
{* can use variable with dot syntax *}
{include file="`$module.$view`.tpl"}
----------------------------------------------------
[
["smarty", [
["delimiter", "{"],
["string", "\"\""],
["string", ["\"\""]],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["string", "\"fo\\\"obar\""],
["string", ["\"fo\\\"obar\""]],
["delimiter", "}"]
]],
["smarty", [
@ -25,9 +52,324 @@
["delimiter", "{"],
["string", "'fo\\'obar'"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["operator", "="],
["string", [
"\"this is message ",
["interpolation", [
["interpolation-punctuation", "{"],
["expression", ["counter"]],
["interpolation-punctuation", "}"]
]],
"\""
]],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["variable", "$foo"],
" test\""
]],
["delimiter", "}"]
]],
" // sees $foo\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["variable", "$foo_bar"],
" test\""
]],
["delimiter", "}"]
]],
" // sees $foo_bar\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$foo"],
["punctuation", "["],
["number", "0"],
["punctuation", "]"]
]],
["interpolation-punctuation", "`"]
]],
" test\""
]],
["delimiter", "}"]
]],
" // sees $foo[0]\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$foo"],
["punctuation", "["],
["variable", "bar"],
["punctuation", "]"]
]],
["interpolation-punctuation", "`"]
]],
" test\""
]],
["delimiter", "}"]
]],
" // sees $foo[bar]\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["variable", "$foo"],
".bar test\""
]],
["delimiter", "}"]
]],
" // sees $foo (not $foo.bar)\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$foo"],
["punctuation", "."],
["variable", "bar"]
]],
["interpolation-punctuation", "`"]
]],
" test\""
]],
["delimiter", "}"]
]],
" // sees $foo.bar\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$foo"],
["punctuation", "."],
["variable", "bar"]
]],
["interpolation-punctuation", "`"]
]],
" test\""
]],
["operator", "|"],
["function", "escape"],
["delimiter", "}"]
]],
" // modifiers outside quotes!\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "{"],
["expression", [
["variable", "$foo"],
["operator", "|"],
["function", "escape"]
]],
["interpolation-punctuation", "}"]
]],
" test\""
]],
["delimiter", "}"]
]],
" // modifiers inside quotes!\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "{"],
["expression", [
["function", "time"],
["punctuation", "("],
["punctuation", ")"]
]],
["interpolation-punctuation", "}"]
]],
" test\""
]],
["delimiter", "}"]
]],
" // PHP function result\r\n",
["smarty", [
["delimiter", "{"],
["keyword", "func"],
["attr-name", "var"],
["operator", "="],
["string", [
"\"test ",
["interpolation", [
["interpolation-punctuation", "{"],
["expression", ["counter"]],
["interpolation-punctuation", "}"]
]],
" test\""
]],
["delimiter", "}"]
]],
" // plugin result\r\n\r\n",
["smarty", [
["comment", "{* will replace $tpl_name with value *}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "include"],
["attr-name", "file"],
["operator", "="],
["string", [
"\"subdir/",
["variable", "$tpl_name"],
".tpl\""
]],
["delimiter", "}"]
]],
["smarty", [
["comment", "{* does NOT replace $tpl_name *}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "include"],
["attr-name", "file"],
["operator", "="],
["string", "'subdir/$tpl_name.tpl'"],
["delimiter", "}"]
]],
" // vars require double quotes!\r\n\r\n",
["smarty", [
["comment", "{* must have backticks as it contains a dot \".\" *}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "cycle"],
["attr-name", "values"],
["operator", "="],
["string", [
"\"one,two,",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$smarty"],
["punctuation", "."],
["variable", "config"],
["punctuation", "."],
["variable", "myval"]
]],
["interpolation-punctuation", "`"]
]],
"\""
]],
["delimiter", "}"]
]],
["smarty", [
["comment", "{* must have backticks as it contains a dot \".\" *}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "include"],
["attr-name", "file"],
["operator", "="],
["string", [
"\"",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$module"],
["punctuation", "."],
["variable", "contact"]
]],
["interpolation-punctuation", "`"]
]],
".tpl\""
]],
["delimiter", "}"]
]],
["smarty", [
["comment", "{* can use variable with dot syntax *}"]
]],
["smarty", [
["delimiter", "{"],
["keyword", "include"],
["attr-name", "file"],
["operator", "="],
["string", [
"\"",
["interpolation", [
["interpolation-punctuation", "`"],
["expression", [
["variable", "$module"],
["punctuation", "."],
["variable", "$view"]
]],
["interpolation-punctuation", "`"]
]],
".tpl\""
]],
["delimiter", "}"]
]]
]
----------------------------------------------------
Checks for strings.
Checks for strings.

View File

@ -4,6 +4,12 @@
{$foo.bar.baz}
{$foo->bar->baz}
{$foo[row]}
{$foo[$x+$x]}
{$foo.a.$b.c}
{$foo.a.{$b+4}.c}
{$foo.a.{$b.c}}
{$foo={counter}+3}
{$foo->bar($baz,2,$bar)}
----------------------------------------------------
@ -48,9 +54,83 @@
["variable", "row"],
["punctuation", "]"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["punctuation", "["],
["variable", "$x"],
["operator", "+"],
["variable", "$x"],
["punctuation", "]"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["punctuation", "."],
["variable", "a"],
["punctuation", "."],
["variable", "$b"],
["punctuation", "."],
["variable", "c"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["punctuation", "."],
["variable", "a"],
["punctuation", "."],
["punctuation", "{"],
["variable", "$b"],
["operator", "+"],
["number", "4"],
["punctuation", "}"],
["punctuation", "."],
["variable", "c"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["punctuation", "."],
["variable", "a"],
["punctuation", "."],
["punctuation", "{"],
["variable", "$b"],
["punctuation", "."],
["variable", "c"],
["punctuation", "}"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["operator", "="],
["punctuation", "{"],
"counter",
["punctuation", "}"],
["operator", "+"],
["number", "3"],
["delimiter", "}"]
]],
["smarty", [
["delimiter", "{"],
["variable", "$foo"],
["punctuation", "->"],
["function", "bar"],
["punctuation", "("],
["variable", "$baz"],
["punctuation", ","],
["number", "2"],
["punctuation", ","],
["variable", "$bar"],
["punctuation", ")"],
["delimiter", "}"]
]]
]
----------------------------------------------------
Checks for variables.
Checks for variables.