Skip to content

Commit e9cd5d8

Browse files
committed
Optimization parameters, escape dote for string parameter, new replace template parsing
1 parent 285a698 commit e9cd5d8

File tree

19 files changed

+173
-107
lines changed

19 files changed

+173
-107
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Expr.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public double Invoke()
137137
BinaryOperatorType.Mul => Left.Invoke() * Right.Invoke(),
138138
BinaryOperatorType.Div => Left.Invoke() / Right.Invoke(),
139139
BinaryOperatorType.Sub => Left.Invoke() - Right.Invoke(),
140+
_ => throw new ArgumentOutOfRangeException()
140141
};
141142
}
142143
}

src/SimpleStateMachine.StructuralSearch.Tests/ConfigurationFile/FullConfig.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
$var$ = $value1$;
2121
FindRules:
2222
- $sign$ In ("Is", "==", "!=", "is not")
23-
- $value$ In ($value1$, "$value1$.Value", $value2$, "$value2$.Value")
23+
- $value$ In ($value1$, "$value1$\.Value", $value2$, "$value2$\.Value")
2424
ReplaceTemplate: |-
2525
$var$ = $value1$ ?? $value2$;
2626
ReplaceRules:

src/SimpleStateMachine.StructuralSearch.Tests/ConfigurationFile/ShortConfig.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$var$ = $value1$;
2020
FindRules:
2121
- $sign$ In ("Is", "==", "!=", "is not")
22-
- $value$ In ($value1$, "$value1$.Value", $value2$, "$value2$.Value")
22+
- $value$ In ($value1$, "$value1$\.Value", $value2$, "$value2$\.Value")
2323
ReplaceTemplate: |-
2424
$var$ = $value1$ ?? $value2$;
2525
ReplaceRules:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
$sign$ In ("Is", "==", "!=", "is not")
2-
$value$ In ($value1$, "$value1$.Value", $value2$, "$value2$.Value")
2+
$value$ In ($value1$, "$value1$\.Value", $value2$, "$value2$\.Value")

src/SimpleStateMachine.StructuralSearch.Tests/FindRuleParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void FindRuleExprParsingShouldBeEqualsCustomResult(string ruleStr, string
5050
Assert.Equal(_ruleStr, customResult.ToLower());
5151
}
5252
[Theory]
53-
[InlineData("FindRule/NullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"", "$value$ In $value1$,\"$value1$.Value\",$value2$,\"$value2$.Value\"")]
53+
[InlineData("FindRule/NullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"", "$value$ In $value1$,\"$value1$\\.Value\",$value2$,\"$value2$\\.Value\"")]
5454
[InlineData("FindRule/AssignmentNullUnionOperator.txt", "$sign$ In \"Is\",\"==\",\"!=\",\"is not\"")]
5555
public void FindRuleParsingFromFileShouldBeSuccess(string filePath, params string[] customResult)
5656
{

src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace SimpleStateMachine.StructuralSearch.Tests
1010
public class ReplaceTemplateTests
1111
{
1212
[Theory]
13-
[InlineData("ReplaceTemplate/NullUnionOperator.txt", 10)]
14-
[InlineData("ReplaceTemplate/AssignmentNullUnionOperator.txt", 6)]
15-
[InlineData("ReplaceTemplate/TernaryOperator.txt", 11)]
13+
[InlineData("ReplaceTemplate/NullUnionOperator.txt", 6)]
14+
[InlineData("ReplaceTemplate/AssignmentNullUnionOperator.txt", 4)]
15+
[InlineData("ReplaceTemplate/TernaryOperator.txt", 7)]
1616
public void ReplaceTemplateParsingShouldHaveStepCount(string templatePath, int stepsCount)
1717
{
1818
var replaceTemplate = File.ReadAllText(templatePath);

src/SimpleStateMachine.StructuralSearch/Constant.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace SimpleStateMachine.StructuralSearch
1+
using System.Linq;
2+
3+
namespace SimpleStateMachine.StructuralSearch
24
{
35
public static partial class Constant
46
{
@@ -136,5 +138,18 @@ public static partial class Constant
136138
/// Parenthesis chars: '(' and ')', '{ and '}', '{ and '}'
137139
/// </summary>
138140
public static readonly (char, char)[] AllParenthesised = { Parenthesis, SquareParenthesis, CurlyParenthesis };
141+
142+
/// <summary>
143+
/// Parenthesis chars: '(' and ')', '{ and '}', '{ and '}'
144+
/// </summary>
145+
public static readonly char[] AllParenthesisArray =
146+
{
147+
LeftParenthesis,
148+
RightParenthesis,
149+
LeftSquareParenthesis,
150+
RightSquareParenthesis,
151+
LeftCurlyParenthesis,
152+
RightCurlyParenthesis
153+
};
139154
}
140155
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Linq;
2+
3+
namespace SimpleStateMachine.StructuralSearch.Extensions;
4+
5+
public static class ArrayExpression
6+
{
7+
public static T[] Add<T>(this T[] array, params T[] values)
8+
{
9+
var list = array.ToList();
10+
list.AddRange(values);
11+
return list.ToArray();
12+
}
13+
}

src/SimpleStateMachine.StructuralSearch/Rules/FindRule/SubRule.cs renamed to src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinarySubRule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
namespace SimpleStateMachine.StructuralSearch.Rules
55
{
6-
public class SubRule : IRule
6+
public class BinarySubRule : IRule
77
{
88
public SubRuleType Type { get; }
99

1010
public IRuleParameter Left { get; }
1111

1212
public IRuleParameter Right { get; }
1313

14-
public SubRule(SubRuleType type, IRuleParameter left, IRuleParameter right)
14+
public BinarySubRule(SubRuleType type, IRuleParameter left, IRuleParameter right)
1515
{
1616
Type = type;
1717
Left = left;

src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderPropertyParser.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ public static class PlaceholderPropertyParser
4545
.Select(property => new Func<PlaceholderParameter, IRuleParameter>(placeholder =>
4646
new PlaceholderLenghtParameter(placeholder, property)))
4747
.Try();
48-
49-
public static readonly Parser<char, IRuleParameter> PlaceholderPropertyParameter =
50-
CommonTemplateParser.Placeholder.Before(CommonParser.Dote)
51-
.Select(name => new PlaceholderParameter(name))
52-
.Then(Parser.OneOf(Lenght, File, Column, Offset, Line),
53-
(placeholder, func) => func(placeholder))
54-
.TrimStart()
48+
49+
public static readonly Parser<char, Func<PlaceholderParameter, IRuleParameter>> PlaceholderPropertyParameter =
50+
CommonParser.Dote.Then(Parser.OneOf(Lenght, File, Column, Offset, Line)).Optional()
51+
.Select(property => new Func<PlaceholderParameter, IRuleParameter>(placeholder =>
52+
property.HasValue ? property.Value(placeholder) : placeholder))
5553
.Try();
54+
55+
// public static readonly Parser<char, IRuleParameter> PlaceholderPropertyParameter =
56+
// CommonTemplateParser.Placeholder.Before(CommonParser.Dote)
57+
// .Select(name => new PlaceholderParameter(name))
58+
// .Then(Parser.OneOf(Lenght, File, Column, Offset, Line),
59+
// (placeholder, func) => func(placeholder))
60+
// .TrimStart()
61+
// .Try();
5662
}
5763
}

0 commit comments

Comments
 (0)