@@ -112,28 +112,28 @@ $Axiom,
112
112
[Collections.IDictionary ]
113
113
$Rule = [Ordered ]@ {},
114
114
115
- [Alias (' Iterations' , ' Steps ' , ' IterationCount ' , ' StepCount' )]
115
+ [Alias (' Iterations' , ' IterationCount ' , ' N ' , ' Steps ' , ' StepCount' )]
116
116
[int ]
117
- $N = 2 ,
117
+ $Order = 2 ,
118
118
119
119
[Collections.IDictionary ]
120
120
$Variable = @ {}
121
121
)
122
122
123
- if ($n -lt 1 ) { return $Axiom }
124
-
125
123
$currentState = " $Axiom "
126
- $combinedPattern = " (?>$ ( $Rule.Keys -join ' |' ) )"
127
- foreach ($iteration in 1 .. $n ) {
128
- $currentState = $currentState -replace $combinedPattern , {
129
- $match = $_
130
- $matchingRule = $rule [" $match " ]
131
- if ($matchingRule -is [ScriptBlock ]) {
132
- return " $ ( & $matchingRule $match ) "
133
- } else {
134
- return $matchingRule
135
- }
136
- }
124
+ if ($Order -ge 1 ) {
125
+ $combinedPattern = " (?>$ ( $Rule.Keys -join ' |' ) )"
126
+ foreach ($iteration in 1 .. $Order ) {
127
+ $currentState = $currentState -replace $combinedPattern , {
128
+ $match = $_
129
+ $matchingRule = $rule [" $match " ]
130
+ if ($matchingRule -is [ScriptBlock ]) {
131
+ return " $ ( . $matchingRule $match ) "
132
+ } else {
133
+ return $matchingRule
134
+ }
135
+ }
136
+ }
137
137
}
138
138
139
139
$localReplacement = [Ordered ]@ {}
@@ -147,22 +147,32 @@ foreach ($key in $variable.Keys) {
147
147
}
148
148
149
149
$finalState = $currentState
150
- $null = foreach ($character in $finalState.ToCharArray ()) {
151
- foreach ($key in $Variable.Keys ) {
152
- if ($character -match $key ) {
153
- $action = $localReplacement [$key ]
154
- if ($action -is [ScriptBlock ]) {
155
- . $action $character
156
- } else {
157
- $action
158
- }
159
- }
160
- }
161
- }
150
+
162
151
$this.PathAttribute = [Ordered ]@ {
163
- " data-l-order" = $N
152
+ " data-l-order" = $Order
164
153
" data-l-axiom" = $Axiom
165
154
" data-l-rules" = ConvertTo-Json $Rule
166
155
" data-l-expanded" = $finalState
167
156
}
157
+
158
+ $MatchesAny = " (?>$ ( $variable.Keys -join ' |' ) )"
159
+ $allMatches = @ ([Regex ]::Matches($finalState , $MatchesAny , ' IgnoreCase,IgnorePatternWhitespace' ))
160
+ $matchCache = @ {}
161
+ :nextMatch foreach ($match in $allMatches ) {
162
+ $m = " $match "
163
+ if (-not $matchCache [$m ]) {
164
+ foreach ($key in $Variable.Keys ) {
165
+ if (-not ($match -match $key )) { continue }
166
+ # if ($variable[$key] -isnot [ScriptBlock]) { continue }
167
+ $matchCache [$m ] = $localReplacement [$key ]
168
+ break
169
+ }
170
+ }
171
+
172
+ if ($matchCache [$m ] -is [ScriptBlock ]) {
173
+ $Orderull = . $matchCache [$m ] $match
174
+ continue nextMatch
175
+ }
176
+ }
177
+
168
178
return $this
0 commit comments