Skip to content

Commit

Permalink
Merge pull request #300 from StartAutomating/PipeScriptFixesAndFun
Browse files Browse the repository at this point in the history
PipeScript 0.2.1
  • Loading branch information
StartAutomating authored Nov 16, 2022
2 parents cfc479d + 249a430 commit ace7a57
Show file tree
Hide file tree
Showing 101 changed files with 867 additions and 3,719 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.2.1:

* Adding preliminary 'define' transpiler (Fixes #299)
* Improving interactive templates (now supported for all languages) (Fixes #285)
* Fixing sequence dotting within non-statements (Fixes #298)
* Allow multiple transpiler outputs to update nearby context (Fixes #297)
* No longer expanding Regex Literals in attributes (Fixes #290)

---

## 0.2:

* Massive Improvements in Templating
Expand Down
17 changes: 13 additions & 4 deletions Get-PipeScript.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Piecemeal [ 0.3.5 ] : Easy Extensible Plugins for PowerShell
#region Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell
# Install-Module Piecemeal -Scope CurrentUser
# Import-Module Piecemeal -Force
# Install-Piecemeal -ExtensionNoun 'PipeScript' -ExtensionPattern '\.psx\.ps1{0,1}$','\.ps1{0,1}\.(?<ext>[^.]+$)','\.ps1{0,1}$' -ExtensionTypeName 'PipeScript' -OutputPath '.\Get-PipeScript.ps1'
Expand Down Expand Up @@ -602,11 +602,20 @@ function Get-PipeScript
$params = @{}
$mappedParams = [Ordered]@{} # Create a collection of mapped parameters
# Walk thru each parameter of this command
foreach ($myParam in $paramSet.Parameters) {
:nextParameter foreach ($myParam in $paramSet.Parameters) {
# If the parameter is ValueFromPipeline
if ($myParam.ValueFromPipeline) {
$potentialPSTypeNames = @($myParam.Attributes.PSTypeName) -ne ''
if ($potentialPSTypeNames) {
foreach ($potentialTypeName in $potentialPSTypeNames) {
if ($potentialTypeName -and $InputObject.pstypenames -contains $potentialTypeName) {
$mappedParams[$myParam.Name] = $params[$myParam.Name] = $InputObject
continue nextParameter
}
}
}
# and we have an input object
if ($null -ne $inputObject -and
elseif ($null -ne $inputObject -and
(
# of the exact type
$myParam.ParameterType -eq $inputObject.GetType() -or
Expand Down Expand Up @@ -925,5 +934,5 @@ function Get-PipeScript
}
}
}
#endregion Piecemeal [ 0.3.5 ] : Easy Extensible Plugins for PowerShell
#endregion Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell

17 changes: 13 additions & 4 deletions Get-Transpiler.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Piecemeal [ 0.3.5 ] : Easy Extensible Plugins for PowerShell
#region Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell
# Install-Module Piecemeal -Scope CurrentUser
# Import-Module Piecemeal -Force
# Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
Expand Down Expand Up @@ -602,11 +602,20 @@ function Get-Transpiler
$params = @{}
$mappedParams = [Ordered]@{} # Create a collection of mapped parameters
# Walk thru each parameter of this command
foreach ($myParam in $paramSet.Parameters) {
:nextParameter foreach ($myParam in $paramSet.Parameters) {
# If the parameter is ValueFromPipeline
if ($myParam.ValueFromPipeline) {
$potentialPSTypeNames = @($myParam.Attributes.PSTypeName) -ne ''
if ($potentialPSTypeNames) {
foreach ($potentialTypeName in $potentialPSTypeNames) {
if ($potentialTypeName -and $InputObject.pstypenames -contains $potentialTypeName) {
$mappedParams[$myParam.Name] = $params[$myParam.Name] = $InputObject
continue nextParameter
}
}
}
# and we have an input object
if ($null -ne $inputObject -and
elseif ($null -ne $inputObject -and
(
# of the exact type
$myParam.ParameterType -eq $inputObject.GetType() -or
Expand Down Expand Up @@ -925,5 +934,5 @@ function Get-Transpiler
}
}
}
#endregion Piecemeal [ 0.3.5 ] : Easy Extensible Plugins for PowerShell
#endregion Piecemeal [ 0.3.6 ] : Easy Extensible Plugins for PowerShell

1 change: 1 addition & 0 deletions ListOfTranspilers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ These are all of the transpilers currently included in PipeScript:
|[CSharp.Template](Transpilers/Templates/CSharp.Template.psx.ps1) |C# Template Transpiler. |
|[CSS.Template](Transpilers/Templates/CSS.Template.psx.ps1) |CSS Template Transpiler. |
|[Decorate](Transpilers/Decorate.psx.ps1) |decorate transpiler |
|[Define](Transpilers/Define.psx.ps1) |Defines a variable |
|[Dot](Transpilers/Syntax/Dot.psx.ps1) |Dot Notation |
|[EqualityComparison](Transpilers/Syntax/EqualityComparison.psx.ps1) |Allows equality comparison. |
|[EqualityTypeComparison](Transpilers/Syntax/EqualityTypeComparison.psx.ps1) |Allows equality type comparison. |
Expand Down
6 changes: 4 additions & 2 deletions PipeScript.Piecemeal.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#require -Module Piecemeal
Push-Location $PSScriptRoot

Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
Install-Piecemeal -ExtensionNoun 'PipeScript' -ExtensionPattern '\.psx\.ps1{0,1}$','\.ps1{0,1}\.(?<ext>[^.]+$)','\.ps1{0,1}$' -ExtensionTypeName 'PipeScript' -OutputPath '.\Get-PipeScript.ps1'
Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1' |
Add-Member Noteproperty CommitMessage "Get-Transpiler: Updating Piecemeal Version" -Force -PassThru
Install-Piecemeal -ExtensionNoun 'PipeScript' -ExtensionPattern '\.psx\.ps1{0,1}$','\.ps1{0,1}\.(?<ext>[^.]+$)','\.ps1{0,1}$' -ExtensionTypeName 'PipeScript' -OutputPath '.\Get-PipeScript.ps1' |
Add-Member Noteproperty CommitMessage "Get-PipeScript: Updating Piecemeal Version" -Force -PassThru


Pop-Location
20 changes: 7 additions & 13 deletions PipeScript.ps.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.2'
ModuleVersion = '0.2.1'
Description = 'An Extensible Transpiler for PowerShell (and anything else)'
RootModule = 'PipeScript.psm1'
PowerShellVersion = '4.0'
Expand All @@ -25,19 +25,13 @@
BuildModule = @('EZOut','Piecemeal','PipeScript','HelpOut', 'PSDevOps')
Tags = 'PipeScript','PowerShell', 'Transpilation', 'Compiler'
ReleaseNotes = @'
## 0.2:
## 0.2.1:
* Massive Improvements in Templating
* Templates can be used interactively (Fixes #285)
* Renaming all Inline Transpilers to Template Transpilers
* Natural Parsing Improvements
* ArrayLiterals are expanded (Fixes #291)
* AsSentence now only allows one value into a singleton (Fixes #279)
* Not expanding expandable strings (Fixes #286)
* Transpilers can change nearby context (Fixes #292)
* Allowing dot syntax to extend across multiple statements (Fixes #273)
* Adding requires keyword (Fixes #293)
* PipeScript modifies its own manifest (Fixes #294)
* Adding preliminary 'define' transpiler (Fixes #299)
* Improving interactive templates (now supported for all languages) (Fixes #285)
* Fixing sequence dotting within non-statements (Fixes #298)
* Allow multiple transpiler outputs to update nearby context (Fixes #297)
* No longer expanding Regex Literals in attributes (Fixes #290)
---
Expand Down
20 changes: 7 additions & 13 deletions PipeScript.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.2'
ModuleVersion = '0.2.1'
Description = 'An Extensible Transpiler for PowerShell (and anything else)'
RootModule = 'PipeScript.psm1'
PowerShellVersion = '4.0'
Expand All @@ -20,19 +20,13 @@
BuildModule = @('EZOut','Piecemeal','PipeScript','HelpOut', 'PSDevOps')
Tags = 'PipeScript','PowerShell', 'Transpilation', 'Compiler'
ReleaseNotes = @'
## 0.2:
## 0.2.1:
* Massive Improvements in Templating
* Templates can be used interactively (Fixes #285)
* Renaming all Inline Transpilers to Template Transpilers
* Natural Parsing Improvements
* ArrayLiterals are expanded (Fixes #291)
* AsSentence now only allows one value into a singleton (Fixes #279)
* Not expanding expandable strings (Fixes #286)
* Transpilers can change nearby context (Fixes #292)
* Allowing dot syntax to extend across multiple statements (Fixes #273)
* Adding requires keyword (Fixes #293)
* PipeScript modifies its own manifest (Fixes #294)
* Adding preliminary 'define' transpiler (Fixes #299)
* Improving interactive templates (now supported for all languages) (Fixes #285)
* Fixing sequence dotting within non-statements (Fixes #298)
* Allow multiple transpiler outputs to update nearby context (Fixes #297)
* No longer expanding Regex Literals in attributes (Fixes #290)
---
Expand Down
2 changes: 1 addition & 1 deletion Transpilers/Core/PipeScript.Template.psx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ process {
}

if (-not (Test-Path $Name)) {
$null = New-Item -ItemType $file -Path $name -Force
$null = New-Item -ItemType File -Path $name -Force
}
$evaluated | Set-Content -Path $name
Get-Item -Path $name
Expand Down
83 changes: 43 additions & 40 deletions Transpilers/Core/Pipescript.psx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -268,60 +268,63 @@ process {
$start = $scriptText.IndexOf($item.Extent.Text, $myOffset)
$end = $start + $item.Extent.Text.Length
$skipUntil = $end # set SkipUntil
$AstReplacements[$item] = $pso # and store the replacement.
$AstReplacements[$item] = $pso # and store the replacement.
}

#region Special Properties

#region Special Properties
# Because PowerShell can attach properties to any object,
# we can use the presence of attached properties to change context around the replacement.
# Because PowerShell can attach properties to any object,
# we can use the presence of attached properties to change context around the replacement.
# This happens regardless of if there is already a replacement for the current item.

# .SkipUntil or .IgnoreUntil can specify a new index or AST end point
foreach ($toSkipAlias in 'SkipUntil', 'IgnoreUntil') {
foreach ($toSkipUntil in $pso.$toSkipAlias) {
if ($toSkipUntil -is [int] -and $toSkipUntil -gt $end) {
$skipUntil = $toSkipUntil
} elseif ($toSkipUntil -is [Management.Automation.Language.Ast]) {
$newSkipStart = $scriptText.IndexOf($toSkipUntil.Extent.Text, $myOffset)
if ($newSkipStart -ne -1) {
$end = $newSkipStart + $toSkipUntil.Extent.Text.Length
if ($end -gt $skipUntil) {
$skipUntil = $end
}
if ($toSkipUntil -ne $item) {
$AstReplacements[$toSkipUntil] = ''
}
# .SkipUntil or .IgnoreUntil can specify a new index or AST end point
foreach ($toSkipAlias in 'SkipUntil', 'IgnoreUntil') {
foreach ($toSkipUntil in $pso.$toSkipAlias) {
if ($toSkipUntil -is [int] -and $toSkipUntil -gt $end) {
$skipUntil = $toSkipUntil
} elseif ($toSkipUntil -is [Management.Automation.Language.Ast]) {
$newSkipStart = $scriptText.IndexOf($toSkipUntil.Extent.Text, $myOffset)
if ($newSkipStart -ne -1) {
$end = $newSkipStart + $toSkipUntil.Extent.Text.Length
if ($end -gt $skipUntil) {
$skipUntil = $end
}
if ($toSkipUntil -ne $item) {
$AstReplacements[$toSkipUntil] = ''
}
}
}
}
}

#.ToRemove,.RemoveAST, or .RemoveElement will remove AST elements or ranges
foreach ($toRemoveAlias in 'ToRemove','RemoveAST','RemoveElement') {
foreach ($toRemove in $pso.$toRemoveAlias) {
if ($toRemove -is [Management.Automation.Language.Ast]) {
$AstReplacements[$toRemove] = ''
} elseif ($toRemove -match '^\d+,\d+$') {
$Replacements[$toRemove] = ''
}
#.ToRemove,.RemoveAST, or .RemoveElement will remove AST elements or ranges
foreach ($toRemoveAlias in 'ToRemove','RemoveAST','RemoveElement') {
foreach ($toRemove in $pso.$toRemoveAlias) {
if ($toRemove -is [Management.Automation.Language.Ast]) {
$AstReplacements[$toRemove] = ''
} elseif ($toRemove -match '^\d+,\d+$') {
$Replacements[$toRemove] = ''
}
}
}

#.ToReplace,.ReplaceAST or .ReplaceElement will replace elements or ranges.
foreach ($toReplaceAlias in 'ToReplace','ReplaceAST','ReplaceElement') {
foreach ($toReplace in $pso.$toReplaceAlias) {
if ($toReplace -isnot [Collections.IDictionary]) {
continue
}
foreach ($tr in $toReplace.GetEnumerator()) {
if ($tr.Key -is [Management.Automaton.Language.Ast]) {
$AstReplacements[$tr.Key] = $tr.Value
} elseif ($tr.Key -match '^\d+,\d+$') {
$textReplacements["$($tr.Key)"] = $tr.Value
}
#.ToReplace,.ReplaceAST or .ReplaceElement will replace elements or ranges.
foreach ($toReplaceAlias in 'ToReplace','ReplaceAST','ReplaceElement') {
foreach ($toReplace in $pso.$toReplaceAlias) {
if ($toReplace -isnot [Collections.IDictionary]) {
continue
}
foreach ($tr in $toReplace.GetEnumerator()) {
if ($tr.Key -is [Management.Automaton.Language.Ast]) {
$AstReplacements[$tr.Key] = $tr.Value
} elseif ($tr.Key -match '^\d+,\d+$') {
$textReplacements["$($tr.Key)"] = $tr.Value
}
}
}
#endregion Special Properties
}
#endregion Special Properties

}
# If the transpiler had output, do not process any more transpilers.
if ($pipeScriptOutput) { break }
Expand Down
Loading

0 comments on commit ace7a57

Please sign in to comment.