File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ param (
2+ [Alias (' Start' , ' StartString' , ' Initiator' )]
3+ [string ]
4+ $Axiom ,
5+
6+ [Alias (' Rules' , ' ProductionRules' )]
7+ [Collections.IDictionary ]
8+ $Rule = [Ordered ]@ {},
9+
10+ [Alias (' Iterations' , ' Steps' , ' IterationCount' , ' StepCount' )]
11+ [int ]
12+ $N = 2 ,
13+
14+ [Collections.IDictionary ]
15+ $Variable = @ {}
16+ )
17+
18+ if ($n -le 1 ) { return $Axiom }
19+
20+ $currentState = " $Axiom "
21+ $combinedPattern = " (?>$ ( $Rule.Keys -join ' |' ) )"
22+ foreach ($iteration in 1 .. $n ) {
23+ $currentState = $currentState -replace $combinedPattern , {
24+ $match = $_
25+ $matchingRule = $rule [" $match " ]
26+ if ($matchingRule -is [ScriptBlock ]) {
27+ return " $ ( & $matchingRule $match ) "
28+ } else {
29+ return $matchingRule
30+ }
31+ }
32+ }
33+
34+ $finalState = $currentState
35+ foreach ($character in $finalState.ToCharArray ()) {
36+ foreach ($key in $Variable.Keys ) {
37+ if ($character -match $key ) {
38+ $action = $Variable [$key ]
39+ if ($action -is [ScriptBlock ]) {
40+ . $action $character
41+ } else {
42+ $action
43+ }
44+ }
45+ }
46+ }
47+ return
You can’t perform that action at this time.
0 commit comments