Skip to content

Commit

Permalink
Latte: Use standard token names and combined delimiter tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Nov 25, 2021
1 parent cefccdd commit 2b4b689
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 124 deletions.
22 changes: 8 additions & 14 deletions components/prism-latte.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
(function (Prism) {
Prism.languages.latte = {
'comment': /^\{\*[\s\S]*/,
'ld': {
pattern: /^\{(?:[=_]|\/?(?!\d|\w+\()\w+)?/,
inside: {
'punctuation': /^\{\/?/,
'tag': {
pattern: /.+/,
alias: 'important'
}
}
'latte-tag': {
// https://latte.nette.org/en/tags
pattern: /(^\{(?:\/(?=[a-z]))?)(?:[=_]|[a-z]\w*\b(?!\())/i,
lookbehind: true,
alias: 'important'
},
'rd': {
pattern: /\}$/,
inside: {
'punctuation': /.+/
}
'delimiter': {
pattern: /^\{\/?|\}$/,
alias: 'punctuation'
},
'php': {
pattern: /\S(?:[\s\S]*\S)?/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-latte.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 20 additions & 58 deletions tests/languages/latte/delimiter_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,100 +15,62 @@ line}

[
["latte", [
["ld", [
["punctuation", "{"],
["tag", "aa"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "{"],
["latte-tag", "aa"],
["delimiter", "}"]
]],

["latte", [
["ld", [
["punctuation", "{/"],
["tag", "aa"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "{/"],
["latte-tag", "aa"],
["delimiter", "}"]
]],

["latte", [
["ld", [
["punctuation", "{"]
]],
["php", [
["operator", "/"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "{/"],
["delimiter", "}"]
]],

"\r\n{",
["latte", [
["ld", [
["punctuation", "{"],
["tag", "aa"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "{"],
["latte-tag", "aa"],
["delimiter", "}"]
]],
"}\r\n",

["latte", [
["ld", [
["punctuation", "{"]
]],
["delimiter", "{"],
["php", [
["number", "10"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "}"]
]],

["latte", [
["ld", [
["punctuation", "{"],
["tag", "="]
]],
["delimiter", "{"],
["latte-tag", "="],
["php", [
["number", "10"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "}"]
]],

["latte", [
["ld", [
["punctuation", "{"]
]],
["delimiter", "{"],
["php", [
["function", ["test"]],
["punctuation", "("],
["punctuation", ")"]
]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "}"]
]],

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

["latte", [
["ld", [
["punctuation", "{"],
["tag", "multi"]
]],

["php", ["line"]],
["rd", [
["punctuation", "}"]
]]
["delimiter", "{"], ["latte-tag", "multi"],
["php", ["line"]], ["delimiter", "}"]
]]
]

Expand Down
203 changes: 170 additions & 33 deletions tests/languages/latte/html_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,179 @@
----------------------------------------------------

[
["tag", [["tag", [["punctuation", "<"], "a"]],
["attr-name", ["href"]], ["attr-value", [["punctuation", "="], ["punctuation", "\""],
["latte", [["ld", [["punctuation", "{"], ["tag", "link"]]],
["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]],
["rd", [["punctuation", "}"]]]]],
["punctuation", "\""]]], ["punctuation", ">"]]],
["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]],
["tag", [["tag", [["punctuation", "</"], "a"]], ["punctuation", ">"]]],
["tag", [
["tag", [
["punctuation", "<"],
"a"
]],
["attr-name", ["href"]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
["latte", [
["delimiter", "{"],
["latte-tag", "link"],
["php", [
"Post",
["punctuation", ":"],
["class-name", "show"],
["variable", "$post"],
["operator", "->"],
["property", "id"]
]],
["delimiter", "}"]
]],
["punctuation", "\""]
]],
["punctuation", ">"]
]],
["latte", [
["delimiter", "{"],
["php", [
["variable", "$post"],
["operator", "->"],
["property", "title"]
]],
["delimiter", "}"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"a"
]],
["punctuation", ">"]
]],

["tag", [["tag", [["punctuation", "<"], "a"]],
["attr-name",
[["latte", [["ld", [["punctuation", "{"], ["tag", "if"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["rd", [["punctuation", "}"]]]]], "title"]
],
["attr-value", [["punctuation", "="], ["punctuation", "\""], "ahoj", ["punctuation", "\""]]],
["attr-name", [["latte", [["ld", [["punctuation", "{/"], ["tag", "if"]]], ["rd", [["punctuation", "}"]]]]]]],
["punctuation", ">"]]],
["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]],
["tag", [["tag", [["punctuation", "</"], "a"]], ["punctuation", ">"]]],
["tag", [
["tag", [
["punctuation", "<"],
"a"
]],
["attr-name", [
["latte", [
["delimiter", "{"],
["latte-tag", "if"],
["php", [
["variable", "$post"],
["operator", "->"],
["property", "id"]
]],
["delimiter", "}"]
]],
"title"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"ahoj",
["punctuation", "\""]
]],
["attr-name", [
["latte", [
["delimiter", "{/"],
["latte-tag", "if"],
["delimiter", "}"]
]]
]],
["punctuation", ">"]
]],
["latte", [
["delimiter", "{"],
["php", [
["variable", "$post"],
["operator", "->"],
["property", "title"]
]],
["delimiter", "}"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"a"
]],
["punctuation", ">"]
]],

["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]],

["tag", [["tag", [["punctuation", "<"], "div"]],
["n-attr", [["attr-name", "n:attr"], ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]],
["punctuation", ">"]]],

["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "''"]]], ["rd", [["punctuation", "}"]]]]],

["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]],

["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]],

["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]],

["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["comment", "/* \" */"]]], ["rd", [["punctuation", "}"]]]]]
["latte", [
["delimiter", "{"],
["latte-tag", "tag"],
["php", [
["variable", "$a"],
["operator", "="],
["constant", "true"],
["operator", "?"],
["number", "10"],
["operator", "*"],
["number", "5"]
]],
["delimiter", "}"]
]],
["tag", [
["tag", [
["punctuation", "<"],
"div"
]],
["n-attr", [
["attr-name", "n:attr"],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
["php", [
["variable", "$a"],
["operator", "="],
["constant", "true"],
["operator", "?"],
["number", "10"],
["operator", "*"],
["number", "5"]
]],
["punctuation", "\""]
]]
]],
["punctuation", ">"]
]],
["latte", [
["delimiter", "{"],
["latte-tag", "php"],
["php", [
["string", "''"]
]],
["delimiter", "}"]
]],
["latte", [
["delimiter", "{"],
["latte-tag", "php"],
["php", [
["string", ["\"\""]]
]],
["delimiter", "}"]
]],
["latte", [
["delimiter", "{"],
["latte-tag", "php"],
["php", [
["string", ["\"ba\\\"r\""]]
]],
["delimiter", "}"]
]],
["latte", [
["delimiter", "{"],
["latte-tag", "php"],
["php", [
["string", "'ba\\'z'"]
]],
["delimiter", "}"]
]],
["latte", [
["delimiter", "{"],
["latte-tag", "php"],
["php", [
["comment", "/* \" */"]
]],
["delimiter", "}"]
]]
]

----------------------------------------------------

Checks for operators.
Checks for operators.
Loading

0 comments on commit 2b4b689

Please sign in to comment.