Skip to content

Commit 13691b3

Browse files
committed
IReplaceRule with check method
1 parent c84251a commit 13691b3

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/SimpleStateMachine.StructuralSearch/Rules/FindRule/EmptyRule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ public class EmptyRule: IRule
55
public bool Execute(ref IParsingContext context)
66
{
77
return true;
8-
98
}
109
}
1110

src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/IReplaceRule.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ namespace SimpleStateMachine.StructuralSearch;
77
public interface IReplaceRule
88
{
99
IEnumerable<ReplaceSubRule> Rules { get; }
10-
IRule ConditionRule { get; }
10+
bool IsMatch(ref IParsingContext context);
1111
}
1212

1313
public class EmptyReplaceRule : IReplaceRule
1414
{
1515
public IEnumerable<ReplaceSubRule> Rules { get; } = Array.Empty<ReplaceSubRule>();
16-
public IRule ConditionRule => Rule.Empty;
16+
17+
public bool IsMatch(ref IParsingContext context)
18+
{
19+
return Rule.Empty.Execute(ref context);
20+
}
1721
}

src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceRule.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public ReplaceRule(IRule conditionRule, IEnumerable<ReplaceSubRule> rules)
1616
Rules = rules;
1717
}
1818

19+
public bool IsMatch(ref IParsingContext context)
20+
{
21+
return ConditionRule.Execute(ref context);
22+
}
23+
1924
public override string ToString()
2025
{
2126
return $"{ConditionRule}{Constant.Space}{Constant.Then}{Constant.Space}{string.Join(Constant.Comma, Rules)}";

src/SimpleStateMachine.StructuralSearch/StructuralSearchParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public IEnumerable<FindParserResult> ApplyReplaceRule(ref IParsingContext contex
6969
List<ReplaceSubRule> rules = new();
7070
foreach (var replaceRule in _replaceRules)
7171
{
72-
if (replaceRule.ConditionRule.Execute(ref context))
72+
if (replaceRule.IsMatch(ref context))
7373
{
7474
rules.AddRange(replaceRule.Rules);
7575
}

0 commit comments

Comments
 (0)