Skip to content

Commit be7b538

Browse files
committed
quoted string regex improvements
1 parent 903782b commit be7b538

File tree

1 file changed

+79
-13
lines changed

1 file changed

+79
-13
lines changed

PowerShellSyntax.tmLanguage

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,7 +2714,7 @@
27142714
<key>comment</key>
27152715
<string>patterns that indicate an expression, might be able to simplify this to include expression_mode and then see if the cursor advanced, sorta, don't forget about 'notCode', maybe check operand/operator only first, as redirect could also be a problem.</string>
27162716
<key>begin</key>
2717-
<string>(?=[$@][{(\w:$?^]|[({]|[,\["\x{201C}-\x{201E}'\x{2018}-\x{201B}])|(?=@?(['\x{2018}-\x{201B}"\x{201C}-\x{201E}])(?:(?&lt;!@\g&lt;1&gt;)|\s*$))|(?=[\x{2013}-\x{2015}-][\s#{(,;|)}&lt;&gt;.!+%*/="\x{201C}-\x{201E}'\x{2018}-\x{201B}\x{2013}-\x{2015}-])</string>
2717+
<string>(?=[$@][{(\w:$?^]|[({\[,]|@?['"\x{2018}-\x{201E}]|[\x{2013}-\x{2015}-][\s#{(,;|)}&lt;&gt;.!+%*/='"\x{2018}-\x{201E}\x{2013}-\x{2015}-])</string>
27182718
<key>end</key>
27192719
<string>$(?=\n)|(?=[;)}\]])</string>
27202720
<key>patterns</key>
@@ -3079,15 +3079,15 @@
30793079
</dict>
30803080
<dict>
30813081
<key>match</key>
3082-
<string>\.(?=['\x{2018}-\x{201B}"\x{201C}-\x{201E}\s{(,;&amp;|)}$])</string>
3082+
<string>\.(?=['"\x{2018}-\x{201E}\s{(,;&amp;|)}$])</string>
30833083
<key>name</key>
30843084
<string>string.unquoted.argument.powershell</string>
30853085
</dict>
30863086
<dict>
30873087
<key>begin</key>
30883088
<string>(?=[^\s{(,;&amp;|)}])</string>
30893089
<key>alternateBegin</key>
3090-
<string>(?=[^'\x{2018}-\x{201B}"\x{201C}-\x{201E}\s\[{(,;&amp;|)}$@])|(?&lt;=\S)(?=[$@&lt;&gt;])</string>
3090+
<string>(?=[^'"\x{2018}-\x{201E}\s\[{(,;&amp;|)}$@])|(?&lt;=\S)(?=[$@&lt;&gt;])</string>
30913091
<key>end</key>
30923092
<string>(?=[\s{(,;&amp;|)}])</string>
30933093
<key>contentName</key>
@@ -3906,7 +3906,7 @@
39063906
<array>
39073907
<dict>
39083908
<key>match</key>
3909-
<string>`[`0abefnrtv"\x{201C}-\x{201E}'\x{2018}-\x{201B}$]</string>
3909+
<string>`[`0abefnrtv]|^`["\x{201C}-\x{201E}](?=@)</string>
39103910
<key>name</key>
39113911
<string>constant.character.escape.powershell</string>
39123912
</dict>
@@ -6343,17 +6343,21 @@
63436343
</dict>
63446344
<key>quotedStrings_Members</key>
63456345
<dict>
6346+
<key>comment</key>
6347+
<string>detect all quoted strings (arguments or expressions) starting here</string>
63466348
<key>begin</key>
6347-
<string>(?=@?(['\x{2018}-\x{201B}"\x{201C}-\x{201E}])(?:(?&lt;!@\g&lt;1&gt;)|\s*$))</string>
6349+
<string>(?=@?['"\x{2018}-\x{201E}])</string>
63486350
<key>end</key>
63496351
<string>(?!\G)</string>
63506352
<key>applyEndPatternLast</key>
63516353
<true/>
63526354
<key>patterns</key>
63536355
<array>
63546356
<dict>
6357+
<key>comment</key>
6358+
<string>single quoted strings</string>
63556359
<key>begin</key>
6356-
<string>['\x{2018}-\x{201B}]</string>
6360+
<string>\G['\x{2018}-\x{201B}]</string>
63576361
<key>beginCaptures</key>
63586362
<dict>
63596363
<key>0</key>
@@ -6387,11 +6391,41 @@
63876391
</array>
63886392
</dict>
63896393
<dict>
6394+
<key>comment</key>
6395+
<string>double quoted here-strings</string>
63906396
<key>begin</key>
6391-
<string>@(?:["\x{201C}-\x{201E}])(?=\s*$)</string>
6397+
<string>\G@["\x{201C}-\x{201E}]</string>
6398+
<key>beginCaptures</key>
6399+
<dict>
6400+
<key>0</key>
6401+
<dict>
6402+
<key>name</key>
6403+
<string>string.quoted.double.heredoc.powershell punctuation.definition.heredoc.begin.powershell</string>
6404+
</dict>
6405+
</dict>
63926406
<key>end</key>
6393-
<string>^(?:["\x{201C}-\x{201E}])@</string>
6394-
<key>name</key>
6407+
<string>^(["\x{201C}-\x{201E}]@)|\G((?:\s*\S+)+)(?:(?!\n)\s)*$</string>
6408+
<key>endCaptures</key>
6409+
<dict>
6410+
<key>1</key>
6411+
<dict>
6412+
<key>name</key>
6413+
<string>string.quoted.double.heredoc.powershell punctuation.definition.heredoc.end.powershell</string>
6414+
</dict>
6415+
<key>2</key>
6416+
<dict>
6417+
<key>patterns</key>
6418+
<array>
6419+
<dict>
6420+
<key>match</key>
6421+
<string>\S+</string>
6422+
<key>name</key>
6423+
<string>invalid.source.powershell</string>
6424+
</dict>
6425+
</array>
6426+
</dict>
6427+
</dict>
6428+
<key>contentName</key>
63956429
<string>string.quoted.double.heredoc.powershell</string>
63966430
<key>patterns</key>
63976431
<array>
@@ -6410,16 +6444,48 @@
64106444
</array>
64116445
</dict>
64126446
<dict>
6447+
<key>comment</key>
6448+
<string>single quoted here-strings</string>
64136449
<key>begin</key>
6414-
<string>@['\x{2018}-\x{201B}](?=\s*$)</string>
6450+
<string>\G@['\x{2018}-\x{201B}]</string>
6451+
<key>beginCaptures</key>
6452+
<dict>
6453+
<key>0</key>
6454+
<dict>
6455+
<key>name</key>
6456+
<string>string.quoted.single.heredoc.powershell punctuation.definition.heredoc.begin.powershell</string>
6457+
</dict>
6458+
</dict>
64156459
<key>end</key>
6416-
<string>^['\x{2018}-\x{201B}]@</string>
6417-
<key>name</key>
6460+
<string>^(['\x{2018}-\x{201B}]@)|\G((?:\s*\S+)+)(?:(?!\n)\s)*$</string>
6461+
<key>endCaptures</key>
6462+
<dict>
6463+
<key>1</key>
6464+
<dict>
6465+
<key>name</key>
6466+
<string>string.quoted.single.heredoc.powershell punctuation.definition.heredoc.end.powershell</string>
6467+
</dict>
6468+
<key>2</key>
6469+
<dict>
6470+
<key>patterns</key>
6471+
<array>
6472+
<dict>
6473+
<key>match</key>
6474+
<string>\S+</string>
6475+
<key>name</key>
6476+
<string>invalid.source.powershell</string>
6477+
</dict>
6478+
</array>
6479+
</dict>
6480+
</dict>
6481+
<key>contentName</key>
64186482
<string>string.quoted.single.heredoc.powershell</string>
64196483
</dict>
64206484
<dict>
6485+
<key>comment</key>
6486+
<string>double quoted strings</string>
64216487
<key>begin</key>
6422-
<string>(?:["\x{201C}-\x{201E}])</string>
6488+
<string>\G(?:["\x{201C}-\x{201E}])</string>
64236489
<key>beginCaptures</key>
64246490
<dict>
64256491
<key>0</key>

0 commit comments

Comments
 (0)