From b5be4c7f9a17c951be43ab9cb8aa0d5ae2f5aa19 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 3 May 2025 14:46:52 +0200 Subject: [PATCH 1/4] Add syntax for if-expression blocks --- language/syntaxes/expressions.tmGrammar.json | 68 +++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/language/syntaxes/expressions.tmGrammar.json b/language/syntaxes/expressions.tmGrammar.json index 6e4fe28..88cd66c 100644 --- a/language/syntaxes/expressions.tmGrammar.json +++ b/language/syntaxes/expressions.tmGrammar.json @@ -5,6 +5,9 @@ { "include": "#expression" }, + { + "include": "#block-if-expression" + }, { "include": "#if-expression" } @@ -38,8 +41,71 @@ } } }, + "block-if-expression": { + "contentName": "meta.embedded.block.github-actions-expression", + "begin": "^\\s*\\b(if:) (?:(\\|)|(>))([1-9])?([-+])?(.*\\n?)", + "beginCaptures": { + "1": { + "patterns": [ + { + "include": "source.github-actions-workflow" + } + ] + }, + "2": { + "name": "keyword.control.flow.block-scalar.literal.yaml" + }, + "3": { + "name": "keyword.control.flow.block-scalar.folded.yaml" + }, + "4": { + "name": "constant.numeric.indentation-indicator.yaml" + }, + "5": { + "name": "storage.modifier.chomping-indicator.yaml" + }, + "6": { + "patterns": [ + { + "include": "#comment" + }, + { + "match": ".+", + "name": "invalid.illegal.expected-comment-or-newline.yaml" + } + ] + } + }, + "end": "^(?=\\S)|(?!\\G)", + "patterns": [ + { + "begin": "^([ ]+)(?! )", + "end": "^(?!\\1|\\s*$)", + "patterns": [ + { + "include": "#function-call" + }, + { + "include": "#context" + }, + { + "include": "#string" + }, + { + "include": "#number" + }, + { + "include": "#boolean" + }, + { + "include": "#null" + } + ] + } + ] + }, "if-expression": { - "match": "\\b(if:) (.*?)$", + "match": "^\\s*\\b(if:) (.*?)$", "contentName": "meta.embedded.block.github-actions-expression", "captures": { "1": { From 68abdf788e37768d8e3990c39cff34f0fca8ac5e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 3 May 2025 14:50:48 +0200 Subject: [PATCH 2/4] Create unified expression syntax pattern --- language/syntaxes/expressions.tmGrammar.json | 77 +++++++------------- 1 file changed, 27 insertions(+), 50 deletions(-) diff --git a/language/syntaxes/expressions.tmGrammar.json b/language/syntaxes/expressions.tmGrammar.json index 88cd66c..b49627d 100644 --- a/language/syntaxes/expressions.tmGrammar.json +++ b/language/syntaxes/expressions.tmGrammar.json @@ -3,7 +3,7 @@ "injectionSelector": "L:source.github-actions-workflow", "patterns": [ { - "include": "#expression" + "include": "#inline-expression" }, { "include": "#block-if-expression" @@ -13,29 +13,14 @@ } ], "repository": { - "expression": { + "inline-expression": { "match": "[|-]?\\$\\{\\{(.*?)\\}\\}", "name": "meta.embedded.block.github-actions-expression", "captures": { "1": { "patterns": [ { - "include": "#function-call" - }, - { - "include": "#context" - }, - { - "include": "#string" - }, - { - "include": "#number" - }, - { - "include": "#boolean" - }, - { - "include": "#null" + "include": "#expression" } ] } @@ -83,22 +68,7 @@ "end": "^(?!\\1|\\s*$)", "patterns": [ { - "include": "#function-call" - }, - { - "include": "#context" - }, - { - "include": "#string" - }, - { - "include": "#number" - }, - { - "include": "#boolean" - }, - { - "include": "#null" + "include": "#expression" } ] } @@ -118,27 +88,34 @@ "2": { "patterns": [ { - "include": "#function-call" - }, - { - "include": "#context" - }, - { - "include": "#string" - }, - { - "include": "#number" - }, - { - "include": "#boolean" - }, - { - "include": "#null" + "include": "#expression" } ] } } }, + "expression": { + "patterns": [ + { + "include": "#function-call" + }, + { + "include": "#context" + }, + { + "include": "#string" + }, + { + "include": "#number" + }, + { + "include": "#boolean" + }, + { + "include": "#null" + } + ] + }, "function-call": { "patterns": [ { From 8a366bc5147cf943f4595c93e39e55cf0529322c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 3 May 2025 14:54:08 +0200 Subject: [PATCH 3/4] Add patterns for logical and comparison operators --- language/syntaxes/expressions.tmGrammar.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/language/syntaxes/expressions.tmGrammar.json b/language/syntaxes/expressions.tmGrammar.json index b49627d..ab5c80e 100644 --- a/language/syntaxes/expressions.tmGrammar.json +++ b/language/syntaxes/expressions.tmGrammar.json @@ -105,6 +105,12 @@ { "include": "#string" }, + { + "include": "#op-comparison" + }, + { + "include": "#op-logical" + }, { "include": "#number" }, @@ -141,6 +147,14 @@ "begin": "'", "end": "'" }, + "op-comparison": { + "name": "keyword.operator.comparison.github-actions-expression", + "match": "(==|!=)" + }, + "op-logical": { + "name": "keyword.operator.logical.github-actions-expression", + "match": "(&&|\\|\\|)" + }, "number": { "name": "constant.numeric.github-actions-expression", "match": "\\b[0-9]+(?:.[0-9]+)?\\b" From aba9c0fe6d15013ebf1d65d44b9ad188b5da2711 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 3 May 2025 14:55:37 +0200 Subject: [PATCH 4/4] Allow inline expressions to span multiple lines --- language/syntaxes/expressions.tmGrammar.json | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/language/syntaxes/expressions.tmGrammar.json b/language/syntaxes/expressions.tmGrammar.json index ab5c80e..b97c135 100644 --- a/language/syntaxes/expressions.tmGrammar.json +++ b/language/syntaxes/expressions.tmGrammar.json @@ -3,7 +3,7 @@ "injectionSelector": "L:source.github-actions-workflow", "patterns": [ { - "include": "#inline-expression" + "include": "#block-inline-expression" }, { "include": "#block-if-expression" @@ -13,18 +13,15 @@ } ], "repository": { - "inline-expression": { - "match": "[|-]?\\$\\{\\{(.*?)\\}\\}", + "block-inline-expression": { "name": "meta.embedded.block.github-actions-expression", - "captures": { - "1": { - "patterns": [ - { - "include": "#expression" - } - ] + "begin": "[|-]?\\$\\{\\{", + "end": "\\}\\}", + "patterns": [ + { + "include": "#expression" } - } + ] }, "block-if-expression": { "contentName": "meta.embedded.block.github-actions-expression",