Skip to content

Commit 14bf1d0

Browse files
committed
Simplify
1 parent b79e70a commit 14bf1d0

32 files changed

+53
-601
lines changed

src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void ReplaceBuildShouldBeSuccess(string templatePath, string resul
2626
IParsingContext parsingContext = new ParsingContext(Input.Input.Empty, []);
2727
for (int i = 0; i < keys.Length; i++)
2828
{
29-
parsingContext[keys[i]] = Placeholder.Placeholder.CreateEmpty(keys[i], values[i]);
29+
parsingContext[keys[i]] = Placeholder.CreateEmpty(keys[i], values[i]);
3030
}
3131

3232
var result = replaceBuilder.Build(ref parsingContext);

src/SimpleStateMachine.StructuralSearch/Constant.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,6 @@ internal static class Constant
135135
/// </summary>
136136
public static readonly string Should = $"{Equals}{More}";
137137

138-
/// <summary>
139-
/// Parenthesis chars: '(' and ')'
140-
/// </summary>
141-
public static readonly (char, char) Parentheses = (LeftParenthesis, RightParenthesis);
142-
143-
/// <summary>
144-
/// Parenthesis chars: '[' and ']'
145-
/// </summary>
146-
public static readonly (char, char) SquareParentheses = (LeftSquareParenthesis, RightSquareParenthesis);
147-
148-
/// <summary>
149-
/// Parenthesis chars: '{ and '}'
150-
/// </summary>
151-
public static readonly (char, char) CurlyParentheses = (LeftCurlyParenthesis, RightCurlyParenthesis);
152-
153-
/// <summary>
154-
/// Parenthesis chars: '(' and ')', '{ and '}', '{ and '}'
155-
/// </summary>
156-
public static readonly (char, char)[] AllParentheses = [Parentheses, SquareParentheses, CurlyParentheses];
157-
158138
/// <summary>
159139
/// Parenthesis chars: '(' and ')', '{ and '}', '{ and '}'
160140
/// </summary>

src/SimpleStateMachine.StructuralSearch/Context/IParsingContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using SimpleStateMachine.StructuralSearch.Input;
33
using SimpleStateMachine.StructuralSearch.Operator.Logical;
4-
using SimpleStateMachine.StructuralSearch.Placeholder;
54

65
namespace SimpleStateMachine.StructuralSearch.Context;
76

src/SimpleStateMachine.StructuralSearch/Context/ParsingContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using SimpleStateMachine.StructuralSearch.Input;
33
using SimpleStateMachine.StructuralSearch.Operator.Logical;
4-
using SimpleStateMachine.StructuralSearch.Placeholder;
54

65
namespace SimpleStateMachine.StructuralSearch.Context;
76

src/SimpleStateMachine.StructuralSearch/CustomParsers/Parsers.cs

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

src/SimpleStateMachine.StructuralSearch/CustomParsers/PlaceholderParser.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ protected override Parser<char, string> BuildParser(Func<Parser<char, string>?>
6060
var token = Parser.OneOf(simpleString, Grammar.WhiteSpaces).Try();
6161
Parser<char, string>? term = null;
6262

63-
var parenthesised = Parsers.BetweenParentheses
64-
(
65-
expr: Parser.Rec(() => term ?? throw new ArgumentNullException(nameof(term))),
66-
mapFunc: (c1, s, c2) => $"{c1}{s}{c2}"
67-
);
63+
var parenthesised = Parser.Rec(() => term ?? throw new ArgumentNullException(nameof(term)))
64+
.BetweenParentheses((c1, s, c2) => $"{c1}{s}{c2}");
6865

6966
term = Parser.OneOf(parenthesised, token).Many().JoinToString();
7067

@@ -94,7 +91,7 @@ public override bool TryParse(ref ParseState<char> state, ref PooledList<Expecte
9491
result = match.Value;
9592
if (res)
9693
{
97-
var placeholderObj = new Placeholder.Placeholder
94+
var placeholderObj = new Placeholder
9895
(
9996
name: _name,
10097
match: match

src/SimpleStateMachine.StructuralSearch/Extensions/ParserExtensions.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ internal static class ParserExtensions
1010
public static Parser<TToken, T> Try<TToken, T>(this Parser<TToken, T> parser)
1111
=> Parser.Try(parser ?? throw new ArgumentNullException(nameof(parser)));
1212

13-
public static Parser<TToken, IEnumerable<T>> AsMany<TToken, T>(this Parser<TToken, T> parser)
14-
=> parser.Select(IEnumerable<T> (x) => [x]);
15-
16-
public static Parser<TToken, T> AsLazy<TToken, T>(this Func<Parser<TToken, T>> parser)
17-
=> Parser.Rec(() => parser() ?? throw new ArgumentNullException(nameof(parser)));
18-
1913
public static Parser<TToken, IEnumerable<T>> AtLeastOnceUntilNot<TToken, T, U>(this Parser<TToken, T> parser,
2014
Parser<TToken, U> terminator) =>
2115
parser != null
@@ -44,8 +38,8 @@ public static Parser<char, Match<T>> Match<T>(this Parser<char, T> parser)
4438
var line = new LinePosition(oldPos.Line, newPos.Line);
4539
var column = new ColumnPosition(oldPos.Col, newPos.Col);
4640
var offset = new OffsetPosition(oldOffset, newOffset);
47-
var Length = newOffset - oldOffset;
48-
return new Match<T>(result, Length, column, line, offset);
41+
var length = newOffset - oldOffset;
42+
return new Match<T>(result, length, column, line, offset);
4943
},
5044
Parser<char>.CurrentPos, Parser<char>.CurrentOffset,
5145
parser,
@@ -80,4 +74,12 @@ public static Parser<char, T> ParenthesisedOptional<T, TResult>(this Parser<char
8074
public static Parser<TToken, Parser<TToken, T>> SelectToParser<TToken, T>(this Parser<TToken, T> parser,
8175
Func<T, Parser<TToken, T>, Parser<TToken, T>> selectFunc)
8276
=> parser.Select(value => selectFunc(value, parser));
77+
78+
public static Parser<char, TResult> BetweenParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
79+
{
80+
var parentheses= Parser.Map(mapFunc, CommonParser.LeftParenthesis, parser, CommonParser.RightParenthesis);
81+
var curlyParentheses= Parser.Map(mapFunc, CommonParser.LeftCurlyParenthesis, parser, CommonParser.RightCurlyParenthesis);
82+
var squareParentheses= Parser.Map(mapFunc, CommonParser.LeftSquareParenthesis, parser, CommonParser.RightSquareParenthesis);
83+
return Parser.OneOf(parentheses, curlyParentheses, squareParentheses);
84+
}
8385
}

src/SimpleStateMachine.StructuralSearch/FindParserResult.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using SimpleStateMachine.StructuralSearch.Placeholder;
32

43
namespace SimpleStateMachine.StructuralSearch;
54

src/SimpleStateMachine.StructuralSearch/Placeholder/IPlaceholder.cs renamed to src/SimpleStateMachine.StructuralSearch/IPlaceholder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace SimpleStateMachine.StructuralSearch.Placeholder;
1+
namespace SimpleStateMachine.StructuralSearch;
22

33
public interface IPlaceholder
44
{

src/SimpleStateMachine.StructuralSearch/Parameters/PlaceholderParameter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SimpleStateMachine.StructuralSearch.Context;
2-
using SimpleStateMachine.StructuralSearch.Placeholder;
32

43
namespace SimpleStateMachine.StructuralSearch.Parameters;
54

0 commit comments

Comments
 (0)