Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Fix incorrect predicate usage in PowerShell lexer (rouge-ruby#1536)
Browse files Browse the repository at this point in the history
The PowerShell lexer includes rules that use the existence of a nil
value in a regular expression to decide whether to push new states onto
the stack. The predicates for these rules were written incorrectly.
This commit removes one of the predicates (which wasn't necessary) and
uses `Object#nil?` in the other to match correctly.
  • Loading branch information
pyrmont authored and mattt committed May 19, 2021
1 parent ce27761 commit 6b61059
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rouge/lexers/powershell.rb
Expand Up @@ -201,20 +201,20 @@ class Powershell < RegexLexer
rule %r/(?:#{KEYWORDS})\b(?![-.])/i, Keyword::Reserved

rule %r/-{1,2}\w+/, Name::Tag

rule %r/(\.)?([-\w]+)(\[)/ do |m|
groups Operator, Name::Function, Punctuation
push :bracket
end

rule %r/([\/\\~\w][-.:\/\\~\w]*)(\n)?/ do |m|
groups Name::Function, Text::Whitespace
push :parameters unless m[2]
push :parameters
end

rule %r/(\.)?([-\w]+)(?:(\()|(\n))?/ do |m|
groups Operator, Name::Function, Punctuation, Text::Whitespace
push :parameters unless m[3]
push :parameters unless m[3].nil?
end

rule %r/[-+*\/%=!.&|]/, Operator
Expand Down
3 changes: 3 additions & 0 deletions spec/visual/samples/powershell
Expand Up @@ -188,6 +188,9 @@ Function Get-IPv4Scopes

} #end function

Write-Output "Updating: $($file.FullName)"
# $content = Get-Content $file.FullName

# Without Error
$gitUserName = "$($userAdObject.Properties['sn']), $($userAdObject.Properties['givenName'])"

Expand Down

0 comments on commit 6b61059

Please sign in to comment.