Skip to content
Open
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
5 changes: 5 additions & 0 deletions assets/highlighting-tests/powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ Write-Host "2 + 2 = $($array[0] + $array[1])"
# Command substitution
$pwdPath = $(Get-Location).Path
Write-Host "Current directory: $pwdPath"

# Commands and operators that begin with a keyword
Get-ChildItem | ForEach-Object { $_.Name } | Format-Table
Invoke-WebRequest -Uri "https://example.com"
if (42 -in $array) { Exit-PSSession }
7 changes: 5 additions & 2 deletions crates/lsh/definitions/powershell.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub fn powershell() {
else if /"/ { yield string; break; }
await input;
}
} else if /[\w\d?:]+-[\w\d?:-]*/ {
// Commands like ForEach-Object or Invoke-WebRequest, which may begin with a keyword
yield method;
} else if /-[a-zA-Z]\w*/ {
// Operators and parameters like -in or -Path, which may contain a keyword
} else if /(?i:begin|class|clean|data|define|dynamicparam|end|enum|filter|from|function|hidden|in|param|process|static|using|var)/ {
if /\w+/ {
yield other;
Expand All @@ -75,8 +80,6 @@ pub fn powershell() {
}
} else if /[$@][\w\d?:]+/ {
yield variable;
} else if /[\w\d?:]+-[\w\d?:-]*/ {
yield method;
} else if /[\w\d?:]+/ {
// Gobble any other tokens that should not be highlighted
}
Expand Down