Skip to content

Commit 661386a

Browse files
authored
Fix incorrect predicate usage in PowerShell lexer (#1536)
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.
1 parent 45c3f41 commit 661386a

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/rouge/lexers/powershell.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,20 @@ class Powershell < RegexLexer
201201
rule %r/(?:#{KEYWORDS})\b(?![-.])/i, Keyword::Reserved
202202

203203
rule %r/-{1,2}\w+/, Name::Tag
204-
204+
205205
rule %r/(\.)?([-\w]+)(\[)/ do |m|
206206
groups Operator, Name::Function, Punctuation
207207
push :bracket
208208
end
209209

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

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

220220
rule %r/[-+*\/%=!.&|]/, Operator

spec/visual/samples/powershell

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ Function Get-IPv4Scopes
188188

189189
} #end function
190190

191+
Write-Output "Updating: $($file.FullName)"
192+
# $content = Get-Content $file.FullName
193+
191194
# Without Error
192195
$gitUserName = "$($userAdObject.Properties['sn']), $($userAdObject.Properties['givenName'])"
193196

0 commit comments

Comments
 (0)