From 1cd08d1613cd859be8b2c056245e92136f1a6246 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Sat, 20 Jun 2020 18:54:29 +0200 Subject: [PATCH] Add highlighting support for conditions This commit adds syntax highlighting support for TypoScript conditions (both legacy conditions and the new Symfony expressions) in both .typoscript and .tsconfig files. The regular expressions used to match the tokens of the Symfony expression language have been adapted from the original Symfony expression language repo (MIT licensed) [1]. [1]: https://github.com/symfony/expression-language/blob/master/Lexer.php --- syntaxes/tsconfig.tmLanguage.json | 71 +++++++++++++++++++++++++++-- syntaxes/typoscript.tmLanguage.json | 71 +++++++++++++++++++++++++++-- 2 files changed, 136 insertions(+), 6 deletions(-) diff --git a/syntaxes/tsconfig.tmLanguage.json b/syntaxes/tsconfig.tmLanguage.json index dac12e8..e3358e4 100644 --- a/syntaxes/tsconfig.tmLanguage.json +++ b/syntaxes/tsconfig.tmLanguage.json @@ -103,10 +103,75 @@ ] }, "conditions": { + "begin": "\\[", + "end": "\\]", + "beginCaptures": { + "0": { + "name": "punctuation.paren.open" + } + }, + "endCaptures": { + "0": { + "name": "punctuation.paren.close" + } + }, "patterns": [ { - "name": "variable.other.tsconfig", - "match": "\\[(adminUser|language|IP|hostname|applicationContext|hour|minute|month|year|dayofweek|dayofmonth|dayofyear|usergroup|loginUser|page|treeLevel|PIDinRootline|PIDupinRootline|compatVersion|globalVar|globalString|global|userFunc|end|((?:\\{1,2}\\w+|\\w+\\\\{1,2})(?:\\w+\\\\{0,2})+)).*\\]" + "match": "(adminUser|language|IP|hostname|applicationContext|hour|minute|month|year|dayofweek|dayofmonth|dayofyear|usergroup|loginUser|page|treeLevel|PIDinRootline|PIDupinRootline|compatVersion|globalVar|globalString|global|userFunc|end|((?:\\{1,2}\\w+|\\w+\\\\{1,2})(?:\\w+\\\\{0,2})+))(?:\\s+=\\s+([^\\]]*))?", + "captures": { + "0": { + "name": "variable.other.tsconfig" + }, + "3": { + "name": "string.unquoted.tsconfig" + } + } + }, + { + "include": "#condition-expression" + } + ] + }, + "condition-expression": { + "patterns": [ + { + "match": "[0-9]+(?:\\.[0-9]+)?([Ee][\\+\\-][0-9]+)?", + "name": "constant.numeric.other.symfonyexpression" + }, + { + "begin": "[\\(\\[\\{]", + "beginCaptures": { + "0": { + "name": "punctuation.paren.open" + } + }, + "end": "[\\)\\]\\}]", + "endCaptures": { + "0": { + "name": "punctuation.paren.close" + } + }, + "patterns": [ + { + "include": "#condition-expression" + } + ] + }, + { + "match": "\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"|'([^'\\\\]*(?:\\\\.[^'\\\\]*)*)'", + "name": "string.quoted.other.symfonyexpression" + }, + { + "match": "(?<=^|[\\s(])not in(?=[\\s(])|\\!\\=\\=|(?<=^|[\\s(])not(?=[\\s(])|(?<=^|[\\s(])and(?=[\\s(])|\\=\\=\\=|\\>\\=|(?<=^|[\\s(])or(?=[\\s(])|\\<\\=|\\*\\*|\\.\\.|(?<=^|[\\s(])in(?=[\\s(])|&&|\\|\\||(?<=^|[\\s(])matches|\\=\\=|\\!\\=|\\*|~|%|\\\/|\\>|\\||\\!|\\^|&|\\+|\\<|\\-", + "name": "keyword.operator.other.symfonyexpression" + }, + { + "match": "[\\.,\\?\\:]", + "name": "punctuation.other.symfonyexpression" + }, + { + "match": "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*", + "name": "variable.other.symfonyexpression" } ] }, @@ -238,4 +303,4 @@ } }, "scopeName": "source.tsconfig" -} +} \ No newline at end of file diff --git a/syntaxes/typoscript.tmLanguage.json b/syntaxes/typoscript.tmLanguage.json index bb5b9ac..3882748 100644 --- a/syntaxes/typoscript.tmLanguage.json +++ b/syntaxes/typoscript.tmLanguage.json @@ -103,10 +103,75 @@ ] }, "conditions": { + "begin": "\\[", + "end": "\\]", + "beginCaptures": { + "0": { + "name": "punctuation.paren.open" + } + }, + "endCaptures": { + "0": { + "name": "punctuation.paren.close" + } + }, "patterns": [ { - "name": "variable.other.typoscript", - "match": "\\[(adminUser|language|IP|hostname|applicationContext|hour|minute|month|year|dayofweek|dayofmonth|dayofyear|usergroup|loginUser|page|treeLevel|PIDinRootline|PIDupinRootline|compatVersion|globalVar|globalString|global|userFunc|end|((?:\\{1,2}\\w+|\\w+\\\\{1,2})(?:\\w+\\\\{0,2})+)).*\\]" + "match": "(adminUser|language|IP|hostname|applicationContext|hour|minute|month|year|dayofweek|dayofmonth|dayofyear|usergroup|loginUser|page|treeLevel|PIDinRootline|PIDupinRootline|compatVersion|globalVar|globalString|global|userFunc|end|((?:\\{1,2}\\w+|\\w+\\\\{1,2})(?:\\w+\\\\{0,2})+))(?:\\s+=\\s+([^\\]]*))?", + "captures": { + "0": { + "name": "variable.other.typoscript" + }, + "3": { + "name": "string.unquoted.typoscript" + } + } + }, + { + "include": "#condition-expression" + } + ] + }, + "condition-expression": { + "patterns": [ + { + "match": "[0-9]+(?:\\.[0-9]+)?([Ee][\\+\\-][0-9]+)?", + "name": "constant.numeric.other.symfonyexpression" + }, + { + "begin": "[\\(\\[\\{]", + "beginCaptures": { + "0": { + "name": "punctuation.paren.open" + } + }, + "end": "[\\)\\]\\}]", + "endCaptures": { + "0": { + "name": "punctuation.paren.close" + } + }, + "patterns": [ + { + "include": "#condition-expression" + } + ] + }, + { + "match": "\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"|'([^'\\\\]*(?:\\\\.[^'\\\\]*)*)'", + "name": "string.quoted.other.symfonyexpression" + }, + { + "match": "(?<=^|[\\s(])not in(?=[\\s(])|\\!\\=\\=|(?<=^|[\\s(])not(?=[\\s(])|(?<=^|[\\s(])and(?=[\\s(])|\\=\\=\\=|\\>\\=|(?<=^|[\\s(])or(?=[\\s(])|\\<\\=|\\*\\*|\\.\\.|(?<=^|[\\s(])in(?=[\\s(])|&&|\\|\\||(?<=^|[\\s(])matches|\\=\\=|\\!\\=|\\*|~|%|\\\/|\\>|\\||\\!|\\^|&|\\+|\\<|\\-", + "name": "keyword.operator.other.symfonyexpression" + }, + { + "match": "[\\.,\\?\\:]", + "name": "punctuation.other.symfonyexpression" + }, + { + "match": "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*", + "name": "variable.other.symfonyexpression" } ] }, @@ -238,4 +303,4 @@ } }, "scopeName": "source.typoscript" -} +} \ No newline at end of file