@@ -104,20 +104,25 @@ F+F+F+F +JJJJ+ F+F+F+F ++ JJJJ' },
104
104
105
105
#>
106
106
param (
107
+ # The axiom, or starting string.
107
108
[Alias (' Start' , ' StartString' , ' Initiator' )]
108
109
[string ]
109
110
$Axiom ,
110
111
112
+ # The rules for expanding each iteration of the axiom.
111
113
[Alias (' Rules' , ' ProductionRules' )]
112
114
[Collections.IDictionary ]
113
115
$Rule = [Ordered ]@ {},
114
116
117
+ # The order of magnitude (or number of iterations)
115
118
[Alias (' Iterations' , ' IterationCount' , ' N' , ' Steps' , ' N' , ' StepCount' )]
116
119
[int ]
117
120
$Order = 2 ,
118
121
122
+ # The ways each variable will be expanded.
119
123
[Collections.IDictionary ]
120
124
$Variable = @ {}
125
+
121
126
)
122
127
123
128
# First, let us expand our axiom
@@ -172,18 +177,24 @@ $allMatches = @([Regex]::Matches($finalState, $MatchesAny, 'IgnoreCase,IgnorePat
172
177
$matchCache = @ {}
173
178
:nextMatch foreach ($match in $allMatches ) {
174
179
$m = " $match "
180
+ # If we have not mapped the match to a script,
175
181
if (-not $matchCache [$m ]) {
182
+ # find the matching replacement.
176
183
foreach ($key in $Variable.Keys ) {
177
184
if (-not ($match -match $key )) { continue }
178
185
$matchCache [$m ] = $localReplacement [$key ]
179
186
break
180
187
}
181
188
}
182
189
190
+ # If we have a script to run
183
191
if ($matchCache [$m ] -is [ScriptBlock ]) {
192
+ # run it
184
193
$null = . $matchCache [$m ] $match
194
+ # and continue to the next match.
185
195
continue nextMatch
186
196
}
187
197
}
188
198
199
+ # return this so we can pipe and chain this method.
189
200
return $this
0 commit comments