Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Created December 1, 2015 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/bcbee5f504c25b166003 to your computer and use it in GitHub Desktop.
Save IISResetMe/bcbee5f504c25b166003 to your computer and use it in GitHub Desktop.
PowerShell can parse itself just fine
function Get-AST
{
param(
[Parameter(Mandatory,ValueFromPipeline)]
[psobject[]]$InputObject
)
process{
foreach($Script in $InputObject){
$Tokens = $Errors = @()
$AST = [System.Management.Automation.Language.Parser]::ParseInput($Script,[ref]$Tokens,[ref]$Errors)
$AST | Add-Member -MemberType NoteProperty -Name Tokens -Value $Tokens
$AST | Add-Member -MemberType NoteProperty -Name Errors -Value $Errors
Write-Output $AST
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment