88
99 Inline PipeScript will be embedded within the file (usually in comments).
1010
11- Anything encountered in a source generator file can be either:
12-
13- * A Literal String (written directly in the underlying source language)
14- * A Script Block (written in PowerShell or PipeScript)
15-
16- This Transpiler takes a sequence of literal strings and script blocks, and constructs the source generation script.
11+ If a Regular Expression can match each section, then the content in each section can be replaced.
1712#>
1813param (
1914# A list of source sections
@@ -24,6 +19,7 @@ $SourceSection,
2419# A string containing the text contents of the file
2520[Parameter (Mandatory , ParameterSetName = ' SourceTextAndPattern' )]
2621[Parameter (Mandatory , ParameterSetName = ' SourceTextReplace' )]
22+ [Parameter (Mandatory , ParameterSetName = ' SourceStartAndEnd' )]
2723[string ]
2824$SourceText ,
2925
@@ -46,35 +42,56 @@ $SourcePattern,
4642[regex ]
4743$ReplacePattern ,
4844
45+ # The Start Pattern.
46+ # This indicates the beginning of what should be considered PipeScript.
47+ # An expression will match everything until -EndPattern
48+ [Parameter (Mandatory , ParameterSetName = ' SourceStartAndEnd' )]
49+ [Alias (' StartRegex' )]
50+ [Regex ]
51+ $StartPattern ,
52+
53+ # The End Pattern
54+ # This indicates the end of what should be considered PipeScript.
55+ [Parameter (Mandatory , ParameterSetName = ' SourceStartAndEnd' )]
56+ [Alias (' EndRegex' )]
57+ [Regex ]
58+ $EndPattern ,
59+
4960[Parameter (ParameterSetName = ' SourceTextReplace' )]
61+ [Parameter (ParameterSetName = ' SourceStartAndEnd' )]
5062[Alias (' Replacer' )]
5163[ScriptBlock ]
5264$ReplacementEvaluator ,
5365
5466# If set, will not transpile script blocks.
5567[Parameter (ParameterSetName = ' SourceTextAndPattern' )]
5668[Parameter (ParameterSetName = ' SourceSections' )]
69+ [Parameter (ParameterSetName = ' SourceStartAndEnd' )]
70+ [Parameter (ParameterSetName = ' SourceTextReplace' )]
5771[switch ]
5872$NoTranspile ,
5973
6074# The path to the source file.
6175[Parameter (ParameterSetName = ' SourceTextAndPattern' )]
6276[Parameter (ParameterSetName = ' SourceSections' )]
6377[Parameter (ParameterSetName = ' SourceTextReplace' )]
78+ [Parameter (ParameterSetName = ' SourceStartAndEnd' )]
6479[string ]
6580$SourceFile ,
6681
6782# A Script Block that will be injected before each inline is run.
6883[Parameter (ParameterSetName = ' SourceTextAndPattern' )]
6984[Parameter (ParameterSetName = ' SourceSections' )]
7085[Parameter (ParameterSetName = ' SourceTextReplace' )]
86+ [Parameter (ParameterSetName = ' SourceStartAndEnd' )]
7187[ScriptBlock ]
7288$Begin ,
7389
7490# A Script Block that will be piped to after each output.
7591[Parameter (ParameterSetName = ' SourceTextAndPattern' )]
7692[Parameter (ParameterSetName = ' SourceSections' )]
7793[Parameter (ParameterSetName = ' SourceTextReplace' )]
94+ [Parameter (ParameterSetName = ' SourceStartAndEnd' )]
7895[Alias (' Process' )]
7996[ScriptBlock ]
8097$ForeachObject ,
@@ -83,6 +100,7 @@ $ForeachObject,
83100[Parameter (ParameterSetName = ' SourceTextAndPattern' )]
84101[Parameter (ParameterSetName = ' SourceSections' )]
85102[Parameter (ParameterSetName = ' SourceTextReplace' )]
103+ [Parameter (ParameterSetName = ' SourceStartAndEnd' )]
86104[ScriptBlock ]
87105$End
88106)
@@ -92,7 +110,22 @@ begin {
92110}
93111
94112process {
95- if ($psCmdlet.ParameterSetName -eq ' SourceTextReplace' ) {
113+ $psParameterSet = $psCmdlet.ParameterSetName
114+ if ($psParameterSet -eq ' SourceStartAndEnd' ) {
115+ $ReplacePattern = [Regex ]::New("
116+ # Match the PipeScript Start
117+ $StartPattern
118+ # Match until the PipeScript end. This will be PipeScript
119+ (?<PipeScript>
120+ (?:.|\s){0,}?(?=\z|$endPattern )
121+ )
122+ # Then Match the PipeScript End
123+ $EndPattern
124+ " , ' IgnoreCase, IgnorePatternWhitespace' , ' 00:00:10' )
125+ $psParameterSet = ' SourceTextReplace'
126+ }
127+
128+ if ($psParameterSet -eq ' SourceTextReplace' ) {
96129 $fileText = $SourceText
97130 if (-not $PSBoundParameters [" ReplacementEvaluator" ]) {
98131 $ReplacementEvaluator = {
@@ -168,7 +201,7 @@ process {
168201 return $ReplacePattern.Replace ($fileText , $ReplacementEvaluator )
169202 }
170203
171- if ($psCmdlet .ParameterSetName -eq ' SourceTextAndPattern' ) {
204+ if ($psParameterSet -eq ' SourceTextAndPattern' ) {
172205
173206 $fileText = $SourceText
174207 $foundSpots = @ ($SourcePattern.Matches ($fileText ))
0 commit comments