Skip to content

Commit 6b168a3

Browse files
authoredDec 5, 2021
Latte: Use standard token names and combined delimiter tokens (#3226)
1 parent 81920b6 commit 6b168a3

File tree

5 files changed

+286
-124
lines changed

5 files changed

+286
-124
lines changed
 

‎components/prism-latte.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
(function (Prism) {
22
Prism.languages.latte = {
33
'comment': /^\{\*[\s\S]*/,
4-
'ld': {
5-
pattern: /^\{(?:[=_]|\/?(?!\d|\w+\()\w+)?/,
6-
inside: {
7-
'punctuation': /^\{\/?/,
8-
'tag': {
9-
pattern: /.+/,
10-
alias: 'important'
11-
}
12-
}
4+
'latte-tag': {
5+
// https://latte.nette.org/en/tags
6+
pattern: /(^\{(?:\/(?=[a-z]))?)(?:[=_]|[a-z]\w*\b(?!\())/i,
7+
lookbehind: true,
8+
alias: 'important'
139
},
14-
'rd': {
15-
pattern: /\}$/,
16-
inside: {
17-
'punctuation': /.+/
18-
}
10+
'delimiter': {
11+
pattern: /^\{\/?|\}$/,
12+
alias: 'punctuation'
1913
},
2014
'php': {
2115
pattern: /\S(?:[\s\S]*\S)?/,

‎components/prism-latte.min.js

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

‎tests/languages/latte/delimiter_feature.test

+20-58
Original file line numberDiff line numberDiff line change
@@ -15,100 +15,62 @@ line}
1515

1616
[
1717
["latte", [
18-
["ld", [
19-
["punctuation", "{"],
20-
["tag", "aa"]
21-
]],
22-
["rd", [
23-
["punctuation", "}"]
24-
]]
18+
["delimiter", "{"],
19+
["latte-tag", "aa"],
20+
["delimiter", "}"]
2521
]],
2622

2723
["latte", [
28-
["ld", [
29-
["punctuation", "{/"],
30-
["tag", "aa"]
31-
]],
32-
["rd", [
33-
["punctuation", "}"]
34-
]]
24+
["delimiter", "{/"],
25+
["latte-tag", "aa"],
26+
["delimiter", "}"]
3527
]],
3628

3729
["latte", [
38-
["ld", [
39-
["punctuation", "{"]
40-
]],
41-
["php", [
42-
["operator", "/"]
43-
]],
44-
["rd", [
45-
["punctuation", "}"]
46-
]]
30+
["delimiter", "{/"],
31+
["delimiter", "}"]
4732
]],
4833

4934
"\r\n{",
5035
["latte", [
51-
["ld", [
52-
["punctuation", "{"],
53-
["tag", "aa"]
54-
]],
55-
["rd", [
56-
["punctuation", "}"]
57-
]]
36+
["delimiter", "{"],
37+
["latte-tag", "aa"],
38+
["delimiter", "}"]
5839
]],
5940
"}\r\n",
6041

6142
["latte", [
62-
["ld", [
63-
["punctuation", "{"]
64-
]],
43+
["delimiter", "{"],
6544
["php", [
6645
["number", "10"]
6746
]],
68-
["rd", [
69-
["punctuation", "}"]
70-
]]
47+
["delimiter", "}"]
7148
]],
7249

7350
["latte", [
74-
["ld", [
75-
["punctuation", "{"],
76-
["tag", "="]
77-
]],
51+
["delimiter", "{"],
52+
["latte-tag", "="],
7853
["php", [
7954
["number", "10"]
8055
]],
81-
["rd", [
82-
["punctuation", "}"]
83-
]]
56+
["delimiter", "}"]
8457
]],
8558

8659
["latte", [
87-
["ld", [
88-
["punctuation", "{"]
89-
]],
60+
["delimiter", "{"],
9061
["php", [
9162
["function", ["test"]],
9263
["punctuation", "("],
9364
["punctuation", ")"]
9465
]],
95-
["rd", [
96-
["punctuation", "}"]
97-
]]
66+
["delimiter", "}"]
9867
]],
9968

10069
"\r\n{'no'}\r\n{\"no\"}\r\n{ no }\r\n",
10170

10271
["latte", [
103-
["ld", [
104-
["punctuation", "{"],
105-
["tag", "multi"]
106-
]],
107-
108-
["php", ["line"]],
109-
["rd", [
110-
["punctuation", "}"]
111-
]]
72+
["delimiter", "{"], ["latte-tag", "multi"],
73+
["php", ["line"]], ["delimiter", "}"]
11274
]]
11375
]
11476

‎tests/languages/latte/html_feature.test

+170-33
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,179 @@
1212
----------------------------------------------------
1313

1414
[
15-
["tag", [["tag", [["punctuation", "<"], "a"]],
16-
["attr-name", ["href"]], ["attr-value", [["punctuation", "="], ["punctuation", "\""],
17-
["latte", [["ld", [["punctuation", "{"], ["tag", "link"]]],
18-
["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]],
19-
["rd", [["punctuation", "}"]]]]],
20-
["punctuation", "\""]]], ["punctuation", ">"]]],
21-
["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]],
22-
["tag", [["tag", [["punctuation", "</"], "a"]], ["punctuation", ">"]]],
15+
["tag", [
16+
["tag", [
17+
["punctuation", "<"],
18+
"a"
19+
]],
20+
["attr-name", ["href"]],
21+
["attr-value", [
22+
["punctuation", "="],
23+
["punctuation", "\""],
24+
["latte", [
25+
["delimiter", "{"],
26+
["latte-tag", "link"],
27+
["php", [
28+
"Post",
29+
["punctuation", ":"],
30+
["class-name", "show"],
31+
["variable", "$post"],
32+
["operator", "->"],
33+
["property", "id"]
34+
]],
35+
["delimiter", "}"]
36+
]],
37+
["punctuation", "\""]
38+
]],
39+
["punctuation", ">"]
40+
]],
41+
["latte", [
42+
["delimiter", "{"],
43+
["php", [
44+
["variable", "$post"],
45+
["operator", "->"],
46+
["property", "title"]
47+
]],
48+
["delimiter", "}"]
49+
]],
50+
["tag", [
51+
["tag", [
52+
["punctuation", "</"],
53+
"a"
54+
]],
55+
["punctuation", ">"]
56+
]],
2357

24-
["tag", [["tag", [["punctuation", "<"], "a"]],
25-
["attr-name",
26-
[["latte", [["ld", [["punctuation", "{"], ["tag", "if"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["rd", [["punctuation", "}"]]]]], "title"]
27-
],
28-
["attr-value", [["punctuation", "="], ["punctuation", "\""], "ahoj", ["punctuation", "\""]]],
29-
["attr-name", [["latte", [["ld", [["punctuation", "{/"], ["tag", "if"]]], ["rd", [["punctuation", "}"]]]]]]],
30-
["punctuation", ">"]]],
31-
["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]],
32-
["tag", [["tag", [["punctuation", "</"], "a"]], ["punctuation", ">"]]],
58+
["tag", [
59+
["tag", [
60+
["punctuation", "<"],
61+
"a"
62+
]],
63+
["attr-name", [
64+
["latte", [
65+
["delimiter", "{"],
66+
["latte-tag", "if"],
67+
["php", [
68+
["variable", "$post"],
69+
["operator", "->"],
70+
["property", "id"]
71+
]],
72+
["delimiter", "}"]
73+
]],
74+
"title"
75+
]],
76+
["attr-value", [
77+
["punctuation", "="],
78+
["punctuation", "\""],
79+
"ahoj",
80+
["punctuation", "\""]
81+
]],
82+
["attr-name", [
83+
["latte", [
84+
["delimiter", "{/"],
85+
["latte-tag", "if"],
86+
["delimiter", "}"]
87+
]]
88+
]],
89+
["punctuation", ">"]
90+
]],
91+
["latte", [
92+
["delimiter", "{"],
93+
["php", [
94+
["variable", "$post"],
95+
["operator", "->"],
96+
["property", "title"]
97+
]],
98+
["delimiter", "}"]
99+
]],
100+
["tag", [
101+
["tag", [
102+
["punctuation", "</"],
103+
"a"
104+
]],
105+
["punctuation", ">"]
106+
]],
33107

34-
["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]],
35-
36-
["tag", [["tag", [["punctuation", "<"], "div"]],
37-
["n-attr", [["attr-name", "n:attr"], ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]],
38-
["punctuation", ">"]]],
39-
40-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "''"]]], ["rd", [["punctuation", "}"]]]]],
41-
42-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]],
43-
44-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]],
45-
46-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]],
47-
48-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["comment", "/* \" */"]]], ["rd", [["punctuation", "}"]]]]]
108+
["latte", [
109+
["delimiter", "{"],
110+
["latte-tag", "tag"],
111+
["php", [
112+
["variable", "$a"],
113+
["operator", "="],
114+
["constant", "true"],
115+
["operator", "?"],
116+
["number", "10"],
117+
["operator", "*"],
118+
["number", "5"]
119+
]],
120+
["delimiter", "}"]
121+
]],
122+
["tag", [
123+
["tag", [
124+
["punctuation", "<"],
125+
"div"
126+
]],
127+
["n-attr", [
128+
["attr-name", "n:attr"],
129+
["attr-value", [
130+
["punctuation", "="],
131+
["punctuation", "\""],
132+
["php", [
133+
["variable", "$a"],
134+
["operator", "="],
135+
["constant", "true"],
136+
["operator", "?"],
137+
["number", "10"],
138+
["operator", "*"],
139+
["number", "5"]
140+
]],
141+
["punctuation", "\""]
142+
]]
143+
]],
144+
["punctuation", ">"]
145+
]],
146+
["latte", [
147+
["delimiter", "{"],
148+
["latte-tag", "php"],
149+
["php", [
150+
["string", "''"]
151+
]],
152+
["delimiter", "}"]
153+
]],
154+
["latte", [
155+
["delimiter", "{"],
156+
["latte-tag", "php"],
157+
["php", [
158+
["string", ["\"\""]]
159+
]],
160+
["delimiter", "}"]
161+
]],
162+
["latte", [
163+
["delimiter", "{"],
164+
["latte-tag", "php"],
165+
["php", [
166+
["string", ["\"ba\\\"r\""]]
167+
]],
168+
["delimiter", "}"]
169+
]],
170+
["latte", [
171+
["delimiter", "{"],
172+
["latte-tag", "php"],
173+
["php", [
174+
["string", "'ba\\'z'"]
175+
]],
176+
["delimiter", "}"]
177+
]],
178+
["latte", [
179+
["delimiter", "{"],
180+
["latte-tag", "php"],
181+
["php", [
182+
["comment", "/* \" */"]
183+
]],
184+
["delimiter", "}"]
185+
]]
49186
]
50187

51188
----------------------------------------------------
52189

53-
Checks for operators.
190+
Checks for operators.

‎tests/languages/latte/php_feature.test

+87-18
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,94 @@
1010
----------------------------------------------------
1111

1212
[
13-
["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]],
14-
15-
["tag", [["tag", [["punctuation", "<"], "div"]], ["n-attr", [["attr-name", "n:attr"],
16-
["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]],
17-
["punctuation", ">"]]],
18-
19-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "''"]]], ["rd", [["punctuation", "}"]]]]],
20-
21-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]],
22-
23-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]],
24-
25-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]],
26-
27-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["comment", "/* \" */"]]], ["rd", [["punctuation", "}"]]]]],
28-
29-
["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["comment", "/* } */"]]], ["rd", [["punctuation", "}"]]]]]
13+
["latte", [
14+
["delimiter", "{"],
15+
["latte-tag", "tag"],
16+
["php", [
17+
["variable", "$a"],
18+
["operator", "="],
19+
["constant", "true"],
20+
["operator", "?"],
21+
["number", "10"],
22+
["operator", "*"],
23+
["number", "5"]
24+
]],
25+
["delimiter", "}"]
26+
]],
27+
["tag", [
28+
["tag", [
29+
["punctuation", "<"],
30+
"div"
31+
]],
32+
["n-attr", [
33+
["attr-name", "n:attr"],
34+
["attr-value", [
35+
["punctuation", "="],
36+
["punctuation", "\""],
37+
["php", [
38+
["variable", "$a"],
39+
["operator", "="],
40+
["constant", "true"],
41+
["operator", "?"],
42+
["number", "10"],
43+
["operator", "*"],
44+
["number", "5"]
45+
]],
46+
["punctuation", "\""]
47+
]]
48+
]],
49+
["punctuation", ">"]
50+
]],
51+
["latte", [
52+
["delimiter", "{"],
53+
["latte-tag", "php"],
54+
["php", [
55+
["string", "''"]
56+
]],
57+
["delimiter", "}"]
58+
]],
59+
["latte", [
60+
["delimiter", "{"],
61+
["latte-tag", "php"],
62+
["php", [
63+
["string", ["\"\""]]
64+
]],
65+
["delimiter", "}"]
66+
]],
67+
["latte", [
68+
["delimiter", "{"],
69+
["latte-tag", "php"],
70+
["php", [
71+
["string", ["\"ba\\\"r\""]]
72+
]],
73+
["delimiter", "}"]
74+
]],
75+
["latte", [
76+
["delimiter", "{"],
77+
["latte-tag", "php"],
78+
["php", [
79+
["string", "'ba\\'z'"]
80+
]],
81+
["delimiter", "}"]
82+
]],
83+
["latte", [
84+
["delimiter", "{"],
85+
["latte-tag", "php"],
86+
["php", [
87+
["comment", "/* \" */"]
88+
]],
89+
["delimiter", "}"]
90+
]],
91+
["latte", [
92+
["delimiter", "{"],
93+
["latte-tag", "php"],
94+
["php", [
95+
["comment", "/* } */"]
96+
]],
97+
["delimiter", "}"]
98+
]]
3099
]
31100

32101
----------------------------------------------------
33102

34-
Checks for operators.
103+
Checks for operators.

0 commit comments

Comments
 (0)
Please sign in to comment.