@@ -716,28 +716,28 @@ $Axiom,
716
716
[Collections.IDictionary]
717
717
$Rule = [Ordered]@{},
718
718
719
- [Alias('Iterations', 'Steps ', 'IterationCount ','StepCount')]
719
+ [Alias('Iterations', 'IterationCount ', 'N', 'Steps ','StepCount')]
720
720
[int]
721
- $N = 2,
721
+ $Order = 2,
722
722
723
723
[Collections.IDictionary]
724
724
$Variable = @{}
725
725
)
726
726
727
- if ($n -lt 1) { return $Axiom}
728
-
729
727
$currentState = "$Axiom"
730
- $combinedPattern = "(?> $($Rule.Keys -join '|'))"
731
- foreach ($iteration in 1..$n) {
732
- $currentState = $currentState -replace $combinedPattern, {
733
- $match = $_
734
- $matchingRule = $rule["$match"]
735
- if ($matchingRule -is [ScriptBlock]) {
736
- return "$(& $matchingRule $match)"
737
- } else {
738
- return $matchingRule
739
- }
740
- }
728
+ if ($Order -ge 1) {
729
+ $combinedPattern = "(?> $($Rule.Keys -join '|'))"
730
+ foreach ($iteration in 1..$Order) {
731
+ $currentState = $currentState -replace $combinedPattern, {
732
+ $match = $_
733
+ $matchingRule = $rule["$match"]
734
+ if ($matchingRule -is [ScriptBlock]) {
735
+ return "$(. $matchingRule $match)"
736
+ } else {
737
+ return $matchingRule
738
+ }
739
+ }
740
+ }
741
741
}
742
742
743
743
$localReplacement = [Ordered]@{}
@@ -751,24 +751,34 @@ foreach ($key in $variable.Keys) {
751
751
}
752
752
753
753
$finalState = $currentState
754
- $null = foreach ($character in $finalState.ToCharArray()) {
755
- foreach ($key in $Variable.Keys) {
756
- if ($character -match $key) {
757
- $action = $localReplacement[$key]
758
- if ($action -is [ScriptBlock]) {
759
- . $action $character
760
- } else {
761
- $action
762
- }
763
- }
764
- }
765
- }
754
+
766
755
$this.PathAttribute = [Ordered]@{
767
- "data-l-order" = $N
756
+ "data-l-order" = $Order
768
757
"data-l-axiom" = $Axiom
769
758
"data-l-rules" = ConvertTo-Json $Rule
770
759
"data-l-expanded" = $finalState
771
760
}
761
+
762
+ $MatchesAny = "(?> $($variable.Keys -join '|'))"
763
+ $allMatches = @([Regex]::Matches($finalState, $MatchesAny, 'IgnoreCase,IgnorePatternWhitespace'))
764
+ $matchCache = @{}
765
+ :nextMatch foreach ($match in $allMatches) {
766
+ $m = "$match"
767
+ if (-not $matchCache[$m]) {
768
+ foreach ($key in $Variable.Keys) {
769
+ if (-not ($match -match $key)) { continue }
770
+ # if ($variable[$key] -isnot [ScriptBlock]) { continue }
771
+ $matchCache[$m] = $localReplacement[$key]
772
+ break
773
+ }
774
+ }
775
+
776
+ if ($matchCache[$m] -is [ScriptBlock]) {
777
+ $Orderull = . $matchCache[$m] $match
778
+ continue nextMatch
779
+ }
780
+ }
781
+
772
782
return $this
773
783
774
784
</Script >
0 commit comments