Skip to content

Commit

Permalink
Further tidy up language syntax
Browse files Browse the repository at this point in the history
- Removes all anonymous contexts
- Properly handles parentheses within interpolated strings
  • Loading branch information
rakuten-buickthomas01 committed Sep 22, 2023
1 parent 5121ae5 commit 18caba2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
42 changes: 24 additions & 18 deletions JQ.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions syntax_test_jq.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18caba2

Please sign in to comment.