Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cb63d43
Fixed line comment to require either new line or at least 1 white spa…
gravejester May 27, 2016
f586c47
Added enum as a reserved word for highlighting. Should partially solv…
gravejester May 27, 2016
098cb8f
Stops 'class' being highlighted wrongly if used as a parameter.
gravejester May 27, 2016
be6300b
Better fix for enum highlighting.
gravejester May 27, 2016
233df30
Added syntax highlighting of parameters. Should fix https://github.co…
gravejester May 27, 2016
b29a436
Added highlighting of 'node' keyword.
gravejester May 27, 2016
d64efcb
Fixes matching in attributes. Should fix https://github.com/SublimeTe…
gravejester May 27, 2016
de590cd
Fixed so class and enum declarations don't match if '-' is used in th…
gravejester May 27, 2016
5c9cac9
Stop Parsing (--%) now also stops highlighting. Should fix https://gi…
gravejester May 27, 2016
a0d2d83
Added shr and shl as bitwise operators. Should fix https://github.com…
gravejester May 27, 2016
731022b
Line comments highlight in function declaration. Should fix https://g…
gravejester May 27, 2016
24a4467
Logical operators don't highlight if not on a word boundary. Should f…
gravejester May 27, 2016
ef59db4
Fixed highlighting of keywords in comment based help. Should fix http…
gravejester May 27, 2016
5585e78
Added example file for testing syntax highlighting rules.
gravejester May 27, 2016
c9579d7
Updated example file.
gravejester May 27, 2016
d2ab16f
Added more test code.
gravejester May 28, 2016
6f667e4
Highlight illegal use of back-tic.
gravejester May 28, 2016
db6fa98
Added 'Role' keyword for comment-based help.
gravejester May 28, 2016
754eccb
Updated test.ps1
gravejester May 28, 2016
affc64f
Fix regressions
gravejester Jun 9, 2016
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
95 changes: 70 additions & 25 deletions PowerShellSyntax.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,39 @@
</dict>
<dict>
<key>begin</key>
<string>(?&lt;![\\-])#</string>
<string>--%</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.powershell</string>
</dict>
</dict>
<key>comment</key>
<string>Stop Parsing</string>
<key>contentName</key>
<string>source.powershell</string>
<key>end</key>
<string>$</string>
<key>name</key>
<string>comment.line.number-sign.powershell</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#commentEmbeddedDocs</string>
<string>#lineComment</string>
</dict>
</array>
</dict>
<dict>
<key>include</key>
<string>#lineComment</string>
</dict>
<dict>
<key>match</key>
<string>(`(?!$))</string>
<key>name</key>
<string>invalid.illegal.powershell</string>
</dict>
<dict>
<key>match</key>
<string>[2-6]&gt;&amp;1|&gt;&gt;|&gt;|&lt;&lt;|&lt;|&gt;|&gt;\||[1-6]&gt;|[1-6]&gt;&gt;</string>
Expand Down Expand Up @@ -234,7 +254,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;!\w)-([ci]?[lg][te]|eq|ne)</string>
<string>(?&lt;!\w)-([ci]?[lg][te]|eq|ne)\b</string>
<key>name</key>
<string>keyword.operator.logical.powershell</string>
</dict>
Expand All @@ -246,7 +266,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;!\w)((?i:begin|break|catch|continue|data|define|do|dynamicparam|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|using|var|where(?!=-object)|while)|%|\?)(?!\w)</string>
<string>(?&lt;!\w)((?i:begin|break|catch|continue|data|define|do|dynamicparam|node|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|using|var|where(?!=-object)|while)|%|\?)(?!\w)</string>
<key>name</key>
<string>keyword.control.powershell</string>
</dict>
Expand All @@ -267,7 +287,7 @@
<key>comment</key>
<string>capture should be entity.name.type, but it doesn't provide a good color in the default schema.</string>
<key>match</key>
<string>(?&lt;!\w)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b</string>
<string>(?&lt;!\w|-)((?i:class|enum)|%|\?)(?:\s)+((?:\p{L}|\d|_|)+)\b</string>
</dict>
<dict>
<key>match</key>
Expand Down Expand Up @@ -295,7 +315,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;!\w)-(?i:band|bor|bnot|bxor)(?!\p{L})</string>
<string>(?&lt;!\w)-(?i:band|bor|bnot|bxor|shr|shl)(?!\p{L})</string>
<key>name</key>
<string>keyword.operator.bitwise.powershell</string>
</dict>
Expand Down Expand Up @@ -400,7 +420,7 @@
</dict>
<dict>
<key>include</key>
<string>#variable</string>
<string>$self</string>
</dict>
</array>
</dict>
Expand Down Expand Up @@ -438,7 +458,7 @@
<key>1</key>
<dict>
<key>name</key>
<string>constant.string.documentation.powershell</string>
<string>keyword.operator.documentation.powershell</string>
</dict>
<key>2</key>
<dict>
Expand All @@ -447,7 +467,7 @@
</dict>
</dict>
<key>match</key>
<string>(?i:\s*(\.)(SYNOPSIS|DESCRIPTION|EXAMPLE|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|FUNCTIONALITY))</string>
<string>(?i:(\.)(SYNOPSIS|DESCRIPTION|EXAMPLE|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|FUNCTIONALITY|ROLE)\b)</string>
<key>name</key>
<string>comment.documentation.embedded.powershell</string>
</dict>
Expand All @@ -457,7 +477,7 @@
<key>1</key>
<dict>
<key>name</key>
<string>constant.string.documentation.powershell</string>
<string>keyword.operator.documentation.powershell</string>
</dict>
<key>2</key>
<dict>
Expand All @@ -467,35 +487,30 @@
<key>3</key>
<dict>
<key>name</key>
<string>keyword.operator.documentation.powershell</string>
<string>constant.string.documentation.powershell</string>
</dict>
</dict>
<key>match</key>
<string>(?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+))</string>
<string>(?i:(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+(.+))</string>
<key>name</key>
<string>comment.documentation.embedded.powershell</string>
</dict>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>constant.string.documentation.powershell</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.operator.documentation.powershell</string>
</dict>
<key>3</key>
<key>2</key>
<dict>
<key>name</key>
<string>string.quoted.double.heredoc.powershell</string>
<string>constant.string.documentation.powershell</string>
</dict>
</dict>
<key>match</key>
<string>(?i:requires\s+-(Version\s+\d(.\d+)?|Assembly\s+(.*)|Module\s+(.*)|PsSnapIn\s+(.*)|ShellId\s+(.*)))</string>
<string>((?i:requires))\s+-(Version\s+\d(?:.\d+)?|Assembly\s+(?:.*)|Module\s+(?:.*)|PsSnapIn\s+(?:.*)|ShellId\s+(?:.*))</string>
<key>name</key>
<string>comment.documentation.embedded.powershell</string>
</dict>
Expand All @@ -522,7 +537,7 @@
<key>function</key>
<dict>
<key>begin</key>
<string>(?&lt;!\S)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+)</string>
<string>(?&lt;!\S)(?i)(function|filter|workflow|configuration)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+)</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand All @@ -548,6 +563,13 @@
</dict>
<key>end</key>
<string>\{|\(</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#lineComment</string>
</dict>
</array>
</dict>
<key>interpolatedStringContent</key>
<dict>
Expand Down Expand Up @@ -629,6 +651,22 @@
</dict>
</array>
</dict>
<key>lineComment</key>
<dict>
<key>begin</key>
<string>(?&lt;![\\-])(?:\s+?|^)#</string>
<key>end</key>
<string>$</string>
<key>name</key>
<string>comment.line.number-sign.powershell</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#commentEmbeddedDocs</string>
</dict>
</array>
</dict>
<key>numericConstant</key>
<dict>
<key>patterns</key>
Expand All @@ -653,7 +691,7 @@
</dict>
</dict>
<key>match</key>
<string>(?&lt;!\w)(?i:(0x)([a-f0-9]+)((?i:L)?(?i:[kmgtp]b)?))(?!\w)</string>
<string>(?&lt;!\w)([-+]?)(?i:(0x)([a-f0-9]+)((?i:L)?(?i:[kmgtp]b)?))(?!\w)</string>
<key>name</key>
<string>constant.numeric.hexadecimal.powershell</string>
</dict>
Expand Down Expand Up @@ -693,6 +731,13 @@
</dict>
</array>
</dict>
<key>parameter</key>
<dict>
<key>match</key>
<string>((?&lt;=\s)-(\w+))</string>
<key>name</key>
<string>variable.parameter.powershell</string>
</dict>
<key>scriptblock</key>
<dict>
<key>begin</key>
Expand Down Expand Up @@ -1183,4 +1228,4 @@
<key>uuid</key>
<string>f8f5ffb0-503e-11df-9879-0800200c9a66</string>
</dict>
</plist>
</plist>
78 changes: 78 additions & 0 deletions examples/advancedFunction.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
.INPUTS
Inputs to this cmdlet (if any)
.OUTPUTS
Output from this cmdlet (if any)
.NOTES
General notes
.COMPONENT
The component this cmdlet belongs to
.ROLE
The role this cmdlet belongs to
.FUNCTIONALITY
The functionality that best describes this cmdlet
#>
function Verb-Noun
{
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
SupportsShouldProcess=$true,
PositionalBinding=$false,
HelpUri = 'http://www.microsoft.com/',
ConfirmImpact='Medium')]
[Alias()]
[OutputType([String])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[ValidateCount(0,5)]
[ValidateSet("sun", "moon", "earth")]
[Alias("p1")]
$Param1,

# Param2 help description
[Parameter(ParameterSetName='Parameter Set 1')]
[AllowNull()]
[AllowEmptyCollection()]
[AllowEmptyString()]
[ValidateScript({$true})]
[ValidateRange(0,5)]
[int]
$Param2,

# Param3 help description
[Parameter(ParameterSetName='Another Parameter Set')]
[ValidatePattern("[a-z]*")]
[ValidateLength(0,15)]
[String]
$Param3
)

Begin
{
}
Process
{
if ($pscmdlet.ShouldProcess("Target", "Operation"))
{
}
}
End
{
}
}
32 changes: 32 additions & 0 deletions examples/class.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Define a class
class TypeName
{
# Property with validate set
[ValidateSet("val1", "Val2")]
[string] $P1

# Static property
static [hashtable] $P2

# Hidden property does not show as result of Get-Member
hidden [int] $P3

# Constructor
TypeName ([string] $s)
{
$this.P1 = $s
}

# Static method
static [void] MemberMethod1([hashtable] $h)
{
[TypeName]::P2 = $h
}

# Instance method
[int] MemberMethod2([int] $i)
{
$this.P3 = $i
return $this.P3
}
}
Loading