Skip to content

Syntax bug fixes (#68, #77, #84, Range Operator) #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Support/PowershellSyntax.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;!\w)-([ci]?[lg][te]|eq|ne)</string>
<string>(?&lt;!\w)-([ci]?[lg][te]|eq|ne)(?!\p{L})</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This incorrectly allows -lexx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevents any letters from following logical operators

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's nice.

<key>name</key>
<string>keyword.operator.logical.powershell</string>
</dict>
Expand Down Expand Up @@ -324,13 +324,19 @@
<string>keyword.operator.other.powershell</string>
</dict>
<dict>
<key>comment</key>
<string>This is very imprecise, is there a syntax for 'must come after...' </string>
<key>match</key>
<string>(?&lt;!\s|^)\.\.(?=\d|\(|\$)</string>
<string>\.\.</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a simple treatment of the Range Operator might be best. Whenever there is .., the parser sees it as the range operator regardless of any issues before and after.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fair enough, since I can't think of any other way to use ..

<key>name</key>
<string>keyword.operator.range.powershell</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax does not correctly capture 1 .. 3 or .5...9. While both examples are valid syntax, the latter example outputs 0 and 1 instead of something with decimals.

</dict>
<dict>
<key>comment</key>
<string>Properties and methods</string>
<key>match</key>
<string>\.(\w)+</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This separates properties and methods from variables. We can probably simplify the variable section some if we decide to stick with this method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would highlight stuff like file.exe

<key>name</key>
<string>entity.name.function.invocation.powershell</string>
</dict>
</array>
<key>repository</key>
<dict>
Expand Down Expand Up @@ -522,7 +528,7 @@
<key>function</key>
<dict>
<key>begin</key>
<string>((?i:function|configuration|workflow))\s+((?:\p{L}|\d|_|-|\.)+)</string>
<string>(?&lt;!-)((?i:function|configuration|workflow))\s+((?:\p{L}|\d|_|-|\.)+)</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks for a - before function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need way more than this. E.g.

Move-Item MyConfiguration MyWorkflow

<key>beginCaptures</key>
<dict>
<key>0</key>
Expand Down
2 changes: 1 addition & 1 deletion tests/pester/SyntaxHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function Test-ScopesEqual
if ($leftScope.Kind -ne $rightScope.Kind)
{
# TODO: what's that??
$bugsExclude = @('entity.name.function*', 'keyword.operator*', 'storage.type*', 'entity.other.attribute-name*', '*constant*')
$bugsExclude = @('entity.name.function*', 'keyword.operator*', 'storage.type*', 'entity.other.attribute-name*', '*constant*', 'support.function.powershell*', 'interpolated.simple.source.powershell*')
foreach ($bug in $bugsExclude)
{
if (($leftScope.Kind -like $bug) -and ($rightScope.Kind -like $bug))
Expand Down
41 changes: 41 additions & 0 deletions tests/samples/test-file.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,44 @@ function Get-EscapedPath
return $path
}
}

# Logical Operators should now allow following letters
-lexx
-ltxx
-gexx
-gtxx
-clexx
-cltxx
-cgexx
-cgtxx
-ilexx
-iltxx
-igexx
-igtxx

-le
-lt
-ge
-gt
-cle
-clt
-cge
-cgt
-ile
-ilt
-ige
-igt

# Range Operators should work with spaces around them and with trailing decimals
1 .. 3
.5...9

# Methods and properties should be highlighted consistently
($foo).bar
$foo.bar
$foo.bar()
$foo.bar().Length
$a.b.c().d

# Function as a parameter
Export-ModuleMember -Function Get-AllDscEvents, Trace-xDscOperation, Get-xDscOperation