Almost any given sentence could be considered valid PowerShell (including this one).
What if we could parse a command as a sentence?
One could map a sentence to a command in a natural language syntax.
This can be done by:
[AST]
[CommandParameter]
s normally, and consider them the start of a clauseValueFromRemainingArguments
, unbound parameters will be bound to itSo algorithmically, this is pretty straightforward.
If you treated a commands a sentences, instead of the way it would normally be parsed in PowerShell, it looks shorter and reads more naturally:
For Example, here are some alternative ways to write Get-Process:
Get-Process -Name powershell -IncludeUserName
Get-Process Name powershell IncludeUserName pwsh
Get-Process IncludeUserName Name powershell pwsh
Get-Process /IncludeUserName --Name powershell pwsh
In the trio of examples, there should be two clauses in the sentence, Name PowerShell
and IncludeUserName
One of the pain points with writing a PipeScript keyword has been how to structure it’s arguments. Because keywords are parsing a CommandAST that has not run, even if one defined parameters on the keyword, they wouldn’t be automatically bound.
Thus there has been a need to have a consistent way to “pre-parse” a keyword.
Additionally, there’s been the desire to make PipeScript’s syntax even more high level than PowerShell’s.
Want an example? In the same Pull Request in which Natural Syntax support was introduced, the ‘all’ keyword was introduced.
This leads to the wonderfully natural syntax you see below.
all functions that AsJob # would get all -Functions -That have an -AsJob parameter
That’s some pretty readable code, right?
Moving forward, expect to see most new keywords using this natural language format.