From 18caba2e8ab512846cf2cdda8d920265ead69639 Mon Sep 17 00:00:00 2001 From: "Buick, Thomas | Tom | MCPD" Date: Fri, 22 Sep 2023 14:00:02 +0900 Subject: [PATCH] Further tidy up language syntax - Removes all anonymous contexts - Properly handles parentheses within interpolated strings --- JQ.sublime-syntax | 42 ++++++++++++++++++++++++------------------ syntax_test_jq.jq | 11 +++++------ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/JQ.sublime-syntax b/JQ.sublime-syntax index a752593..5759640 100644 --- a/JQ.sublime-syntax +++ b/JQ.sublime-syntax @@ -213,31 +213,37 @@ contexts: - meta_scope: string.quoted.double.jq - match: '\\\(' scope: constant.character.escape.begin_interp.jq - push: - - clear_scopes: true - - match: '\(' - push: - - meta_scope: meta.block.parenthesis.jq - - match: \) - pop: true - - - match: \) - scope: constant.character.escape.end_interp.jq - pop: true + push: inside_interp - match: '(\\)' captures: 1: constant.character.escape.jq - push: - - meta_scope: meta.escape.sequence.jq - - match: "(.)" - captures: - 1: constant.character.escape.escaped.jq - pop: true - + push: string_escape_sequence - match: '"' scope: punctuation.definition.string.end.jq pop: true + string_escape_sequence: + - meta_scope: meta.escape.sequence.jq + - match: "(.)" + captures: + 1: constant.character.escape.escaped.jq + pop: true + + inside_interp: + - meta_scope: source.interp.jq + - clear_scopes: true + - match: '\(' + push: inside_interp_parens + - match: \) + scope: constant.character.escape.end_interp.jq + pop: true + + inside_interp_parens: + - match: '\(' + push: inside_interp_parens + - match: '\)' + pop: true + comments: - match: '#' scope: punctuation.definition.comment.jq diff --git a/syntax_test_jq.jq b/syntax_test_jq.jq index 20503b5..6296915 100644 --- a/syntax_test_jq.jq +++ b/syntax_test_jq.jq @@ -65,18 +65,17 @@ def keys($value; $value; test): ; # <- punctuation.terminator.jq -{ array: [1, 2, 3 ,4] } | @json "My string with eval: \( .array | ( . | . += 1 ) )" +{ array: [1, 2, 3 ,4] } | @json "My string with eval: \( .array | ( . | . += (1 + 2) ) )." # <- meta.block.in_brace.jq - meta.block.in_brace.jq meta.block.in_brace.jq # ^ meta.block.in_bracket.jq # ^ - meta.block.in_bracket.jq # ^^^^^ constant.language.format.jq # ^^^^^^^^^^^^^^^^^^^^^^ source.jq string.quoted.double.jq -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - source.jq string.quoted.double.jq -# ^ source.jq string.quoted.double.jq +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.interp.jq - source.jq string.quoted.double.jq +# ^ source.jq string.quoted.double.jq +# ^ source.jq string.quoted.double.jq # ^^ constant.character.escape.begin_interp.jq -# ^ constant.character.escape.end_interp.jq -# ^^^^^^^^^^^^^^ meta.block.parenthesis.jq - +# ^ constant.character.escape.end_interp.jq {i:0} | while(.i < 10 ; .i += 1) # ^^^^^ keyword.control.flow.jq