From ed7dd4693b57eb4be0cdb579e7501a29ece572f4 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 20 Oct 2024 14:23:48 +0200 Subject: [PATCH] Add support for guard tag Supported by Twig 3.15+ --- Syntaxes/HTML/syntax_test_scopes.html.twig | 48 ++++++++++++++++++++++ Syntaxes/Text/Text (Twig).sublime-syntax | 44 +++++++++++++++++--- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/Syntaxes/HTML/syntax_test_scopes.html.twig b/Syntaxes/HTML/syntax_test_scopes.html.twig index 75a4824..2a292b2 100644 --- a/Syntaxes/HTML/syntax_test_scopes.html.twig +++ b/Syntaxes/HTML/syntax_test_scopes.html.twig @@ -1278,6 +1278,54 @@ {# ^^^^^^^^ meta.path.twig variable.other.twig #} {# ^^ punctuation.section.embedded.end.twig #} +|============================================================================== +| Guard +| https://twig.symfony.com/doc/3.x/tags/guard.html +|============================================================================== + +{% guard function importmap %} +{#^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.twig source.twig.embedded #} +{# ^^ meta.embedded.statement.twig - source #} +{# ^^^^^ keyword.other.twig #} +{# ^^^^^^^^ storage.type.function.twig #} +{# ^^^^^^^^^ meta.function-call.identifier.twig variable.function.twig #} +{# ^^ punctuation.section.embedded.end.twig #} + + {{ importmap('app') }} +{# ^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.expression.twig #} +{# ^^ punctuation.section.embedded.begin.twig #} +{# ^^^^^^^^^^^^^^^^^^ source.twig.embedded #} +{# ^^^^^^^^^ meta.function-call.identifier.twig variable.function.twig #} +{# ^^^^^^^ meta.function-call.arguments.twig #} +{# ^ punctuation.section.arguments.begin.twig #} +{# ^^^^^ meta.string.twig string.quoted.single.twig #} +{# ^ punctuation.definition.string.begin.twig #} +{# ^ punctuation.definition.string.end.twig #} +{# ^ punctuation.section.arguments.end.twig #} +{# ^^ punctuation.section.embedded.end.twig #} + +{% guard filter callable %} +{#^^^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.twig source.twig.embedded #} +{# ^^ meta.embedded.statement.twig - source #} +{# ^^^^^ keyword.other.twig #} +{# ^^^^^^ storage.type.filter.twig #} +{# ^^^^^^^^ meta.function-call.identifier.twig variable.function.filter.twig #} +{# ^^ punctuation.section.embedded.end.twig #} + +{% guard test callable %} +{#^^^^^^^^^^^^^^^^^^^^^ meta.embedded.statement.twig source.twig.embedded #} +{# ^^ meta.embedded.statement.twig - source #} +{# ^^^^^ keyword.other.twig #} +{# ^^^^ storage.type.test.twig #} +{# ^^^^^^^^ meta.function-call.identifier.twig variable.function.test.twig #} +{# ^^ punctuation.section.embedded.end.twig #} + +{% endguard %} +{#^^^^^^^^^^ meta.embedded.statement.twig source.twig.embedded #} +{# ^^ meta.embedded.statement.twig - source #} +{# ^^^^^^^^ keyword.other.twig #} +{# ^^ punctuation.section.embedded.end.twig #} + |============================================================================== | If | https://twig.symfony.com/doc/3.x/tags/if.html diff --git a/Syntaxes/Text/Text (Twig).sublime-syntax b/Syntaxes/Text/Text (Twig).sublime-syntax index 865e712..c80a741 100644 --- a/Syntaxes/Text/Text (Twig).sublime-syntax +++ b/Syntaxes/Text/Text (Twig).sublime-syntax @@ -308,7 +308,7 @@ contexts: ###[ TWIG OTHER STATEMENTS ]################################################### other-statement: - # other statements + # apply statement - match: apply\b scope: keyword.other.twig set: @@ -318,6 +318,15 @@ contexts: - match: endapply\b scope: keyword.other.twig pop: 1 + # guard statement + - match: guard\b + scope: keyword.other.twig + set: + - guard-meta + - guard-type + - match: endguard\b + scope: keyword.other.twig + pop: 1 # block tags - match: (?:end)?(?:autoescape|cache|embed|sandbox|with)\b scope: keyword.other.twig @@ -327,6 +336,24 @@ contexts: scope: keyword.other.twig pop: 1 + guard-meta: + - meta_scope: meta.statement.guard.twig + - include: block-pop + + guard-type: + - match: filter\b + scope: storage.type.filter.twig + set: + - filter-meta + - filter-name + - match: function\b + scope: storage.type.function.twig + set: function-name + - match: test\b + scope: storage.type.test.twig + set: test-expression + - include: else-pop + ###[ TWIG FILTERS ]############################################################ filters: @@ -356,14 +383,21 @@ contexts: ###[ TWIG FUNCTION CALLS ]##################################################### functions: + - match: (?={{identifiers}}\() + push: + - function-arguments + - function-name + + function-name: # builtin functions - - match: '{{builtin_functions}}(?=\()' + - match: '{{builtin_functions}}' scope: meta.function-call.identifier.twig support.function.twig - push: function-arguments + pop: 1 # custom functions - - match: \w+(?=\() + - match: '{{identifiers}}' scope: meta.function-call.identifier.twig variable.function.twig - push: function-arguments + pop: 1 + - include: else-pop function-arguments: - match: \(