PipeScript contains several new language keywords that are not found in PowerShell.
This directory contains the implementations of PipeScript language keywords.
& {
$glitters = @{glitters=$true}
all that glitters
}.Transpile() function mallard([switch]$Quack) { $Quack }
Get-Command mallard | Get-Member | Select-Object -ExpandProperty TypeName -Unique
all functions that quack are ducks
Get-Command mallard | Get-Member | Select-Object -ExpandProperty TypeName -Unique
. {
$numbers = 1..100
$null = all $numbers where { ($_ % 2) -eq 1 } are odd
$null = all $numbers where { ($_ % 2) -eq 0 } are even
}.Transpile()
@(
. { all even $numbers }.Transpile()
).Length
@(
. { all odd $numbers }.Transpile()
).Length # With no second argument, assert will throw an error with the condition of the assertion.
Invoke-PipeScript {
assert (1 -ne 1)
} -Debug # With a second argument of a string, assert will throw an error
Invoke-PipeScript {
assert ($false) "It's not true!"
} -Debug # Conditions can also be written as a ScriptBlock
Invoke-PipeScript {
assert {$false} "Process id '$pid' Asserted"
} -Verbose # If the assertion action was a ScriptBlock, no exception is automatically thrown
Invoke-PipeScript {
assert ($false) { Write-Information "I Assert There Is a Problem"}
} -Verbose # assert can be used with the object pipeline. $_ will be the current object.
Invoke-PipeScript {
1..4 | assert {$_ % 2} "$_ is not odd!"
} -Debug # You can provide a ```[ScriptBlock]``` as the second argument to see each failure
Invoke-PipeScript {
1..4 | assert {$_ % 2} { Write-Error "$_ is not odd!" }
} -Debug .>PipeScript -ScriptBlock {
await $Websocket.SendAsync($SendSegment, 'Binary', $true, [Threading.CancellationToken]::new($false))
} .>PipeScript -ScriptBlock {
$receiveResult = await $Websocket.ReceiveAsync($receiveSegment, [Threading.CancellationToken]::new($false))
} .> { new DateTime } .> { new byte 1 } .> { new int[] 5 } .> { new Timespan } .> { new datetime 12/31/1999 } .> { new @{RandomNumber = Get-Random; A ='b'}} .> { new Diagnostics.ProcessStartInfo @{FileName='f'} } .> { new ScriptBlock 'Get-Command'} .> { (new PowerShell).AddScript("Get-Command").Invoke() } .> { new 'https://schema.org/Thing' } Use-PipeScript { object { $x = 1; $y = 2 }} Use-PipeScript { object @{ x = 1; y = 2 }} Use-PipeScript { Object } requires latest pipescript # will require the latest version of pipescript requires variable $pid $sid # will error, because there is no $sid {
$x = 0
until ($x == 10) {
$x
$x++
}
} |.>PipeScript Invoke-PipeScript {
until "00:00:05" {
[DateTime]::Now
Start-Sleep -Milliseconds 500
}
} Invoke-PipeScript {
until "12:17 pm" {
[DateTime]::Now
Start-Sleep -Milliseconds 500
}
} {
$eventCounter = 0
until "MyEvent" {
$eventCounter++
$eventCounter
until "00:00:03" {
"sleeping a few seconds"
Start-Sleep -Milliseconds 500
}
if (-not ($eventCounter % 5)) {
$null = New-Event -SourceIdentifier MyEvent
}
}
} | .>PipeScript Invoke-PipeScript {
$tries = 3
until (-not $tries) {
"$tries tries left"
$tries--
}
} Use-PipeScript {
$y = when x {
"y"
}
}
Use-PipeScript {
$timer = new Timers.Timer 1000 @{AutoReset=$false}
when $timer.Elapsed {
"time's up"
}
}Keywords will generally be implemented as a Transpiler that tranforms a CommandAST.