Skip to content

Commit 3a3546d

Browse files
authored
[ShellScript] Fix nested arithmetic groups (#4269)
Fixes #4268 This PR fixes nested groups in arithmetic expressions not being scoped, which causes patterns to fallback to compound command expansion.
1 parent 5060836 commit 3a3546d

File tree

2 files changed

+121
-5
lines changed

2 files changed

+121
-5
lines changed

ShellScript/Bash.sublime-syntax

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,19 +1582,20 @@ contexts:
15821582
- match: \'
15831583
scope: punctuation.definition.quoted.begin.shell
15841584
push: expression-single-quoted-body
1585-
- match: \(
1586-
scope: punctuation.section.group.begin.shell
1587-
push: expression-group-body
1585+
- include: expression-groups
15881586
- include: expression-common
15891587

15901588
expression-double-quoted-body:
15911589
- match: \"
15921590
scope: punctuation.definition.quoted.end.shell
15931591
pop: 1
1592+
- include: expression-double-quoted-groups
1593+
- include: expression-common
1594+
1595+
expression-double-quoted-groups:
15941596
- match: \(
15951597
scope: punctuation.section.group.begin.shell
15961598
push: expression-double-quoted-group-body
1597-
- include: expression-common
15981599

15991600
expression-double-quoted-group-body:
16001601
- meta_scope: meta.group.shell
@@ -1603,16 +1604,20 @@ contexts:
16031604
pop: 1
16041605
- match: (?=")
16051606
pop: 1
1607+
- include: expression-double-quoted-groups
16061608
- include: expression-common
16071609

16081610
expression-single-quoted-body:
16091611
- match: \'
16101612
scope: punctuation.definition.quoted.end.shell
16111613
pop: 1
1614+
- include: expression-single-quoted-groups
1615+
- include: expression-common
1616+
1617+
expression-single-quoted-groups:
16121618
- match: \(
16131619
scope: punctuation.section.group.begin.shell
16141620
push: expression-single-quoted-group-body
1615-
- include: expression-common
16161621

16171622
expression-single-quoted-group-body:
16181623
- meta_scope: meta.group.shell
@@ -1621,13 +1626,20 @@ contexts:
16211626
pop: 1
16221627
- match: (?=')
16231628
pop: 1
1629+
- include: expression-single-quoted-groups
16241630
- include: expression-common
16251631

1632+
expression-groups:
1633+
- match: \(
1634+
scope: punctuation.section.group.begin.shell
1635+
push: expression-group-body
1636+
16261637
expression-group-body:
16271638
- meta_scope: meta.group.shell
16281639
- match: \)
16291640
scope: punctuation.section.group.end.shell
16301641
pop: 1
1642+
- include: expression-groups
16311643
- include: expression-common
16321644

16331645
expression-common:

ShellScript/Bash/tests/syntax_test_scope.bash

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13380,6 +13380,110 @@ ip=10.10.20.14
1338013380
((a+=b))
1338113381
# ^ - string.unquoted
1338213382

13383+
(( val = ( a - ( b * c + ( d - e ) ) ) / "d" ))
13384+
#^ meta.compound.arithmetic.shell - meta.arithmetic
13385+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.compound.arithmetic.shell meta.arithmetic.shell
13386+
# ^^ meta.compound.arithmetic.shell - meta.arithmetic
13387+
# ^^^^^^^ - meta.group
13388+
# ^^^^^^ meta.group.shell - meta.group meta.group
13389+
# ^^^^^^^^^^ meta.group.shell meta.group.shell - meta.group meta.group meta.group
13390+
# ^^^^^^^^^ meta.group.shell meta.group.shell meta.group.shell
13391+
# ^^ meta.group.shell meta.group.shell - meta.group meta.group meta.group
13392+
# ^^ meta.group.shell - meta.group meta.group
13393+
# ^^^^^^^ - meta.group
13394+
#^ punctuation.section.compound.begin.shell
13395+
# ^^^ variable.other.readwrite.shell
13396+
# ^ keyword.operator.assignment.shell
13397+
# ^ punctuation.section.group.begin.shell
13398+
# ^ variable.other.readwrite.shell
13399+
# ^ keyword.operator.arithmetic.shell
13400+
# ^ punctuation.section.group.begin.shell
13401+
# ^ variable.other.readwrite.shell
13402+
# ^ keyword.operator.arithmetic.shell
13403+
# ^ variable.other.readwrite.shell
13404+
# ^ keyword.operator.arithmetic.shell
13405+
# ^ punctuation.section.group.begin.shell
13406+
# ^ variable.other.readwrite.shell
13407+
# ^ keyword.operator.arithmetic.shell
13408+
# ^ variable.other.readwrite.shell
13409+
# ^ punctuation.section.group.end.shell
13410+
# ^ punctuation.section.group.end.shell
13411+
# ^ punctuation.section.group.end.shell
13412+
# ^ keyword.operator.arithmetic.shell
13413+
# ^ punctuation.definition.quoted.begin.shell
13414+
# ^ variable.other.readwrite.shell
13415+
# ^ punctuation.definition.quoted.end.shell
13416+
# ^^ punctuation.section.compound.end.shell
13417+
13418+
(( val = '( a - ( b * c + ( d - e ) ) ) / d' ))
13419+
#^ meta.compound.arithmetic.shell - meta.arithmetic
13420+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.compound.arithmetic.shell meta.arithmetic.shell
13421+
# ^^ meta.compound.arithmetic.shell - meta.arithmetic
13422+
# ^^^^^^^^ - meta.group
13423+
# ^^^^^^ meta.group.shell - meta.group meta.group
13424+
# ^^^^^^^^^^ meta.group.shell meta.group.shell - meta.group meta.group meta.group
13425+
# ^^^^^^^^^ meta.group.shell meta.group.shell meta.group.shell
13426+
# ^^ meta.group.shell meta.group.shell - meta.group meta.group meta.group
13427+
# ^^ meta.group.shell - meta.group meta.group
13428+
# ^^^^^^ - meta.group
13429+
#^ punctuation.section.compound.begin.shell
13430+
# ^^^ variable.other.readwrite.shell
13431+
# ^ keyword.operator.assignment.shell
13432+
# ^ punctuation.definition.quoted.begin.shell
13433+
# ^ punctuation.section.group.begin.shell
13434+
# ^ variable.other.readwrite.shell
13435+
# ^ keyword.operator.arithmetic.shell
13436+
# ^ punctuation.section.group.begin.shell
13437+
# ^ variable.other.readwrite.shell
13438+
# ^ keyword.operator.arithmetic.shell
13439+
# ^ variable.other.readwrite.shell
13440+
# ^ keyword.operator.arithmetic.shell
13441+
# ^ punctuation.section.group.begin.shell
13442+
# ^ variable.other.readwrite.shell
13443+
# ^ keyword.operator.arithmetic.shell
13444+
# ^ variable.other.readwrite.shell
13445+
# ^ punctuation.section.group.end.shell
13446+
# ^ punctuation.section.group.end.shell
13447+
# ^ punctuation.section.group.end.shell
13448+
# ^ keyword.operator.arithmetic.shell
13449+
# ^ variable.other.readwrite.shell
13450+
# ^ punctuation.definition.quoted.end.shell
13451+
# ^^ punctuation.section.compound.end.shell
13452+
13453+
(( val = "( a - ( b * c + ( d - e ) ) ) / d" ))
13454+
#^ meta.compound.arithmetic.shell - meta.arithmetic
13455+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.compound.arithmetic.shell meta.arithmetic.shell
13456+
# ^^ meta.compound.arithmetic.shell - meta.arithmetic
13457+
# ^^^^^^^^ - meta.group
13458+
# ^^^^^^ meta.group.shell - meta.group meta.group
13459+
# ^^^^^^^^^^ meta.group.shell meta.group.shell - meta.group meta.group meta.group
13460+
# ^^^^^^^^^ meta.group.shell meta.group.shell meta.group.shell
13461+
# ^^ meta.group.shell meta.group.shell - meta.group meta.group meta.group
13462+
# ^^ meta.group.shell - meta.group meta.group
13463+
# ^^^^^^ - meta.group
13464+
#^ punctuation.section.compound.begin.shell
13465+
# ^^^ variable.other.readwrite.shell
13466+
# ^ keyword.operator.assignment.shell
13467+
# ^ punctuation.definition.quoted.begin.shell
13468+
# ^ punctuation.section.group.begin.shell
13469+
# ^ variable.other.readwrite.shell
13470+
# ^ keyword.operator.arithmetic.shell
13471+
# ^ punctuation.section.group.begin.shell
13472+
# ^ variable.other.readwrite.shell
13473+
# ^ keyword.operator.arithmetic.shell
13474+
# ^ variable.other.readwrite.shell
13475+
# ^ keyword.operator.arithmetic.shell
13476+
# ^ punctuation.section.group.begin.shell
13477+
# ^ variable.other.readwrite.shell
13478+
# ^ keyword.operator.arithmetic.shell
13479+
# ^ variable.other.readwrite.shell
13480+
# ^ punctuation.section.group.end.shell
13481+
# ^ punctuation.section.group.end.shell
13482+
# ^ punctuation.section.group.end.shell
13483+
# ^ keyword.operator.arithmetic.shell
13484+
# ^ variable.other.readwrite.shell
13485+
# ^ punctuation.definition.quoted.end.shell
13486+
# ^^ punctuation.section.compound.end.shell
1338313487

1338413488
###############################################################################
1338513489
# 7.1 Job Control Basics #

0 commit comments

Comments
 (0)