Skip to content

Commit 8e25da0

Browse files
committed
refact
1 parent 91f2d4b commit 8e25da0

File tree

8 files changed

+61
-67
lines changed

8 files changed

+61
-67
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ internal static class Program
77
{
88
static void Main(string[] args)
99
{
10-
var result = FindRuleParser.ParseTemplate("$var$ Is int");
11-
var result1 = result.Execute("125");
10+
var result = StructuralSearch.ParseFindRule("$var$ Is int or equals \"test\"");
11+
var result1 = result.Execute("test");
1212

1313

1414
var t = ExprParser.ParseOrThrow("( 2 + 2 ) * 2");

src/SimpleStateMachine.StructuralSearch/Extensions/CharExtensions.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/SimpleStateMachine.StructuralSearch/StructuralSearch/CommonParser.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
using static Pidgin.Parser;
44
namespace SimpleStateMachine.StructuralSearch
55
{
6-
public static class CommonParser
6+
internal static class CommonParser
77
{
8-
public static readonly Parser<char, string> Empty
8+
internal static readonly Parser<char, string> Empty
99
= Parsers.String(Constant.Empty, false);
1010

11-
public static readonly Parser<char, char> AnyChar
11+
internal static readonly Parser<char, char> AnyChar
1212
= AnyCharExcept(Constant.FindTemplate.All());
1313

14-
public static readonly Parser<char, char> Space
14+
internal static readonly Parser<char, char> Space
1515
= Char(Constant.Space);
1616

17-
public static readonly Parser<char, string> AnyString
17+
internal static readonly Parser<char, string> AnyString
1818
= AnyChar.AtLeastOnceString();
1919

20-
public static readonly Parser<char, string> Spaces
20+
internal static readonly Parser<char, string> Spaces
2121
= Space.AtLeastOnceString();
2222

23-
public static readonly Parser<char, string> LineEnds
23+
internal static readonly Parser<char, string> LineEnds
2424
= EndOfLine.AtLeastOnceString();
2525

26-
public static readonly Parser<char, string> WhiteSpaces
26+
internal static readonly Parser<char, string> WhiteSpaces
2727
= OneOf(Spaces, LineEnds);
2828

29-
public static readonly Parser<char, string> Identifier
29+
internal static readonly Parser<char, string> Identifier
3030
= Letter.Then(AnyString, (h, t) => h + t);
3131

32-
public static readonly Parser<char, char> Comma
32+
internal static readonly Parser<char, char> Comma
3333
= Char(Constant.Comma);
3434

35-
public static readonly Parser<char, char> DoubleQuotes
35+
internal static readonly Parser<char, char> DoubleQuotes
3636
= Char(Constant.DoubleQuotes);
3737

38-
public static readonly Parser<char, char> SingleQuotes
38+
internal static readonly Parser<char, char> SingleQuotes
3939
= Char(Constant.SingleQuotes);
4040

41-
public static Parser<char, T> Parenthesised<T>(Parser<char, T> parser, Func<Parser<char, string>, Parser<char, string>> custom)
41+
internal static Parser<char, T> Parenthesised<T>(Parser<char, T> parser, Func<Parser<char, string>, Parser<char, string>> custom)
4242
{
4343
return parser.Between(custom(Parsers.Stringc(Constant.LeftParenthesis)),
4444
custom(Parsers.Stringc(Constant.RightParenthesis)));

src/SimpleStateMachine.StructuralSearch/StructuralSearch/CommonTemplateParser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
namespace SimpleStateMachine.StructuralSearch
77
{
8-
public static class CommonTemplateParser
8+
internal static class CommonTemplateParser
99
{
10-
public static readonly Parser<char, char> AnyCharWithPlshd =
10+
internal static readonly Parser<char, char> AnyCharWithPlshd =
1111
AnyCharExcept(Constant.FindTemplate.AllExclude(Constant.PlaceholderSeparator));
1212

13-
public static readonly Parser<char, string> Placeholder
13+
internal static readonly Parser<char, string> Placeholder
1414
= CommonParser.Identifier.Between(Char(Constant.PlaceholderSeparator));
1515

16-
public static readonly Parser<char, string> StringWithPlshd
16+
internal static readonly Parser<char, string> StringWithPlshd
1717
= AnyCharWithPlshd.AtLeastOnceString();
1818

1919
//can be contains one $
20-
public static readonly Parser<char, string> StringWithoutPlaceholder
20+
internal static readonly Parser<char, string> StringWithoutPlaceholder
2121
= Any.AtLeastOnceAsStringUntilNot(Placeholder);
2222

23-
public static readonly Parser<char, string> Token
23+
internal static readonly Parser<char, string> Token
2424
= OneOf(Placeholder.Try(),
2525
CommonParser.WhiteSpaces.Try(),
2626
ParsingConfiguration.Comment.Try(),

src/SimpleStateMachine.StructuralSearch/StructuralSearch/FindTemplateParser.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleStateMachine.StructuralSearch
66
{
7-
public static class FindTemplateParser
7+
internal static class FindTemplateParser
88
{
99
static FindTemplateParser()
1010
{
@@ -22,30 +22,30 @@ static FindTemplateParser()
2222
.JoinResults();
2323
}
2424

25-
public static readonly Parser<char, IEnumerable<Parser<char, string>>> Empty =
25+
internal static readonly Parser<char, IEnumerable<Parser<char, string>>> Empty =
2626
ParserToParser.ResultAsParser(CommonParser.Empty)
2727
.AsMany();
2828

29-
public static readonly Parser<char, Parser<char, string>> AnyString =
29+
internal static readonly Parser<char, Parser<char, string>> AnyString =
3030
ParserToParser.ResultAsParser(CommonParser.AnyString)
3131
.Try();
3232

33-
public static readonly Parser<char, Parser<char, string>> WhiteSpaces =
33+
internal static readonly Parser<char, Parser<char, string>> WhiteSpaces =
3434
ParserToParser.ResultAsParser(CommonParser.WhiteSpaces)
3535
.Try();
3636

37-
public static readonly Parser<char, Parser<char, string>> Placeholder =
37+
internal static readonly Parser<char, Parser<char, string>> Placeholder =
3838
CommonTemplateParser.Placeholder
3939
.Select(name => new PlaceholderParser(name))
4040
.As<char, PlaceholderParser, Parser<char, string>>();
4141

42-
public static readonly Parser<char, IEnumerable<Parser<char, string>>> Token =
42+
internal static readonly Parser<char, IEnumerable<Parser<char, string>>> Token =
4343
Parser.OneOf(AnyString, Placeholder, WhiteSpaces)
4444
.AsMany();
4545

46-
public static readonly Parser<char, IEnumerable<Parser<char, string>>> Term;
46+
internal static readonly Parser<char, IEnumerable<Parser<char, string>>> Term;
4747

48-
public static readonly Parser<char, IEnumerable<Parser<char, string>>> Parenthesised;
48+
internal static readonly Parser<char, IEnumerable<Parser<char, string>>> Parenthesised;
4949

5050
private static readonly Parser<char, Parser<char, string>> TemplateParser;
5151

@@ -71,26 +71,26 @@ internal static Parser<char, SourceMatch> ParseTemplate(string str)
7171
// }
7272

7373

74-
// public static readonly Parser<char, Parser<char, SourceMatch>> Empty =
74+
// internal static readonly Parser<char, Parser<char, SourceMatch>> Empty =
7575
// ParserToParser.ResultAsMatch(CommonParser.Empty);
7676
//
77-
// public static readonly Parser<char, Parser<char, SourceMatch>> AnyString =
77+
// internal static readonly Parser<char, Parser<char, SourceMatch>> AnyString =
7878
// ParserToParser.ResultAsMatch(CommonParser.AnyString).Try();
7979
//
80-
// public static readonly Parser<char, Parser<char, SourceMatch>> WhiteSpaces =
80+
// internal static readonly Parser<char, Parser<char, SourceMatch>> WhiteSpaces =
8181
// ParserToParser.ResultAsMatch(CommonParser.WhiteSpaces).Try();
8282
//
83-
// public static readonly Parser<char, Parser<char, SourceMatch>> Placeholder =
83+
// internal static readonly Parser<char, Parser<char, SourceMatch>> Placeholder =
8484
// CommonTemplateParser.Placeholder
8585
// .Select(name => new PlaceholderParser(name))
8686
// .Cast<Parser<char, SourceMatch>>();
8787
//
88-
// public static readonly Parser<char, Parser<char, SourceMatch>> Token =
88+
// internal static readonly Parser<char, Parser<char, SourceMatch>> Token =
8989
// Parser.OneOf(AnyString, Placeholder, WhiteSpaces);
9090
//
91-
// public static readonly Parser<char, Parser<char, SourceMatch>> Term;
91+
// internal static readonly Parser<char, Parser<char, SourceMatch>> Term;
9292
//
93-
// public static readonly Parser<char, Parser<char, SourceMatch>> Parenthesised;
93+
// internal static readonly Parser<char, Parser<char, SourceMatch>> Parenthesised;
9494
//
9595
// private static readonly Parser<char, Parser<char, SourceMatch>> TemplateParser;
9696
//

src/SimpleStateMachine.StructuralSearch/StructuralSearch/ReplaceTemplateParser.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace SimpleStateMachine.StructuralSearch
77
{
8-
public class ReplaceTemplateParser
8+
internal class ReplaceTemplateParser
99
{
1010
static ReplaceTemplateParser()
1111
{
@@ -22,29 +22,29 @@ static ReplaceTemplateParser()
2222
.MergerMany();
2323
}
2424

25-
public static readonly Parser<char, IReplaceStep> Empty =
25+
internal static readonly Parser<char, IReplaceStep> Empty =
2626
ParserToReplace.ResultAsReplace(CommonParser.Empty);
2727

28-
public static readonly Parser<char, IReplaceStep> AnyString =
28+
internal static readonly Parser<char, IReplaceStep> AnyString =
2929
ParserToReplace.ResultAsReplace(CommonParser.AnyString)
3030
.Try();
3131

32-
public static readonly Parser<char, IReplaceStep> WhiteSpaces =
32+
internal static readonly Parser<char, IReplaceStep> WhiteSpaces =
3333
ParserToReplace.ResultAsReplace(CommonParser.WhiteSpaces)
3434
.Try();
3535

36-
public static readonly Parser<char, IReplaceStep> Placeholder =
36+
internal static readonly Parser<char, IReplaceStep> Placeholder =
3737
CommonTemplateParser.Placeholder.Select(name=> new PlaceholderReplace(name))
3838
.As<char, PlaceholderReplace, IReplaceStep>()
3939
.Try();
4040

41-
public static readonly Parser<char, IEnumerable<IReplaceStep>> Token =
41+
internal static readonly Parser<char, IEnumerable<IReplaceStep>> Token =
4242
Parser.OneOf(AnyString, Placeholder, WhiteSpaces)
4343
.AsMany();
4444

45-
public static readonly Parser<char, IEnumerable<IReplaceStep>> Term;
45+
internal static readonly Parser<char, IEnumerable<IReplaceStep>> Term;
4646

47-
public static readonly Parser<char, IEnumerable<IReplaceStep>> Parenthesised;
47+
internal static readonly Parser<char, IEnumerable<IReplaceStep>> Parenthesised;
4848

4949
private static readonly Parser<char, IEnumerable<IReplaceStep>> TemplateParser;
5050

src/SimpleStateMachine.StructuralSearch/StructuralSearch/RulesParser.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@
77

88
namespace SimpleStateMachine.StructuralSearch
99
{
10-
public static class FindRuleParser
10+
internal static class FindRuleParser
1111
{
12-
public static Parser<char, Func<IRule, IRule, IRule>> Binary(Parser<char, BinaryRuleType> op)
12+
internal static Parser<char, Func<IRule, IRule, IRule>> Binary(Parser<char, BinaryRuleType> op)
1313
=> op.Select<Func<IRule, IRule, IRule>>(type => (l, r) => new BinaryRule(type, l, r));
1414

15-
public static Parser<char, Func<IRule, IRule>> Unary(Parser<char, UnaryRuleType> op)
15+
internal static Parser<char, Func<IRule, IRule>> Unary(Parser<char, UnaryRuleType> op)
1616
=> op.Select<Func<IRule, IRule>>(type => param => new UnaryRule(type, param));
1717

1818

19-
public static readonly Parser<char, Func<IRule, IRule, IRule>> And
19+
internal static readonly Parser<char, Func<IRule, IRule, IRule>> And
2020
= Binary(Parsers.EnumValue(BinaryRuleType.And).Trim());
2121

22-
public static readonly Parser<char, Func<IRule, IRule, IRule>> Or
22+
internal static readonly Parser<char, Func<IRule, IRule, IRule>> Or
2323
= Binary(Parsers.EnumValue(BinaryRuleType.Or).Trim());
2424

25-
public static readonly Parser<char, Func<IRule, IRule, IRule>> NOR
25+
internal static readonly Parser<char, Func<IRule, IRule, IRule>> NOR
2626
= Binary(Parsers.EnumValue(BinaryRuleType.NOR).Trim());
2727

28-
public static readonly Parser<char, Func<IRule, IRule, IRule>> XOR
28+
internal static readonly Parser<char, Func<IRule, IRule, IRule>> XOR
2929
= Binary(Parsers.EnumValue(BinaryRuleType.XOR).Trim());
3030

31-
public static readonly Parser<char, Func<IRule, IRule, IRule>> NAND
31+
internal static readonly Parser<char, Func<IRule, IRule, IRule>> NAND
3232
= Binary(Parsers.EnumValue(BinaryRuleType.NAND).Trim());
3333

34-
public static readonly Parser<char, Func<IRule, IRule, IRule>> XNOR
34+
internal static readonly Parser<char, Func<IRule, IRule, IRule>> XNOR
3535
= Binary(Parsers.EnumValue(BinaryRuleType.XNOR).Trim());
3636

37-
public static readonly Parser<char, Func<IRule, IRule>> Not
37+
internal static readonly Parser<char, Func<IRule, IRule>> Not
3838
= Unary(Parsers.EnumValue(UnaryRuleType.Not).Trim());
3939

40-
public static readonly Parser<char, IRule> Expr = ExpressionParser.Build<char, IRule>(
40+
internal static readonly Parser<char, IRule> Expr = ExpressionParser.Build<char, IRule>(
4141
rule => (
4242
Parser.OneOf(
4343
SubRuleParser.UnarySubRule,
@@ -58,13 +58,13 @@ public static readonly Parser<char, Func<IRule, IRule>> Not
5858
)
5959
);
6060

61-
public static readonly Parser<char, IRule> Rule =
61+
internal static readonly Parser<char, IRule> Rule =
6262
Parser.Map((name, rule) => new Rule(name, rule),
6363
CommonTemplateParser.Placeholder.Trim(),
6464
Expr)
6565
.As<char, Rule, IRule>();
6666

67-
public static IRule ParseTemplate(string str)
67+
internal static IRule ParseTemplate(string str)
6868
{
6969
return Rule.ParseOrThrow(str);
7070
}

src/SimpleStateMachine.StructuralSearch/StructuralSearch/StructuralSearch.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Pidgin;
22
using SimpleStateMachine.StructuralSearch.ReplaceTemplate;
3+
using SimpleStateMachine.StructuralSearch.Rules;
34

45
namespace SimpleStateMachine.StructuralSearch
56
{
@@ -10,5 +11,8 @@ public static Parser<char, SourceMatch> ParseFindTemplate(string template)
1011

1112
public static IReplaceBuilder ParseReplaceTemplate(string template)
1213
=> ReplaceTemplateParser.ParseTemplate(template);
14+
15+
public static IRule ParseFindRule(string template)
16+
=> FindRuleParser.ParseTemplate(template);
1317
}
1418
}

0 commit comments

Comments
 (0)