Skip to content

Commit 74be7e5

Browse files
committed
Test rule parser
1 parent aff0f5e commit 74be7e5

File tree

2 files changed

+15
-8
lines changed
  • src

2 files changed

+15
-8
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ internal static class Program
1010
{
1111
static void Main(string[] args)
1212
{
13+
var result = FindRuleParser.ParseTemplate("$var$ Equals \"125\"");
14+
1315
var t = ExprParser.ParseOrThrow("( 2 + 2 ) * 2");
1416
var resw = t.Invoke();
1517
var test = String("return ")

src/SimpleStateMachine.StructuralSearch/StructuralSearch/RulesParser.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static FindRuleParser()
3939
Parser.AnyCharExcept(Constant.DoubleQuotes)
4040
.AtLeastOnceString()
4141
.Between(CommonParser.DoubleQuotes)
42-
.Trim()
4342
.Select(x => new StringParameter(x))
4443
.As<char, StringParameter, IRuleParameter>()
44+
.Trim()
4545
.Try();
4646

4747
public static readonly Parser<char, IRuleParameter> Parameter =
@@ -54,7 +54,7 @@ static FindRuleParser()
5454
Parsers.EnumExcept(true, Rules.SubRuleType.Is, Rules.SubRuleType.In)
5555
.Trim();
5656

57-
public static readonly Parser<char, IRule> UnaryRule =
57+
public static readonly Parser<char, IRule> UnarySubRule =
5858
Parser.Map((type, param) => new UnarySubRule(type, param),
5959
SubRuleType, Parameter)
6060
.As<char, UnarySubRule, IRule>()
@@ -64,13 +64,13 @@ static FindRuleParser()
6464
Parsers.Enum<PlaceholderType>(true)
6565
.Trim();
6666

67-
public static readonly Parser<char, IRule> IsRule =
67+
public static readonly Parser<char, IRule> IsSubRule =
6868
Parser.Map((type, param) => new IsRule(type, param),
6969
Parsers.EnumValue(Rules.SubRuleType.Is), PlaceholderType)
7070
.As<char, IsRule, IRule>()
7171
.Try();
7272

73-
public static readonly Parser<char, IRule> InRule =
73+
public static readonly Parser<char, IRule> InSubRule =
7474
Parser.Map((type, param) => new InRule(type, param),
7575
Parsers.EnumValue(Rules.SubRuleType.In), Parameters)
7676
.As<char, InRule, IRule>()
@@ -108,9 +108,9 @@ public static readonly Parser<char, Func<IRule, IRule>> Not
108108
public static readonly Parser<char, IRule> Expr = ExpressionParser.Build<char, IRule>(
109109
rule => (
110110
Parser.OneOf(
111-
UnaryRule,
112-
IsRule,
113-
InRule,
111+
UnarySubRule,
112+
IsSubRule,
113+
InSubRule,
114114
CommonParser.Parenthesised(rule, x => x.Trim())
115115
),
116116
new[]
@@ -128,9 +128,14 @@ public static readonly Parser<char, Func<IRule, IRule>> Not
128128

129129
public static readonly Parser<char, IRule> Rule =
130130
Parser.Map((name, rule) => new Rule(name, rule),
131-
CommonTemplateParser.Placeholder,
131+
CommonTemplateParser.Placeholder.Trim(),
132132
Expr)
133133
.As<char, Rule, IRule>();
134+
135+
public static IRule ParseTemplate(string str)
136+
{
137+
return Rule.ParseOrThrow(str);
138+
}
134139

135140

136141
// public static readonly Parser<char, IRule> Rule =

0 commit comments

Comments
 (0)