Skip to content
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

Support using grave character to escape characters in PowerShell lexer #1551

Merged
merged 4 commits into from
Jul 4, 2020
Merged
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
1 change: 1 addition & 0 deletions lib/rouge/lexers/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class Powershell < RegexLexer
end

state :parameters do
rule %r/`./m, Str::Escape
rule %r/\s*?\n/, Text::Whitespace, :pop!
rule %r/[;(){}\]]/, Punctuation, :pop!
rule %r/[|=]/, Operator, :pop!
Expand Down
13 changes: 8 additions & 5 deletions spec/visual/samples/powershell
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ process {
}

###########################
# Control structures
# Control structures
###########################

if ($var1 -eq $var2)
Expand All @@ -114,15 +114,15 @@ Foreach ($Thing in $Things ) {
}

###########################
# Classes
# Classes
###########################

class Child : Parent, Relatives {
[int] hidden $var = 8

Child ([string]$a, [string]$b, [int]$capacity) {
$this.var = $a
}
}

[string]toString() {
return "A string"
Expand Down Expand Up @@ -194,5 +194,8 @@ Write-Output "Updating: $($file.FullName)"
# Without Error
$gitUserName = "$($userAdObject.Properties['sn']), $($userAdObject.Properties['givenName'])"

# With Error
# Grave escaping
$gitExeString = "$gitExeFolder\git.exe" &("$gitExeString") config --add --global user.name `"$gitUserName`"
Get-ChildItem -Include *.txt `
-Recurse
Write-Output `$hello