Skip to content

Commit d37eb66

Browse files
Merge pull request #36 from SimpleStateMachine/personal/rsolovev/v3.0
Mark implementation as internal
2 parents b5e1b61 + 208ed8e commit d37eb66

File tree

112 files changed

+413
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+413
-604
lines changed

src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,18 @@ internal static class Program
99
{
1010
static void Main(string[] args)
1111
{
12-
13-
var pr = Parser.String("var").Trim();
14-
var str = pr.ParseOrThrow("var");
15-
str = pr.ParseOrThrow(" var");
16-
str = pr.ParseOrThrow("var ");
17-
str = pr.ParseOrThrow(" var ");
18-
var source = "test;;;test;;;.";
19-
var parser = Parser.OneOf(Parser<char>.Any.ThenReturn(Unit.Value), Parser<char>.End);
20-
21-
22-
var t = Parser<char>.Any.AtLeastOnceAsStringUntil(Lookahead(String(";").Then(Not(String(";"))).Try())).ParseOrThrow(source);
12+
//StructuralSearch.ParseFindTemplate()
2313

2414

2515
var path = "Test.txt";
2616
var oldText = "0123456789";
2717
var text = "test";
2818
File.WriteAllText(path, oldText);
2919

30-
using var stringReader = text.AsStream();
31-
using var streamWriter = File.OpenWrite(path);
32-
33-
stringReader.CopyPartTo(streamWriter, 0, 7);
20+
// using var stringReader = text.AsStream();
21+
// using var streamWriter = File.OpenWrite(path);
22+
//
23+
// stringReader.CopyPartTo(streamWriter, 0, 7);
3424

3525
// var config = YmlHelper.Parse(
3626
// @"C:\Users\roman\GitHub\SimpleStateMachine.StructuralSearch\src\SimpleStateMachine.StructuralSearch.Tests\ConfigurationFile\FullConfig.yml");

src/SimpleStateMachine.StructuralSearch.Tests/ExamplesInput/TernaryOperator.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,34 @@ public class TernaryOperator
55
public int Test1()
66
{
77
var temp = 1;
8-
8+
99
if (temp == 2)
1010
return 3;
1111
else
1212
return 4;
1313
}
14-
14+
1515
public int Test2()
1616
{
1717
var temp = 5;
18-
18+
1919
if (temp == 6)
2020
return 7;
2121
else
2222
return 8;
2323
}
24-
24+
2525
public int Test3()
2626
{
2727
var temp2 = 1;
28-
28+
2929
if (temp2 == 2)
3030
return 3;
3131
else
32-
return 4;
32+
return 4;
3333
}
34-
34+
3535
public static void Test5()
3636
{
37-
3837
}
3938
}
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
namespace SimpleStateMachine.StructuralSearch.Tests.Examples
1+
namespace SimpleStateMachine.StructuralSearch.Tests.Examples;
2+
3+
public class TernaryOperator
24
{
3-
public class TernaryOperator
5+
public int Test1()
6+
{
7+
var temp = 1;
8+
9+
return temp == 2? 3 : 4;
10+
}
11+
12+
public int Test2()
13+
{
14+
var temp = 5;
15+
16+
return temp == 6? 7 : 8;
17+
}
18+
19+
public int Test3()
20+
{
21+
var temp2 = 1;
22+
23+
return temp2 == 2? 3 : 4;
24+
}
25+
26+
public static void Test5()
427
{
5-
public int Test1()
6-
{
7-
var temp = 1;
8-
9-
return temp == 2? 3 : 4;
10-
}
11-
12-
public int Test2()
13-
{
14-
var temp = 5;
15-
16-
return temp == 6? 7 : 8;
17-
}
18-
19-
public int Test3()
20-
{
21-
var temp2 = 1;
22-
23-
return temp2 == 2? 3 : 4;
24-
}
25-
26-
public static void Test5()
27-
{
28-
29-
}
3028
}
3129
}

src/SimpleStateMachine.StructuralSearch.Tests/FindTemplateParserTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ public static void SourceParsingBeFindTemplateShouldBeSuccess(string templatePat
2929
{
3030
var findTemplate = File.ReadAllText(templatePath);
3131
var source = File.ReadAllText(sourcePath);
32-
var input = Input.String(source);
32+
var input = Input.Input.String(source);
3333
var findParser = StructuralSearch.ParseFindTemplate(findTemplate);
34-
IParsingContext parsingContext = new ParsingContext(input);
35-
var matches = findParser.Parse(ref parsingContext);
34+
var matches = findParser.Parse(input);
3635
Assert.Single(matches);
3736

3837
var match = matches.First();

src/SimpleStateMachine.StructuralSearch.Tests/PlaceholderParserTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ public static class PlaceholderParserTests
1212
[InlineData("($test$)", "(value (test) )", "value (test) ")]
1313
public static void TemplateParsingShouldBeSuccess(string template, string source, string result)
1414
{
15-
var input = Input.String(source);
16-
IParsingContext parsingContext = new ParsingContext(input);
15+
var input = Input.Input.String(source);
1716
var templateParser = StructuralSearch.ParseFindTemplate(template);
18-
var matches = templateParser.Parse(ref parsingContext);
17+
var matches = templateParser.Parse(input);
1918

2019
Assert.Single(matches);
2120
var match = matches.First();
@@ -30,10 +29,9 @@ public static void TemplateParsingShouldBeSuccess(string template, string source
3029
[InlineData("$var$;.", "test;;;.", "test;;")]
3130
public static void TemplateParsingShouldBeSuccess2(string template, string source, params string[] values)
3231
{
33-
var input = Input.String(source);
34-
IParsingContext parsingContext = new ParsingContext(input);
32+
var input = Input.Input.String(source);
3533
var templateParser = StructuralSearch.ParseFindTemplate(template);
36-
var matches = templateParser.Parse(ref parsingContext);
34+
var matches = templateParser.Parse(input);
3735
Assert.Single(matches);
3836
var match = matches.First();
3937
Assert.Equal(match.Placeholders.Count, values.Length);

src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.IO;
22
using System.Linq;
33
using Pidgin;
4+
using SimpleStateMachine.StructuralSearch.ReplaceTemplate;
45
using Xunit;
56

67
namespace SimpleStateMachine.StructuralSearch.Tests;
@@ -15,11 +16,9 @@ public static void ReplaceTemplateParsingShouldHaveStepCount(string templatePath
1516
{
1617
var replaceTemplate = File.ReadAllText(templatePath);
1718
var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate);
18-
IParsingContext context = ParsingContext.Empty;
19-
var result = replaceBuilder.Build(ref context);
2019

2120
Assert.NotNull(replaceTemplate);
22-
Assert.Equal(replaceBuilder.Steps.Count(), stepsCount);
21+
Assert.Equal(((ReplaceBuilder)replaceBuilder).Steps.Count(), stepsCount);
2322
}
2423

2524
[Theory]
@@ -38,12 +37,12 @@ public static void ReplaceBuildShouldBeSuccess(string templatePath, string resul
3837
var replaceResult = File.ReadAllText(resultPath);
3938
var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate);
4039

41-
IParsingContext parsingContext = new ParsingContext(Input.Empty);
40+
IParsingContext parsingContext = new ParsingContext(Input.Input.Empty);
4241
for (int i = 0; i < keys.Length; i++)
4342
{
44-
parsingContext.AddPlaceholder(Placeholder.CreateEmpty(parsingContext, keys[i], values[i]));
43+
parsingContext[keys[i]] = Placeholder.CreateEmpty(parsingContext, keys[i], values[i]);
4544
}
46-
45+
4746
var result = replaceBuilder.Build(ref parsingContext);
4847

4948
Assert.NotNull(replaceTemplate);

src/SimpleStateMachine.StructuralSearch.Tests/StructurSearchParserTests.cs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,38 @@ public static void StructuralSearchShouldBeSuccess(string exampleName, string ex
1616
var parser = new StructuralSearchParser(config);
1717

1818
var fileInfo = new FileInfo(exampleFilePath);
19-
var input = Input.File(fileInfo);
20-
IParsingContext context = new ParsingContext(input);
21-
22-
var matches = parser.Parse(ref context);
19+
var input = Input.Input.File(fileInfo);
20+
var matches = parser.Parse(input);
2321
Assert.Equal(matches.Count(), matchesCount);
2422
}
2523

26-
[Theory]
27-
[InlineData("NullUnionOperator", 2)]
28-
[InlineData("TernaryOperator", 3)]
29-
public static void StructuralSearchShouldBe(string exampleName, int matchesCount)
30-
{
31-
var config = ConfigurationMock.GetConfigurationFromFiles(exampleName);
32-
var directory = Directory.GetCurrentDirectory();
33-
var inputFilePath = Path.Combine(directory, $"ExamplesInput/{exampleName}.cs");
34-
var resultFilePath = Path.Combine(directory, $"ExamplesOutput/{exampleName}.txt");
35-
var outputFilePath = Path.Combine(directory, $"{exampleName}.cs");
36-
37-
var parser = new StructuralSearchParser(config);
38-
39-
var inputFileInfo = new FileInfo(inputFilePath);
40-
var input = Input.File(inputFileInfo);
41-
IParsingContext context = new ParsingContext(input);
42-
var matches = parser.Parse(ref context);
43-
matches = parser.ApplyFindRule(ref context, matches);
44-
matches = parser.ApplyReplaceRule(ref context, matches);
45-
var replaceMatches = parser.GetReplaceMatches(ref context, matches);
46-
var outputFileInfo = new FileInfo(outputFilePath);
47-
var output = Output.File(outputFileInfo);
48-
output.Replace(input, replaceMatches);
49-
50-
Assert.Equal(matches.Count(), matchesCount);
51-
var resultStr = File.ReadAllText(resultFilePath);
52-
var outputStr = File.ReadAllText(outputFilePath);
53-
Assert.Equal(resultStr, outputStr);
54-
}
24+
// [Theory]
25+
// [InlineData("NullUnionOperator", 2)]
26+
// [InlineData("TernaryOperator", 3)]
27+
// public static void StructuralSearchShouldBe(string exampleName, int matchesCount)
28+
// {
29+
// var config = ConfigurationMock.GetConfigurationFromFiles(exampleName);
30+
// var directory = Directory.GetCurrentDirectory();
31+
// var inputFilePath = Path.Combine(directory, $"ExamplesInput/{exampleName}.cs");
32+
// var resultFilePath = Path.Combine(directory, $"ExamplesOutput/{exampleName}.txt");
33+
// var outputFilePath = Path.Combine(directory, $"{exampleName}.cs");
34+
//
35+
// var parser = new StructuralSearchParser(config);
36+
//
37+
// var inputFileInfo = new FileInfo(inputFilePath);
38+
// var input = Input.File(inputFileInfo);
39+
// IParsingContext context = new ParsingContext(input);
40+
// var matches = parser.Parse(input);
41+
// matches = parser.ApplyFindRule(ref context, matches);
42+
// matches = parser.ApplyReplaceRule(ref context, matches);
43+
// var replaceMatches = parser.GetReplaceMatches(ref context, matches);
44+
// var outputFileInfo = new FileInfo(outputFilePath);
45+
// var output = Output.File(outputFileInfo);
46+
// output.Replace(input, replaceMatches);
47+
//
48+
// Assert.Equal(matches.Count(), matchesCount);
49+
// var resultStr = File.ReadAllText(resultFilePath);
50+
// var outputStr = File.ReadAllText(outputFilePath);
51+
// Assert.Equal(resultStr, outputStr);
52+
// }
5553
}

src/SimpleStateMachine.StructuralSearch.Tests/StructuralSearchTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using SimpleStateMachine.StructuralSearch;
55
using SimpleStateMachine.StructuralSearch.Configurations;
66
using SimpleStateMachine.StructuralSearch.Extensions;
7+
using SimpleStateMachine.StructuralSearch.Input;
78
using Xunit;
89

910
namespace SimpleStateMachine.StructuralSearch.Tests;
@@ -33,7 +34,7 @@ public static void StructuralSearchShouldBeSuccess(string inputText, string temp
3334
// Template
3435
"void $methodName$($params$)",
3536
// Result placeholders
36-
new Dictionary<string, string>()
37+
new Dictionary<string, string>
3738
{
3839
{ "methodName", "MyMethodName" },
3940
{ "params", "int value1, double value2" }
@@ -46,7 +47,7 @@ public static void StructuralSearchShouldBeSuccess(string inputText, string temp
4647
[InlineData("ExamplesInput/Methods.cs")]
4748
public static void StructuralSearchShouldBeSuccess2(string filePath)
4849
{
49-
var configuration = new Configuration()
50+
var configuration = new Configuration
5051
{
5152
FindTemplate = "$Modificator$ $ReturnType$ $MethodName$($params$)",
5253
FindRules = new List<string>
@@ -58,8 +59,7 @@ public static void StructuralSearchShouldBeSuccess2(string filePath)
5859
};
5960

6061
var parser = new StructuralSearchParser(configuration);
61-
IParsingContext context = new ParsingContext(new FileInput(new FileInfo(filePath)));
62-
var results = parser.Parse(ref context).ToList();
62+
var results = parser.Parse(new FileInput(new FileInfo(filePath))).ToList();
6363
// parser.ApplyFindRule(results);
6464
}
6565
}

src/SimpleStateMachine.StructuralSearch/Constant.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
namespace SimpleStateMachine.StructuralSearch;
1+
using System.Collections.Generic;
22

3-
public static partial class Constant
3+
namespace SimpleStateMachine.StructuralSearch;
4+
5+
internal static partial class Constant
46
{
57
/// <summary>
68
/// Parenthesis empty string
@@ -140,7 +142,7 @@ public static partial class Constant
140142
/// <summary>
141143
/// Parenthesis chars: '(' and ')', '{ and '}', '{ and '}'
142144
/// </summary>
143-
public static readonly char[] AllParenthesisArray =
145+
public static readonly IReadOnlySet<char> AllParenthesisArray = new HashSet<char>
144146
{
145147
LeftParenthesis,
146148
RightParenthesis,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using SimpleStateMachine.StructuralSearch.Input;
5+
6+
namespace SimpleStateMachine.StructuralSearch;
7+
8+
public sealed class EmptyFindParser: IFindParser
9+
{
10+
public static readonly EmptyFindParser Value = new ();
11+
12+
public List<FindParserResult> Parse(IInput input)
13+
=> Array.Empty<FindParserResult>().ToList();
14+
}

0 commit comments

Comments
 (0)