Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 4f8d7bb

Browse files
committed
Fix heredoc expansion
1 parent b4e9453 commit 4f8d7bb

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

grammars/shell-unix-bash.cson

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@
548548
]
549549
}
550550
{
551-
'begin': '(<<)-\\s*("|\'|)\\s*\\\\?([^;&<\\s]+)\\2'
551+
'begin': '(<<)-\\s*("|\')\\s*\\\\?([^;&<\\s]+)\\2'
552552
'beginCaptures':
553553
'1':
554554
'name': 'keyword.operator.heredoc.shell'
@@ -561,7 +561,7 @@
561561
'name': 'string.unquoted.heredoc.no-indent.shell'
562562
}
563563
{
564-
'begin': '(<<)\\s*("|\'|)\\s*\\\\?([^;&<\\s]+)\\2'
564+
'begin': '(<<)\\s*("|\')\\s*\\\\?([^;&<\\s]+)\\2'
565565
'beginCaptures':
566566
'1':
567567
'name': 'keyword.operator.heredoc.shell'
@@ -573,6 +573,56 @@
573573
'name': 'keyword.control.heredoc-token.shell'
574574
'name': 'string.unquoted.heredoc.shell'
575575
}
576+
{
577+
'begin': '(<<)-\\s*\\\\?([^;&<\\s]+)'
578+
'beginCaptures':
579+
'1':
580+
'name': 'keyword.operator.heredoc.shell'
581+
'2':
582+
'name': 'keyword.control.heredoc-token.shell'
583+
'end': '^\\t*(\\2)(?=\\s|;|&|$)'
584+
'endCaptures':
585+
'1':
586+
'name': 'keyword.control.heredoc-token.shell'
587+
'name': 'string.unquoted.heredoc.expanded.no-indent.shell'
588+
'patterns': [
589+
{
590+
'match': '\\\\[\\$`\\\\\\n]'
591+
'name': 'constant.character.escape.shell'
592+
}
593+
{
594+
'include': '#variable'
595+
}
596+
{
597+
'include': '#interpolation'
598+
}
599+
]
600+
}
601+
{
602+
'begin': '(<<)\\s*\\\\?([^;&<\\s]+)'
603+
'beginCaptures':
604+
'1':
605+
'name': 'keyword.operator.heredoc.shell'
606+
'2':
607+
'name': 'keyword.control.heredoc-token.shell'
608+
'end': '^(\\2)(?=\\s|;|&|$)'
609+
'endCaptures':
610+
'1':
611+
'name': 'keyword.control.heredoc-token.shell'
612+
'name': 'string.unquoted.heredoc.expanded.shell'
613+
'patterns': [
614+
{
615+
'match': '\\\\[\\$`\\\\\\n]'
616+
'name': 'constant.character.escape.shell'
617+
}
618+
{
619+
'include': '#variable'
620+
}
621+
{
622+
'include': '#interpolation'
623+
}
624+
]
625+
}
576626
]
577627
'herestring':
578628
'patterns': [

spec/shell-unix-bash-spec.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ describe "Shell script grammar", ->
220220
stuff
221221
#{delim}
222222
"""
223-
expect(tokens[0][0]).toEqual value: '<<', scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.operator.heredoc.shell']
224-
expect(tokens[0][1]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.control.heredoc-token.shell']
225-
expect(tokens[1][0]).toEqual value: 'stuff', scopes: ['source.shell', 'string.unquoted.heredoc.shell']
226-
expect(tokens[2][0]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.control.heredoc-token.shell']
223+
expect(tokens[0][0]).toEqual value: '<<', scopes: ['source.shell', 'string.unquoted.heredoc.expanded.shell', 'keyword.operator.heredoc.shell']
224+
expect(tokens[0][1]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.expanded.shell', 'keyword.control.heredoc-token.shell']
225+
expect(tokens[1][0]).toEqual value: 'stuff', scopes: ['source.shell', 'string.unquoted.heredoc.expanded.shell']
226+
expect(tokens[2][0]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.expanded.shell', 'keyword.control.heredoc-token.shell']
227227
228228
for delim in delims
229229
tokens = grammar.tokenizeLines """

0 commit comments

Comments
 (0)