Skip to content

Commit

Permalink
Merge pull request #173 from msftrncs/fixQuotedStringIssues
Browse files Browse the repository at this point in the history
Fix and enhance mulitple quoted string issues
  • Loading branch information
andyleejordan committed Mar 17, 2021
2 parents 4a0a076 + f5dfc7b commit c784ca4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 27 deletions.
75 changes: 51 additions & 24 deletions PowerShellSyntax.tmLanguage
Expand Up @@ -101,7 +101,7 @@
</dict>
<dict>
<key>begin</key>
<string>(?&lt;!')'</string>
<string>['\x{2018}-\x{201B}]</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand All @@ -111,7 +111,9 @@
</dict>
</dict>
<key>end</key>
<string>'(?!')</string>
<string>['\x{2018}-\x{201B}]</string>
<key>applyEndPatternLast</key>
<true/>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand All @@ -126,17 +128,33 @@
<array>
<dict>
<key>match</key>
<string>''</string>
<string>['\x{2018}-\x{201B}]{2}</string>
<key>name</key>
<string>constant.character.escape.powershell</string>
</dict>
</array>
</dict>
<dict>
<key>begin</key>
<string>\@"(?=$)</string>
<string>(@["\x{201C}-\x{201E}])\s*$</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.powershell</string>
</dict>
</dict>
<key>end</key>
<string>^"@</string>
<string>^["\x{201C}-\x{201E}]@</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.end.powershell</string>
</dict>
</dict>
<key>name</key>
<string>string.quoted.double.heredoc.powershell</string>
<key>patterns</key>
Expand All @@ -157,20 +175,27 @@
</dict>
<dict>
<key>begin</key>
<string>\@'(?=$)</string>
<string>(@['\x{2018}-\x{201B}])\s*$</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.powershell</string>
</dict>
</dict>
<key>end</key>
<string>^'@</string>
<key>name</key>
<string>string.quoted.single.heredoc.powershell</string>
<key>patterns</key>
<array>
<string>^['\x{2018}-\x{201B}]@</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>match</key>
<string>''</string>
<key>name</key>
<string>constant.character.escape.powershell</string>
<string>punctuation.definition.string.end.powershell</string>
</dict>
</array>
</dict>
<key>name</key>
<string>string.quoted.single.heredoc.powershell</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -593,20 +618,14 @@
<array>
<dict>
<key>match</key>
<string>`[`0abefnrtv"'$]</string>
<string>`[`0abefnrtv'"\x{2018}-\x{201E}$]</string>
<key>name</key>
<string>constant.character.escape.powershell</string>
</dict>
<dict>
<key>include</key>
<string>#unicodeEscape</string>
</dict>
<dict>
<key>match</key>
<string>""</string>
<key>name</key>
<string>constant.character.escape.powershell</string>
</dict>
</array>
</dict>
<key>unicodeEscape</key>
Expand Down Expand Up @@ -1516,7 +1535,7 @@
<key>doubleQuotedString</key>
<dict>
<key>begin</key>
<string>(?&lt;!(?&lt;!`)")"</string>
<string>["\x{201C}-\x{201E}]</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand All @@ -1526,7 +1545,9 @@
</dict>
</dict>
<key>end</key>
<string>"(?!")</string>
<string>["\x{201C}-\x{201E}]</string>
<key>applyEndPatternLast</key>
<true/>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand All @@ -1551,6 +1572,12 @@
<key>include</key>
<string>#doubleQuotedStringEscapes</string>
</dict>
<dict>
<key>match</key>
<string>["\x{201C}-\x{201E}]{2}</string>
<key>name</key>
<string>constant.character.escape.powershell</string>
</dict>
<dict>
<key>include</key>
<string>#interpolation</string>
Expand Down
23 changes: 20 additions & 3 deletions spec/testfiles/syntax_test_TheBigTestFile.ps1
Expand Up @@ -379,21 +379,38 @@ $a3[1..2]
"This 'string' is nice."
# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell

# Double quoted here-string
@"
# Double quoted here-string, white space at end of start token allowed
@"
# <- string.quoted.double.heredoc.powershell
# <- string.quoted.double.heredoc.powershell
$This is a 'double quoted'
# <- punctuation.definition.variable.powershell
# ^ string.quoted.double.heredoc.powershell support.variable.automatic.powershell
Isn't it "nice"??
Isn't it ""nice""??
# ^^ not:constant.character.escape.powershell
There is no @platting here!
# ^ not:punctuation.definition.variable.powershell
# ^ not:variable.other.readwrite.powershell
"@
# <- string.quoted.double.heredoc.powershell
# <- string.quoted.double.heredoc.powershell

# Single quoted here-string, white space at end of start token allowed
@'
# <- string.quoted.single.heredoc.powershell
# <- string.quoted.single.heredoc.powershell
$This is a ''single quoted''
# ^^ not:constant.character.escape.powershell
# <- not:punctuation.definition.variable.powershell
# ^ string.quoted.single.heredoc.powershell not:support.variable.automatic.powershell
Isn't it "nice"??
There is no @platting here!
# ^ not:punctuation.definition.variable.powershell
# ^ not:variable.other.readwrite.powershell
'@
# <- string.quoted.single.heredoc.powershell
# <- string.quoted.single.heredoc.powershell

# Numeric constants
-3
# ^^ constant.numeric.integer.powershell
Expand Down

0 comments on commit c784ca4

Please sign in to comment.