Skip to content

Commit e03a7c2

Browse files
authoredDec 7, 2021
Twig: Improved tokenization (#3259)
1 parent 21a3c2d commit e03a7c2

14 files changed

+576
-270
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@
13501350
},
13511351
"twig": {
13521352
"title": "Twig",
1353-
"require": "markup",
1353+
"require": "markup-templating",
13541354
"owner": "brandonkelly"
13551355
},
13561356
"typescript": {

‎components/prism-twig.js

+38-40
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
Prism.languages.twig = {
2-
'comment': /\{#[\s\S]*?#\}/,
3-
'tag': {
4-
pattern: /\{\{[\s\S]*?\}\}|\{%[\s\S]*?%\}/,
2+
'comment': /^\{#[\s\S]*?#\}$/,
3+
4+
'tag-name': {
5+
pattern: /(^\{%-?\s*)\w+/,
6+
lookbehind: true,
7+
alias: 'keyword'
8+
},
9+
'delimiter': {
10+
pattern: /^\{[{%]-?|-?[%}]\}$/,
11+
alias: 'punctuation'
12+
},
13+
14+
'string': {
15+
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
516
inside: {
6-
'ld': {
7-
pattern: /^(?:\{\{-?|\{%-?\s*\w+)/,
8-
inside: {
9-
'punctuation': /^(?:\{\{|\{%)-?/,
10-
'keyword': /\w+/
11-
}
12-
},
13-
'rd': {
14-
pattern: /-?(?:%\}|\}\})$/,
15-
inside: {
16-
'punctuation': /.+/
17-
}
18-
},
19-
'string': {
20-
pattern: /("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
21-
inside: {
22-
'punctuation': /^['"]|['"]$/
23-
}
24-
},
25-
'keyword': /\b(?:even|if|odd)\b/,
26-
'boolean': /\b(?:false|null|true)\b/,
27-
'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/,
28-
'operator': [
29-
{
30-
pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
31-
lookbehind: true
32-
},
33-
/[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
34-
],
35-
'property': /\b[a-zA-Z_]\w*\b/,
36-
'punctuation': /[()\[\]{}:.,]/
17+
'punctuation': /^['"]|['"]$/
3718
}
3819
},
20+
'keyword': /\b(?:even|if|odd)\b/,
21+
'boolean': /\b(?:false|null|true)\b/,
22+
'number': /\b0x[\dA-Fa-f]+|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][-+]?\d+)?/,
23+
'operator': [
24+
{
25+
pattern: /(\s)(?:and|b-and|b-or|b-xor|ends with|in|is|matches|not|or|same as|starts with)(?=\s)/,
26+
lookbehind: true
27+
},
28+
/[=<>]=?|!=|\*\*?|\/\/?|\?:?|[-+~%|]/
29+
],
30+
'punctuation': /[()\[\]{}:.,]/
31+
};
3932

40-
// The rest can be parsed as HTML
41-
'other': {
42-
// We want non-blank matches
43-
pattern: /\S(?:[\s\S]*\S)?/,
44-
inside: Prism.languages.markup
33+
Prism.hooks.add('before-tokenize', function (env) {
34+
if (env.language !== 'twig') {
35+
return;
4536
}
46-
};
37+
38+
var pattern = /\{(?:#[\s\S]*?#|%[\s\S]*?%|\{[\s\S]*?\})\}/g;
39+
Prism.languages['markup-templating'].buildPlaceholders(env, 'twig', pattern);
40+
});
41+
42+
Prism.hooks.add('after-tokenize', function (env) {
43+
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'twig');
44+
});

‎components/prism-twig.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/autoloader/prism-autoloader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
"markup-templating"
154154
],
155155
"textile": "markup",
156-
"twig": "markup",
156+
"twig": "markup-templating",
157157
"typescript": "javascript",
158158
"v": "clike",
159159
"vala": "clike",

‎plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/twig+pug/twig_inclusion.test

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
[
77
["filter-atpl", [
8-
["filter-name", ":atpl"],
9-
["tag", [
10-
["ld", [["punctuation", "{{"]]],
11-
["number", "42"],
12-
["rd", [["punctuation", "}}"]]]
13-
]]
8+
["filter-name", ":atpl"],
9+
10+
["punctuation", "{"],
11+
["punctuation", "{"],
12+
["number", "42"],
13+
["delimiter", "}}"]
1414
]]
1515
]
1616

1717
----------------------------------------------------
1818

19-
Checks for atpl filter (Twig) in Jade.
19+
Checks for atpl filter (Twig) in Jade.

‎tests/languages/twig/boolean_feature.test

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
----------------------------------------------------
66

77
[
8-
["tag", [
9-
["ld", [["punctuation", "{{"]]],
8+
["twig", [
9+
["delimiter", "{{"],
1010
["boolean", "null"],
11-
["rd", [["punctuation", "}}"]]]
11+
["delimiter", "}}"]
1212
]],
13-
["tag", [
14-
["ld", [["punctuation", "{{-"]]],
13+
["twig", [
14+
["delimiter", "{{-"],
1515
["boolean", "true"],
16-
["rd", [["punctuation", "-}}"]]]
16+
["delimiter", "-}}"]
1717
]],
18-
["tag", [
19-
["ld", [["punctuation", "{{"]]],
18+
["twig", [
19+
["delimiter", "{{"],
2020
["boolean", "false"],
21-
["rd", [["punctuation", "}}"]]]
21+
["delimiter", "}}"]
2222
]]
2323
]
2424

2525
----------------------------------------------------
2626

27-
Checks for booleans and null.
27+
Checks for booleans and null.

‎tests/languages/twig/comment_feature.test

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ bar #}
66
----------------------------------------------------
77

88
[
9-
["comment", "{##}"],
10-
["comment", "{# foo #}"],
11-
["comment", "{# foo\r\nbar #}"]
9+
["twig", [
10+
["comment", "{##}"]
11+
]],
12+
["twig", [
13+
["comment", "{# foo #}"]
14+
]],
15+
["twig", [
16+
["comment", "{# foo\r\nbar #}"]
17+
]]
1218
]
1319

1420
----------------------------------------------------
1521

16-
Checks for comments.
22+
Checks for comments.

‎tests/languages/twig/keyword_feature.test

+44-29
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,63 @@
66
----------------------------------------------------
77

88
[
9-
["tag", [
10-
["ld", [["punctuation", "{%"], ["keyword", "for"]]],
11-
["property", "foo"],
12-
["operator", "in"], ["property", "bar"],
13-
["keyword", "if"], ["property", "baz"],
14-
["rd", [["punctuation", "%}"]]]
9+
["twig", [
10+
["delimiter", "{%"],
11+
["tag-name", "for"],
12+
" foo ",
13+
["operator", "in"],
14+
" bar ",
15+
["keyword", "if"],
16+
" baz ",
17+
["delimiter", "%}"]
1518
]],
16-
["tag", [
17-
["ld", [["punctuation", "{%"], ["keyword", "endfor"]]],
18-
["rd", [["punctuation", "%}"]]]
19+
["twig", [
20+
["delimiter", "{%"],
21+
["tag-name", "endfor"],
22+
["delimiter", "%}"]
1923
]],
20-
["tag", [
21-
["ld", [["punctuation", "{%-"], ["keyword", "if"]]],
22-
["property", "foo"], ["punctuation", "("], ["punctuation", ")"],
23-
["rd", [["punctuation", "-%}"]]]
24+
25+
["twig", [
26+
["delimiter", "{%-"],
27+
["tag-name", "if"],
28+
" foo",
29+
["punctuation", "("],
30+
["punctuation", ")"],
31+
["delimiter", "-%}"]
2432
]],
25-
["tag", [
26-
["ld", [["punctuation", "{%-"], ["keyword", "endif"]]],
27-
["rd", [["punctuation", "-%}"]]]
33+
["twig", [
34+
["delimiter", "{%-"],
35+
["tag-name", "endif"],
36+
["delimiter", "-%}"]
2837
]],
29-
["tag", [
30-
["ld", [["punctuation", "{%"], ["keyword", "macro"]]],
31-
["property", "foobar"], ["punctuation", "("], ["punctuation", ")"],
32-
["rd", [["punctuation", "%}"]]]
38+
39+
["twig", [
40+
["delimiter", "{%"],
41+
["tag-name", "macro"],
42+
" foobar",
43+
["punctuation", "("],
44+
["punctuation", ")"],
45+
["delimiter", "%}"]
3346
]],
34-
["tag", [
35-
["ld", [["punctuation", "{%"], ["keyword", "endmacro"]]],
36-
["rd", [["punctuation", "%}"]]]
47+
["twig", [
48+
["delimiter", "{%"],
49+
["tag-name", "endmacro"],
50+
["delimiter", "%}"]
3751
]],
38-
["tag", [
39-
["ld", [["punctuation", "{{"]]],
40-
["property", "foo"],
52+
53+
["twig", [
54+
["delimiter", "{{"],
55+
" foo ",
4156
["operator", "is"],
4257
["keyword", "even"],
4358
["operator", "or"],
44-
["property", "bar"],
59+
" bar ",
4560
["operator", "is"],
4661
["keyword", "odd"],
47-
["rd", [["punctuation", "}}"]]]
62+
["delimiter", "}}"]
4863
]]
4964
]
5065

5166
----------------------------------------------------
5267

53-
Checks for keywords.
68+
Checks for keywords.
+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>My Webpage</title>
5+
</head>
6+
<body>
7+
<ul id="navigation">
8+
{% for item in navigation %}
9+
<li><a href="{{ item.href }}">{{ item.caption }}</a></li>
10+
{% endfor %}
11+
</ul>
12+
13+
<h1>My Webpage</h1>
14+
{{ a_variable }}
15+
</body>
16+
</html>
17+
18+
----------------------------------------------------
19+
20+
[
21+
["doctype", [
22+
["punctuation", "<!"],
23+
["doctype-tag", "DOCTYPE"],
24+
["name", "html"],
25+
["punctuation", ">"]
26+
]],
27+
28+
["tag", [
29+
["tag", [
30+
["punctuation", "<"],
31+
"html"
32+
]],
33+
["punctuation", ">"]
34+
]],
35+
36+
["tag", [
37+
["tag", [
38+
["punctuation", "<"],
39+
"head"
40+
]],
41+
["punctuation", ">"]
42+
]],
43+
44+
["tag", [
45+
["tag", [
46+
["punctuation", "<"],
47+
"title"
48+
]],
49+
["punctuation", ">"]
50+
]],
51+
"My Webpage",
52+
["tag", [
53+
["tag", [
54+
["punctuation", "</"],
55+
"title"
56+
]],
57+
["punctuation", ">"]
58+
]],
59+
60+
["tag", [
61+
["tag", [
62+
["punctuation", "</"],
63+
"head"
64+
]],
65+
["punctuation", ">"]
66+
]],
67+
68+
["tag", [
69+
["tag", [
70+
["punctuation", "<"],
71+
"body"
72+
]],
73+
["punctuation", ">"]
74+
]],
75+
76+
["tag", [
77+
["tag", [
78+
["punctuation", "<"],
79+
"ul"
80+
]],
81+
["attr-name", ["id"]],
82+
["attr-value", [
83+
["punctuation", "="],
84+
["punctuation", "\""],
85+
"navigation",
86+
["punctuation", "\""]
87+
]],
88+
["punctuation", ">"]
89+
]],
90+
91+
["twig", [
92+
["delimiter", "{%"],
93+
["tag-name", "for"],
94+
" item ",
95+
["operator", "in"],
96+
" navigation ",
97+
["delimiter", "%}"]
98+
]],
99+
100+
["tag", [
101+
["tag", [
102+
["punctuation", "<"],
103+
"li"
104+
]],
105+
["punctuation", ">"]
106+
]],
107+
["tag", [
108+
["tag", [
109+
["punctuation", "<"],
110+
"a"
111+
]],
112+
["attr-name", ["href"]],
113+
["attr-value", [
114+
["punctuation", "="],
115+
["punctuation", "\""],
116+
["twig", [
117+
["delimiter", "{{"],
118+
" item",
119+
["punctuation", "."],
120+
"href ",
121+
["delimiter", "}}"]
122+
]],
123+
["punctuation", "\""]
124+
]],
125+
["punctuation", ">"]
126+
]],
127+
["twig", [
128+
["delimiter", "{{"],
129+
" item",
130+
["punctuation", "."],
131+
"caption ",
132+
["delimiter", "}}"]
133+
]],
134+
["tag", [
135+
["tag", [
136+
["punctuation", "</"],
137+
"a"
138+
]],
139+
["punctuation", ">"]
140+
]],
141+
["tag", [
142+
["tag", [
143+
["punctuation", "</"],
144+
"li"
145+
]],
146+
["punctuation", ">"]
147+
]],
148+
149+
["twig", [
150+
["delimiter", "{%"],
151+
["tag-name", "endfor"],
152+
["delimiter", "%}"]
153+
]],
154+
155+
["tag", [
156+
["tag", [
157+
["punctuation", "</"],
158+
"ul"
159+
]],
160+
["punctuation", ">"]
161+
]],
162+
163+
["tag", [
164+
["tag", [
165+
["punctuation", "<"],
166+
"h1"
167+
]],
168+
["punctuation", ">"]
169+
]],
170+
"My Webpage",
171+
["tag", [
172+
["tag", [
173+
["punctuation", "</"],
174+
"h1"
175+
]],
176+
["punctuation", ">"]
177+
]],
178+
179+
["twig", [
180+
["delimiter", "{{"],
181+
" a_variable ",
182+
["delimiter", "}}"]
183+
]],
184+
185+
["tag", [
186+
["tag", [
187+
["punctuation", "</"],
188+
"body"
189+
]],
190+
["punctuation", ">"]
191+
]],
192+
193+
["tag", [
194+
["tag", [
195+
["punctuation", "</"],
196+
"html"
197+
]],
198+
["punctuation", ">"]
199+
]]
200+
]

‎tests/languages/twig/number_feature.test

+19-19
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@
88
----------------------------------------------------
99

1010
[
11-
["tag", [
12-
["ld", [["punctuation", "{{"]]],
11+
["twig", [
12+
["delimiter", "{{"],
1313
["number", "0xBadFace"],
14-
["rd", [["punctuation", "}}"]]]
14+
["delimiter", "}}"]
1515
]],
16-
["tag", [
17-
["ld", [["punctuation", "{{"]]],
16+
["twig", [
17+
["delimiter", "{{"],
1818
["number", "42"],
19-
["rd", [["punctuation", "}}"]]]
19+
["delimiter", "}}"]
2020
]],
21-
["tag", [
22-
["ld", [["punctuation", "{{"]]],
21+
["twig", [
22+
["delimiter", "{{"],
2323
["number", "3.14159"],
24-
["rd", [["punctuation", "}}"]]]
24+
["delimiter", "}}"]
2525
]],
26-
["tag", [
27-
["ld", [["punctuation", "{{"]]],
26+
["twig", [
27+
["delimiter", "{{"],
2828
["number", "3e15"],
29-
["rd", [["punctuation", "}}"]]]
29+
["delimiter", "}}"]
3030
]],
31-
["tag", [
32-
["ld", [["punctuation", "{{"]]],
31+
["twig", [
32+
["delimiter", "{{"],
3333
["number", "4.5E-4"],
34-
["rd", [["punctuation", "}}"]]]
34+
["delimiter", "}}"]
3535
]],
36-
["tag", [
37-
["ld", [["punctuation", "{{"]]],
36+
["twig", [
37+
["delimiter", "{{"],
3838
["number", "0.2e+8"],
39-
["rd", [["punctuation", "}}"]]]
39+
["delimiter", "}}"]
4040
]]
4141
]
4242

4343
----------------------------------------------------
4444

45-
Checks for hexadecimal and decimal numbers.
45+
Checks for hexadecimal and decimal numbers.

‎tests/languages/twig/operator_feature.test

+212-139
Original file line numberDiff line numberDiff line change
@@ -28,152 +28,225 @@
2828
----------------------------------------------------
2929

3030
[
31-
["tag", [
32-
["ld", [["punctuation", "{%"], ["keyword", "set"]]],
33-
["property", "a"], ["operator", "="], ["number", "4"],
34-
["rd", [["punctuation", "%}"]]]
35-
]],
36-
["tag", [
37-
["ld", [["punctuation", "{{"]]],
38-
["property", "a"], ["operator", "=="], ["number", "4"],
39-
["rd", [["punctuation", "}}"]]]
40-
]],
41-
["tag", [
42-
["ld", [["punctuation", "{{"]]],
43-
["property", "b"], ["operator", "!="], ["property", "c"],
44-
["rd", [["punctuation", "}}"]]]
45-
]],
46-
["tag", [
47-
["ld", [["punctuation", "{{"]]],
48-
["property", "c"], ["operator", "<"], ["property", "d"],
49-
["rd", [["punctuation", "}}"]]]
50-
]],
51-
["tag", [
52-
["ld", [["punctuation", "{{"]]],
53-
["property", "d"], ["operator", "<="], ["property", "e"],
54-
["rd", [["punctuation", "}}"]]]
55-
]],
56-
["tag", [
57-
["ld", [["punctuation", "{{"]]],
58-
["property", "e"], ["operator", ">"], ["property", "f"],
59-
["rd", [["punctuation", "}}"]]]
60-
]],
61-
["tag", [
62-
["ld", [["punctuation", "{{"]]],
63-
["property", "f"], ["operator", ">="], ["property", "g"],
64-
["rd", [["punctuation", "}}"]]]
65-
]],
66-
["tag", [
67-
["ld", [["punctuation", "{{"]]],
68-
["property", "g"], ["operator", "+"], ["property", "h"],
69-
["rd", [["punctuation", "}}"]]]
70-
]],
71-
["tag", [
72-
["ld", [["punctuation", "{{"]]],
73-
["property", "h"], ["operator", "-"], ["property", "i"],
74-
["rd", [["punctuation", "}}"]]]
75-
]],
76-
["tag", [
77-
["ld", [["punctuation", "{{"]]],
78-
["property", "i"], ["operator", "~"], ["property", "j"],
79-
["rd", [["punctuation", "}}"]]]
80-
]],
81-
["tag", [
82-
["ld", [["punctuation", "{{"]]],
83-
["property", "j"], ["operator", "*"], ["property", "k"],
84-
["rd", [["punctuation", "}}"]]]
85-
]],
86-
["tag", [
87-
["ld", [["punctuation", "{{"]]],
88-
["property", "k"], ["operator", "**"], ["property", "l"],
89-
["rd", [["punctuation", "}}"]]]
90-
]],
91-
["tag", [
92-
["ld", [["punctuation", "{{"]]],
93-
["property", "l"], ["operator", "/"], ["property", "m"],
94-
["rd", [["punctuation", "}}"]]]
95-
]],
96-
["tag", [
97-
["ld", [["punctuation", "{{"]]],
98-
["property", "m"], ["operator", "//"], ["property", "n"],
99-
["rd", [["punctuation", "}}"]]]
100-
]],
101-
["tag", [
102-
["ld", [["punctuation", "{{"]]],
103-
["property", "n"], ["operator", "%"], ["property", "o"],
104-
["rd", [["punctuation", "}}"]]]
105-
]],
106-
["tag", [
107-
["ld", [["punctuation", "{{"]]],
108-
["property", "o"],
31+
["twig", [
32+
["delimiter", "{%"],
33+
["tag-name", "set"],
34+
" a ",
35+
["operator", "="],
36+
["number", "4"],
37+
["delimiter", "%}"]
38+
]],
39+
["twig", [
40+
["delimiter", "{{"],
41+
" a ",
42+
["operator", "=="],
43+
["number", "4"],
44+
["delimiter", "}}"]
45+
]],
46+
["twig", [
47+
["delimiter", "{{"],
48+
" b ",
49+
["operator", "!="],
50+
" c ",
51+
["delimiter", "}}"]
52+
]],
53+
["twig", [
54+
["delimiter", "{{"],
55+
" c ",
56+
["operator", "<"],
57+
" d ",
58+
["delimiter", "}}"]
59+
]],
60+
["twig", [
61+
["delimiter", "{{"],
62+
" d ",
63+
["operator", "<="],
64+
" e ",
65+
["delimiter", "}}"]
66+
]],
67+
["twig", [
68+
["delimiter", "{{"],
69+
" e ",
70+
["operator", ">"],
71+
" f ",
72+
["delimiter", "}}"]
73+
]],
74+
["twig", [
75+
["delimiter", "{{"],
76+
" f ",
77+
["operator", ">="],
78+
" g ",
79+
["delimiter", "}}"]
80+
]],
81+
["twig", [
82+
["delimiter", "{{"],
83+
" g ",
84+
["operator", "+"],
85+
" h ",
86+
["delimiter", "}}"]
87+
]],
88+
["twig", [
89+
["delimiter", "{{"],
90+
" h ",
91+
["operator", "-"],
92+
" i ",
93+
["delimiter", "}}"]
94+
]],
95+
["twig", [
96+
["delimiter", "{{"],
97+
" i ",
98+
["operator", "~"],
99+
" j ",
100+
["delimiter", "}}"]
101+
]],
102+
["twig", [
103+
["delimiter", "{{"],
104+
" j ",
105+
["operator", "*"],
106+
" k ",
107+
["delimiter", "}}"]
108+
]],
109+
["twig", [
110+
["delimiter", "{{"],
111+
" k ",
112+
["operator", "**"],
113+
" l ",
114+
["delimiter", "}}"]
115+
]],
116+
["twig", [
117+
["delimiter", "{{"],
118+
" l ",
119+
["operator", "/"],
120+
" m ",
121+
["delimiter", "}}"]
122+
]],
123+
["twig", [
124+
["delimiter", "{{"],
125+
" m ",
126+
["operator", "//"],
127+
" n ",
128+
["delimiter", "}}"]
129+
]],
130+
["twig", [
131+
["delimiter", "{{"],
132+
" n ",
133+
["operator", "%"],
134+
" o ",
135+
["delimiter", "}}"]
136+
]],
137+
["twig", [
138+
["delimiter", "{{"],
139+
" o",
109140
["operator", "|"],
110-
["property", "default"],
141+
"default",
111142
["punctuation", "("],
112-
["string", [["punctuation", "'"], "foo", ["punctuation", "'"]]],
143+
["string", [
144+
["punctuation", "'"],
145+
"foo",
146+
["punctuation", "'"]
147+
]],
113148
["punctuation", ")"],
114-
["rd", [["punctuation", "}}"]]]
115-
]],
116-
["tag", [
117-
["ld", [["punctuation", "{{"]]],
118-
["property", "p"], ["operator", "?"],
119-
["property", "q"], ["punctuation", ":"],
120-
["property", "r"],
121-
["rd", [["punctuation", "}}"]]]
122-
]],
123-
["tag", [
124-
["ld", [["punctuation", "{{"]]],
125-
["property", "s"], ["operator", "?:"], ["property", "t"],
126-
["rd", [["punctuation", "}}"]]]
127-
]],
128-
["tag", [
129-
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
130-
["property", "a"], ["operator", "and"], ["property", "b"],
131-
["operator", "or"], ["operator", "not"], ["property", "c"],
132-
["rd", [["punctuation", "%}"]]]
133-
]],
134-
["tag", [
135-
["ld", [["punctuation", "{%"], ["keyword", "for"]]],
136-
["property", "p"], ["operator", "in"], ["property", "foo"],
137-
["rd", [["punctuation", "%}"]]]
138-
]],
139-
["tag", [
140-
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
141-
["property", "d"], ["operator", "b-and"],
142-
["property", "e"], ["operator", "and"],
143-
["property", "f"], ["operator", "b-xor"],
144-
["property", "g"], ["operator", "or"],
145-
["property", "h"], ["operator", "b-or"],
146-
["property", "i"],
147-
["rd", [["punctuation", "%}"]]]
148-
]],
149-
["tag", [
150-
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
151-
["property", "j"],
152-
["operator", "starts with"],
153-
["string", [["punctuation", "'"], "h", ["punctuation", "'"]]],
154-
["rd", [["punctuation", "%}"]]]
149+
["delimiter", "}}"]
150+
]],
151+
["twig", [
152+
["delimiter", "{{"],
153+
" p ",
154+
["operator", "?"],
155+
" q ",
156+
["punctuation", ":"],
157+
" r ",
158+
["delimiter", "}}"]
159+
]],
160+
["twig", [
161+
["delimiter", "{{"],
162+
" s ",
163+
["operator", "?:"],
164+
" t ",
165+
["delimiter", "}}"]
155166
]],
156-
["tag", [
157-
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
158-
["property", "i"],
167+
168+
["twig", [
169+
["delimiter", "{%"],
170+
["tag-name", "if"],
171+
" a ",
172+
["operator", "and"],
173+
" b ",
174+
["operator", "or"],
175+
["operator", "not"],
176+
" c ",
177+
["delimiter", "%}"]
178+
]],
179+
["twig", [
180+
["delimiter", "{%"],
181+
["tag-name", "for"],
182+
" p ",
183+
["operator", "in"],
184+
" foo ",
185+
["delimiter", "%}"]
186+
]],
187+
["twig", [
188+
["delimiter", "{%"],
189+
["tag-name", "if"],
190+
" d ",
191+
["operator", "b-and"],
192+
" e ",
193+
["operator", "and"],
194+
" f ",
195+
["operator", "b-xor"],
196+
" g ",
197+
["operator", "or"],
198+
" h ",
199+
["operator", "b-or"],
200+
" i ",
201+
["delimiter", "%}"]
202+
]],
203+
["twig", [
204+
["delimiter", "{%"],
205+
["tag-name", "if"],
206+
" j ",
207+
["operator", "starts with"],
208+
["string", [
209+
["punctuation", "'"],
210+
"h",
211+
["punctuation", "'"]
212+
]],
213+
["delimiter", "%}"]
214+
]],
215+
["twig", [
216+
["delimiter", "{%"],
217+
["tag-name", "if"],
218+
" i ",
159219
["operator", "ends with"],
160-
["string", [["punctuation", "'"], "j", ["punctuation", "'"]]],
161-
["rd", [["punctuation", "%}"]]]
162-
]],
163-
["tag", [
164-
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
165-
["property", "k"], ["operator", "is"],
166-
["operator", "same as"], ["boolean", "false"],
167-
["rd", [["punctuation", "%}"]]]
168-
]],
169-
["tag", [
170-
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
171-
["property", "l"], ["operator", "matches"],
172-
["string", [["punctuation", "'"], "/f[o]{2,}(?:bar)?", ["punctuation", "'"]]],
173-
["rd", [["punctuation", "%}"]]]
220+
["string", [
221+
["punctuation", "'"],
222+
"j",
223+
["punctuation", "'"]
224+
]],
225+
["delimiter", "%}"]
226+
]],
227+
["twig", [
228+
["delimiter", "{%"],
229+
["tag-name", "if"],
230+
" k ",
231+
["operator", "is"],
232+
["operator", "same as"],
233+
["boolean", "false"],
234+
["delimiter", "%}"]
235+
]],
236+
["twig", [
237+
["delimiter", "{%"],
238+
["tag-name", "if"],
239+
" l ",
240+
["operator", "matches"],
241+
["string", [
242+
["punctuation", "'"],
243+
"/f[o]{2,}(?:bar)?",
244+
["punctuation", "'"]
245+
]],
246+
["delimiter", "%}"]
174247
]]
175248
]
176249

177250
----------------------------------------------------
178251

179-
Checks for operators.
252+
Checks for operators.

‎tests/languages/twig/string_feature.test

+31-17
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,42 @@
66
----------------------------------------------------
77

88
[
9-
["tag", [
10-
["ld", [["punctuation", "{{"]]],
11-
["string", [["punctuation", "'"], ["punctuation", "'"]]],
12-
["rd", [["punctuation", "}}"]]]
9+
["twig", [
10+
["delimiter", "{{"],
11+
["string", [
12+
["punctuation", "'"],
13+
["punctuation", "'"]
14+
]],
15+
["delimiter", "}}"]
1316
]],
14-
["tag", [
15-
["ld", [["punctuation", "{{"]]],
16-
["string", [["punctuation", "\""], ["punctuation", "\""]]],
17-
["rd", [["punctuation", "}}"]]]
17+
["twig", [
18+
["delimiter", "{{"],
19+
["string", [
20+
["punctuation", "\""],
21+
["punctuation", "\""]
22+
]],
23+
["delimiter", "}}"]
1824
]],
19-
["tag", [
20-
["ld", [["punctuation", "{{"]]],
21-
["string", [["punctuation", "\""], "ba\\\"r", ["punctuation", "\""]]],
22-
["rd", [["punctuation", "}}"]]]
25+
["twig", [
26+
["delimiter", "{{"],
27+
["string", [
28+
["punctuation", "\""],
29+
"ba\\\"r",
30+
["punctuation", "\""]
31+
]],
32+
["delimiter", "}}"]
2333
]],
24-
["tag", [
25-
["ld", [["punctuation", "{{"]]],
26-
["string", [["punctuation", "'"], "ba\\'z", ["punctuation", "'"]]],
27-
["rd", [["punctuation", "}}"]]]
34+
["twig", [
35+
["delimiter", "{{"],
36+
["string", [
37+
["punctuation", "'"],
38+
"ba\\'z",
39+
["punctuation", "'"]
40+
]],
41+
["delimiter", "}}"]
2842
]]
2943
]
3044

3145
----------------------------------------------------
3246

33-
Checks for strings.
47+
Checks for strings.

0 commit comments

Comments
 (0)
Please sign in to comment.