Skip to content
Merged
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
18 changes: 9 additions & 9 deletions src/functions/public/Core/Get-ASTCommand.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function Get-AstCommand {
<#
.SYNOPSIS
Retrieves command AST (Abstract Syntax Tree) elements from a PowerShell script or AST object.
Retrieves command Ast (Abstract Syntax Tree) elements from a PowerShell script or Ast object.

.DESCRIPTION
This function extracts and returns command AST elements from a specified PowerShell script file,
script content, or an existing AST object. The function supports multiple input methods, including
direct script text, file paths, or existing AST objects. It also provides an option to search nested
This function extracts and returns command Ast elements from a specified PowerShell script file,
script content, or an existing Ast object. The function supports multiple input methods, including
direct script text, file paths, or existing Ast objects. It also provides an option to search nested
functions and script block expressions.

.EXAMPLE
Expand All @@ -19,7 +19,7 @@
Errors : {}
```

Parses the specified script file and extracts command AST elements.
Parses the specified script file and extracts command Ast elements.

.EXAMPLE
Get-AstCommand -Script "Get-Process; Write-Host 'Hello'"
Expand All @@ -31,7 +31,7 @@
Errors : {}
```

Parses the provided script content and extracts command AST elements.
Parses the provided script content and extracts command Ast elements.

.EXAMPLE
$ast = [System.Management.Automation.Language.Parser]::ParseInput("Get-Process", [ref]$null, [ref]$null)
Expand All @@ -44,13 +44,13 @@
Errors : {}
```

Extracts command AST elements from a manually parsed AST object.
Extracts command Ast elements from a manually parsed Ast object.

.OUTPUTS
PSCustomObject

.NOTES
Returns an object containing extracted AST elements, tokens, and errors.
Returns an object containing extracted Ast elements, tokens, and errors.

.LINK
https://psmodule.io/Ast/Functions/Core/Get-AstCommand/
Expand Down Expand Up @@ -80,7 +80,7 @@
)]
[string] $Script,

# An existing AST object to search.
# An existing Ast object to search.
[Parameter(
Mandatory,
ValueFromPipeline,
Expand Down
10 changes: 5 additions & 5 deletions src/functions/public/Core/Get-ASTFunction.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function Get-AstFunction {
<#
.SYNOPSIS
Retrieves function definitions from a PowerShell script or AST.
Retrieves function definitions from a PowerShell script or Ast.

.DESCRIPTION
This function extracts function definitions from a given PowerShell script file, script content,
or an existing AST (Abstract Syntax Tree) object. It supports searching by function name
or an existing Ast (Abstract Syntax Tree) object. It supports searching by function name
and can optionally search within nested functions and script block expressions.

.EXAMPLE
Expand Down Expand Up @@ -43,13 +43,13 @@
Errors : {}
```

Extracts function definitions from an existing AST object.
Extracts function definitions from an existing Ast object.

.OUTPUTS
PSCustomObject

.NOTES
Contains AST objects, tokenized script content, and parsing errors if any.
Contains Ast objects, tokenized script content, and parsing errors if any.

.LINK
https://psmodule.io/Ast/Functions/Core/Get-AstFunction
Expand Down Expand Up @@ -79,7 +79,7 @@
)]
[string] $Script,

# An existing AST object to search.
# An existing Ast object to search.
[Parameter(
Mandatory,
ValueFromPipeline,
Expand Down
10 changes: 5 additions & 5 deletions src/functions/public/Core/Get-ASTScript.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function Get-AstScript {
<#
.SYNOPSIS
Parses a PowerShell script or script file and returns its abstract syntax tree (AST).
Parses a PowerShell script or script file and returns its abstract syntax tree (Ast).

.DESCRIPTION
The Get-AstScript function parses a PowerShell script or script file and returns its abstract syntax tree (AST),
The Get-AstScript function parses a PowerShell script or script file and returns its abstract syntax tree (Ast),
along with tokens and errors encountered during parsing. This function can be used to analyze the structure
of a script by specifying either the script content directly or the path to a script file.

Expand All @@ -18,7 +18,7 @@
Errors : {Error1, Error2, ...}
```

Parses the PowerShell script located at "C:\\Scripts\\example.ps1" and returns its AST, tokens, and any parsing errors.
Parses the PowerShell script located at "C:\\Scripts\\example.ps1" and returns its Ast, tokens, and any parsing errors.

.EXAMPLE
Get-AstScript -Script "Write-Host 'Hello World'"
Expand All @@ -30,14 +30,14 @@
Errors : {}
```

Parses the provided PowerShell script string and returns its AST, tokens, and any parsing errors.
Parses the provided PowerShell script string and returns its Ast, tokens, and any parsing errors.

.OUTPUTS
PSCustomObject

.NOTES
The returned custom object contains the following properties:
- `Ast` - [System.Management.Automation.Language.ScriptBlockAst]. The abstract syntax tree (AST) of the parsed script.
- `Ast` - [System.Management.Automation.Language.ScriptBlockAst]. The abstract syntax tree (Ast) of the parsed script.
- `Tokens` - [System.Management.Automation.Language.Token[]]. The tokens generated during parsing.
- `Errors` - [System.Management.Automation.Language.ParseError[]]. Any parsing errors encountered.

Expand Down
14 changes: 7 additions & 7 deletions src/functions/public/Functions/Get-ASTFunctionAlias.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-ASTFunctionAlias {
function Get-AstFunctionAlias {
<#
.SYNOPSIS
Retrieves function aliases from a PowerShell script or file.
Expand All @@ -10,7 +10,7 @@
within nested functions and script blocks.

.EXAMPLE
Get-ASTFunctionAlias -Path "C:\Scripts\MyScript.ps1" -Name "Get-User"
Get-AstFunctionAlias -Path "C:\Scripts\MyScript.ps1" -Name "Get-User"

Output:
```powershell
Expand All @@ -22,7 +22,7 @@
Retrieves aliases assigned to the function `Get-User` within the specified script file.

.EXAMPLE
Get-ASTFunctionAlias -Script $scriptContent -Recurse
Get-AstFunctionAlias -Script $scriptContent -Recurse

Output:
```powershell
Expand All @@ -40,7 +40,7 @@
An object containing the function name and its associated aliases.

.LINK
https://psmodule.io/AST/Functions/Functions/Get-ASTFunctionAlias
https://psmodule.io/Ast/Functions/Functions/Get-AstFunctionAlias
#>
[CmdletBinding()]
param (
Expand Down Expand Up @@ -78,15 +78,15 @@
process {
switch ($PSCmdlet.ParameterSetName) {
'Path' {
$functionAST = Get-ASTFunction -Name $Name -Path $Path -Recurse:$Recurse
$functionAst = Get-AstFunction -Name $Name -Path $Path -Recurse:$Recurse
}
'Script' {
$functionAST = Get-ASTFunction -Name $Name -Script $Script -Recurse:$Recurse
$functionAst = Get-AstFunction -Name $Name -Script $Script -Recurse:$Recurse
}
}

# Process each function and extract aliases
$functionAST.Ast | ForEach-Object {
$functionAst.Ast | ForEach-Object {
$funcName = $_.Name
$funcAttributes = $_.Body.FindAll({ $args[0] -is [System.Management.Automation.Language.AttributeAst] }, $true) | Where-Object {
$_.Parent -is [System.Management.Automation.Language.ParamBlockAst]
Expand Down
20 changes: 10 additions & 10 deletions src/functions/public/Functions/Get-ASTFunctionName.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function Get-ASTFunctionName {
function Get-AstFunctionName {
<#
.SYNOPSIS
Retrieves the names of functions from an abstract syntax tree (AST) in a PowerShell script.
Retrieves the names of functions from an abstract syntax tree (Ast) in a PowerShell script.

.DESCRIPTION
Parses a PowerShell script file or script content to extract function names using an abstract syntax tree (AST).
Parses a PowerShell script file or script content to extract function names using an abstract syntax tree (Ast).
The function supports searching by name, parsing from a file path, or directly from a script string. It can also
search within nested functions and script block expressions when the -Recurse switch is used.

.EXAMPLE
Get-ASTFunctionName -Path "C:\Scripts\example.ps1"
Get-AstFunctionName -Path "C:\Scripts\example.ps1"

Output:
```powershell
Expand All @@ -20,7 +20,7 @@
Extracts function names from the specified PowerShell script file.

.EXAMPLE
Get-ASTFunctionName -Script "function Test-Function { param($x) Write-Host $x }"
Get-AstFunctionName -Script "function Test-Function { param($x) Write-Host $x }"

Output:
```powershell
Expand All @@ -30,7 +30,7 @@
Extracts function names from the given script string.

.EXAMPLE
Get-ASTFunctionName -Path "C:\Scripts\example.ps1" -Recurse
Get-AstFunctionName -Path "C:\Scripts\example.ps1" -Recurse

Output:
```powershell
Expand All @@ -48,7 +48,7 @@
The name of each function found in the PowerShell script.

.LINK
https://psmodule.io/AST/Functions/Functions/Get-ASTFunctionName/
https://psmodule.io/Ast/Functions/Functions/Get-AstFunctionName/
#>

[CmdletBinding()]
Expand Down Expand Up @@ -87,15 +87,15 @@
process {
switch ($PSCmdlet.ParameterSetName) {
'Path' {
$functionAST = Get-ASTFunction -Name $Name -Path $Path -Recurse:$Recurse
$functionAst = Get-AstFunction -Name $Name -Path $Path -Recurse:$Recurse
}
'Script' {
$functionAST = Get-ASTFunction -Name $Name -Script $Script -Recurse:$Recurse
$functionAst = Get-AstFunction -Name $Name -Script $Script -Recurse:$Recurse
}
}

# Process each function and extract the name
$functionAST.Ast | ForEach-Object {
$functionAst.Ast | ForEach-Object {
$_.Name
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/functions/public/Functions/Get-ASTFunctionType.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function Get-ASTFunctionType {
function Get-AstFunctionType {
<#
.SYNOPSIS
Retrieves the type of an abstract syntax tree (AST) function.
Retrieves the type of an abstract syntax tree (Ast) function.

.DESCRIPTION
Parses a PowerShell script file or script content to determine the type of function present.
The function classifies functions as `Function`, `Filter`, `Workflow`, or `Configuration`.
It supports searching for specific function names and can process nested functions if required.

.EXAMPLE
Get-ASTFunctionType -Path "C:\Scripts\MyScript.ps1"
Get-AstFunctionType -Path "C:\Scripts\MyScript.ps1"

Output:
```powershell
Expand All @@ -22,7 +22,7 @@
Parses the specified script file and identifies function types.

.EXAMPLE
Get-ASTFunctionType -Script "function Test { param() Write-Output 'Hello' }"
Get-AstFunctionType -Script "function Test { param() Write-Output 'Hello' }"

Output:
```powershell
Expand All @@ -40,7 +40,7 @@
Represents the function name and its determined type.

.LINK
https://psmodule.io/AST/Functions/Functions/Get-ASTFunctionType/
https://psmodule.io/Ast/Functions/Functions/Get-AstFunctionType/
#>
[OutputType([pscustomobject])]
[CmdletBinding()]
Expand Down Expand Up @@ -79,14 +79,14 @@
process {
switch ($PSCmdlet.ParameterSetName) {
'Path' {
$functionAST = Get-ASTFunction -Name $Name -Path $Path -Recurse:$Recurse
$functionAst = Get-AstFunction -Name $Name -Path $Path -Recurse:$Recurse
}
'Script' {
$functionAST = Get-ASTFunction -Name $Name -Script $Script -Recurse:$Recurse
$functionAst = Get-AstFunction -Name $Name -Script $Script -Recurse:$Recurse
}
}

$functionAST.Ast | ForEach-Object {
$functionAst.Ast | ForEach-Object {
$type = if ($_.IsWorkflow) {
'Workflow'
} elseif ($_.IsConfiguration) {
Expand Down
6 changes: 3 additions & 3 deletions src/functions/public/Lines/Get-ASTLineComment.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
filter Get-ASTLineComment {
filter Get-AstLineComment {
<#
.SYNOPSIS
Extracts comment tokens from a given line of PowerShell code.
Expand All @@ -9,7 +9,7 @@
the specified kind, defaulting to 'Comment'.

.EXAMPLE
"# This is a comment" | Get-ASTLineComment
"# This is a comment" | Get-AstLineComment

Output:
```powershell
Expand All @@ -26,7 +26,7 @@
An array of tokens representing comments extracted from the input line.

.LINK
https://psmodule.io/AST/Functions/Lines/Get-ASTLineComment/
https://psmodule.io/Ast/Functions/Lines/Get-AstLineComment/
#>
[OutputType([System.Management.Automation.Language.Token[]])]
[CmdletBinding()]
Expand Down
16 changes: 8 additions & 8 deletions src/functions/public/Scripts/Get-ASTScriptCommand.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-ASTScriptCommand {
function Get-AstScriptCommand {
<#
.SYNOPSIS
Retrieves the commands used within a specified PowerShell script.
Expand All @@ -9,17 +9,17 @@
Returns details such as command name, position, and file reference.

.EXAMPLE
Get-ASTScriptCommand -Path "C:\Scripts\example.ps1"
Get-AstScriptCommand -Path "C:\Scripts\example.ps1"

Extracts and lists all commands found in the specified PowerShell script.

.EXAMPLE
Get-ASTScriptCommand -Path "C:\Scripts\example.ps1" -IncludeCallOperators
Get-AstScriptCommand -Path "C:\Scripts\example.ps1" -IncludeCallOperators

Extracts all commands, including those executed with call operators (& and .).

.LINK
https://psmodule.io/AST/Functions/Scripts/Get-ASTScriptCommand/
https://psmodule.io/Ast/Functions/Scripts/Get-AstScriptCommand/
#>
[CmdletBinding(DefaultParameterSetName = 'Ast')]
param (
Expand All @@ -46,7 +46,7 @@
)]
[string] $Script,

# An existing AST object to search.
# An existing Ast object to search.
[Parameter(
Mandatory,
ValueFromPipeline,
Expand Down Expand Up @@ -81,13 +81,13 @@
}

# Gather CommandAsts
$commandAST = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $Recurse)
$commandAst = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $Recurse)

if (-not $IncludeCallOperators) {
$commandAST = $commandAST | Where-Object { $_.InvocationOperator -notin 'Ampersand', 'Dot' }
$commandAst = $commandAst | Where-Object { $_.InvocationOperator -notin 'Ampersand', 'Dot' }
}

$commandAST | ForEach-Object {
$commandAst | ForEach-Object {
$invocationOperator = switch ($_.InvocationOperator) {
'Ampersand' { '&' }
'Dot' { '.' }
Expand Down