Skip to content

Commit c784ca4

Browse files
Merge pull request #173 from msftrncs/fixQuotedStringIssues
Fix and enhance mulitple quoted string issues
2 parents 4a0a076 + f5dfc7b commit c784ca4

File tree

2 files changed

+71
-27
lines changed

2 files changed

+71
-27
lines changed

PowerShellSyntax.tmLanguage

+51-24
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</dict>
102102
<dict>
103103
<key>begin</key>
104-
<string>(?&lt;!')'</string>
104+
<string>['\x{2018}-\x{201B}]</string>
105105
<key>beginCaptures</key>
106106
<dict>
107107
<key>0</key>
@@ -111,7 +111,9 @@
111111
</dict>
112112
</dict>
113113
<key>end</key>
114-
<string>'(?!')</string>
114+
<string>['\x{2018}-\x{201B}]</string>
115+
<key>applyEndPatternLast</key>
116+
<true/>
115117
<key>endCaptures</key>
116118
<dict>
117119
<key>0</key>
@@ -126,17 +128,33 @@
126128
<array>
127129
<dict>
128130
<key>match</key>
129-
<string>''</string>
131+
<string>['\x{2018}-\x{201B}]{2}</string>
130132
<key>name</key>
131133
<string>constant.character.escape.powershell</string>
132134
</dict>
133135
</array>
134136
</dict>
135137
<dict>
136138
<key>begin</key>
137-
<string>\@"(?=$)</string>
139+
<string>(@["\x{201C}-\x{201E}])\s*$</string>
140+
<key>beginCaptures</key>
141+
<dict>
142+
<key>1</key>
143+
<dict>
144+
<key>name</key>
145+
<string>punctuation.definition.string.begin.powershell</string>
146+
</dict>
147+
</dict>
138148
<key>end</key>
139-
<string>^"@</string>
149+
<string>^["\x{201C}-\x{201E}]@</string>
150+
<key>endCaptures</key>
151+
<dict>
152+
<key>0</key>
153+
<dict>
154+
<key>name</key>
155+
<string>punctuation.definition.string.end.powershell</string>
156+
</dict>
157+
</dict>
140158
<key>name</key>
141159
<string>string.quoted.double.heredoc.powershell</string>
142160
<key>patterns</key>
@@ -157,20 +175,27 @@
157175
</dict>
158176
<dict>
159177
<key>begin</key>
160-
<string>\@'(?=$)</string>
178+
<string>(@['\x{2018}-\x{201B}])\s*$</string>
179+
<key>beginCaptures</key>
180+
<dict>
181+
<key>1</key>
182+
<dict>
183+
<key>name</key>
184+
<string>punctuation.definition.string.begin.powershell</string>
185+
</dict>
186+
</dict>
161187
<key>end</key>
162-
<string>^'@</string>
163-
<key>name</key>
164-
<string>string.quoted.single.heredoc.powershell</string>
165-
<key>patterns</key>
166-
<array>
188+
<string>^['\x{2018}-\x{201B}]@</string>
189+
<key>endCaptures</key>
190+
<dict>
191+
<key>0</key>
167192
<dict>
168-
<key>match</key>
169-
<string>''</string>
170193
<key>name</key>
171-
<string>constant.character.escape.powershell</string>
194+
<string>punctuation.definition.string.end.powershell</string>
172195
</dict>
173-
</array>
196+
</dict>
197+
<key>name</key>
198+
<string>string.quoted.single.heredoc.powershell</string>
174199
</dict>
175200
<dict>
176201
<key>include</key>
@@ -593,20 +618,14 @@
593618
<array>
594619
<dict>
595620
<key>match</key>
596-
<string>`[`0abefnrtv"'$]</string>
621+
<string>`[`0abefnrtv'"\x{2018}-\x{201E}$]</string>
597622
<key>name</key>
598623
<string>constant.character.escape.powershell</string>
599624
</dict>
600625
<dict>
601626
<key>include</key>
602627
<string>#unicodeEscape</string>
603628
</dict>
604-
<dict>
605-
<key>match</key>
606-
<string>""</string>
607-
<key>name</key>
608-
<string>constant.character.escape.powershell</string>
609-
</dict>
610629
</array>
611630
</dict>
612631
<key>unicodeEscape</key>
@@ -1516,7 +1535,7 @@
15161535
<key>doubleQuotedString</key>
15171536
<dict>
15181537
<key>begin</key>
1519-
<string>(?&lt;!(?&lt;!`)")"</string>
1538+
<string>["\x{201C}-\x{201E}]</string>
15201539
<key>beginCaptures</key>
15211540
<dict>
15221541
<key>0</key>
@@ -1526,7 +1545,9 @@
15261545
</dict>
15271546
</dict>
15281547
<key>end</key>
1529-
<string>"(?!")</string>
1548+
<string>["\x{201C}-\x{201E}]</string>
1549+
<key>applyEndPatternLast</key>
1550+
<true/>
15301551
<key>endCaptures</key>
15311552
<dict>
15321553
<key>0</key>
@@ -1551,6 +1572,12 @@
15511572
<key>include</key>
15521573
<string>#doubleQuotedStringEscapes</string>
15531574
</dict>
1575+
<dict>
1576+
<key>match</key>
1577+
<string>["\x{201C}-\x{201E}]{2}</string>
1578+
<key>name</key>
1579+
<string>constant.character.escape.powershell</string>
1580+
</dict>
15541581
<dict>
15551582
<key>include</key>
15561583
<string>#interpolation</string>

spec/testfiles/syntax_test_TheBigTestFile.ps1

+20-3
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,38 @@ $a3[1..2]
379379
"This 'string' is nice."
380380
# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
381381

382-
# Double quoted here-string
383-
@"
382+
# Double quoted here-string, white space at end of start token allowed
383+
@"
384384
# <- string.quoted.double.heredoc.powershell
385385
# <- string.quoted.double.heredoc.powershell
386386
$This is a 'double quoted'
387387
# <- punctuation.definition.variable.powershell
388388
# ^ string.quoted.double.heredoc.powershell support.variable.automatic.powershell
389-
Isn't it "nice"??
389+
Isn't it ""nice""??
390+
# ^^ not:constant.character.escape.powershell
390391
There is no @platting here!
391392
# ^ not:punctuation.definition.variable.powershell
392393
# ^ not:variable.other.readwrite.powershell
393394
"@
394395
# <- string.quoted.double.heredoc.powershell
395396
# <- string.quoted.double.heredoc.powershell
396397

398+
# Single quoted here-string, white space at end of start token allowed
399+
@'
400+
# <- string.quoted.single.heredoc.powershell
401+
# <- string.quoted.single.heredoc.powershell
402+
$This is a ''single quoted''
403+
# ^^ not:constant.character.escape.powershell
404+
# <- not:punctuation.definition.variable.powershell
405+
# ^ string.quoted.single.heredoc.powershell not:support.variable.automatic.powershell
406+
Isn't it "nice"??
407+
There is no @platting here!
408+
# ^ not:punctuation.definition.variable.powershell
409+
# ^ not:variable.other.readwrite.powershell
410+
'@
411+
# <- string.quoted.single.heredoc.powershell
412+
# <- string.quoted.single.heredoc.powershell
413+
397414
# Numeric constants
398415
-3
399416
# ^^ constant.numeric.integer.powershell

0 commit comments

Comments
 (0)