Skip to content

Commit a1b62b6

Browse files
committed
Format code
1 parent d0edb3e commit a1b62b6

File tree

8 files changed

+64
-74
lines changed

8 files changed

+64
-74
lines changed

src/SimpleStateMachine.StructuralSearch.Tests/Attributes/FilesDataAttribute.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,16 @@
66

77
namespace SimpleStateMachine.StructuralSearch.Tests.Attributes;
88

9-
public class FilesDataAttribute : DataAttribute
9+
public class FilesDataAttribute(string folderPath) : DataAttribute
1010
{
11-
private readonly string _folderPath;
12-
13-
public FilesDataAttribute(string folderPath)
14-
{
15-
_folderPath = folderPath;
16-
}
17-
1811
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
1912
{
2013
ArgumentNullException.ThrowIfNull(testMethod);
2114

22-
if (!Directory.Exists(_folderPath))
23-
{
24-
throw new DirectoryNotFoundException($"Could not find folder: {_folderPath}");
25-
}
15+
if (!Directory.Exists(folderPath))
16+
throw new DirectoryNotFoundException($"Could not find folder: {folderPath}");
2617

27-
foreach (var file in Directory.GetFiles(_folderPath))
28-
{
18+
foreach (var file in Directory.GetFiles(folderPath))
2919
yield return [file];
30-
}
3120
}
3221
}

src/SimpleStateMachine.StructuralSearch.Tests/SimpleStateMachine.StructuralSearch.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ProjectReference Include="..\SimpleStateMachine.StructuralSearch\SimpleStateMachine.StructuralSearch.csproj"/>
1111
</ItemGroup>
1212

13-
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
13+
<ItemGroup>
1414
<Content Include="ExamplesOutput\*">
1515
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1616
</Content>

src/SimpleStateMachine.StructuralSearch/Configuration.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,32 @@ public class Configuration : IEquatable<Configuration>
1313

1414
public bool Equals(Configuration? other)
1515
{
16-
var findTemplateEquals = FindTemplate == other?.FindTemplate;
17-
var findRulesEquals = NullableSequenceEqual(FindRules, other?.FindRules);
18-
var replaceTemplateEquals = ReplaceTemplate == other?.ReplaceTemplate;
19-
var replaceRulesEquals = NullableSequenceEqual(ReplaceRules, other?.ReplaceRules);
20-
return findTemplateEquals && findRulesEquals && replaceTemplateEquals && replaceRulesEquals;
16+
if (other is null) return false;
17+
if (ReferenceEquals(this, other)) return true;
18+
return FindTemplate == other.FindTemplate
19+
&& NullableSequenceEqual(FindRules, other.FindRules)
20+
&& ReplaceTemplate == other.ReplaceTemplate
21+
&& NullableSequenceEqual(ReplaceRules, other.ReplaceRules);
2122
}
2223

23-
public override bool Equals(object? obj)
24-
=> obj?.GetType() == GetType() && Equals((Configuration)obj);
24+
public override bool Equals(object? obj)
25+
{
26+
if (obj is null) return false;
27+
if (ReferenceEquals(this, obj)) return true;
28+
if (obj.GetType() != GetType()) return false;
29+
return Equals((Configuration)obj);
30+
}
2531

26-
public override int GetHashCode()
27-
=> HashCode.Combine(FindTemplate, FindRules, ReplaceTemplate, ReplaceRules);
32+
public override int GetHashCode()
33+
{
34+
return HashCode.Combine(FindTemplate, FindRules, ReplaceTemplate, ReplaceRules);
35+
}
2836

2937
private static bool NullableSequenceEqual<TSource>(IEnumerable<TSource>? first, IEnumerable<TSource>? second)
3038
{
3139
if (first is null && second is null)
3240
return true;
33-
41+
3442
if (first is null || second is null)
3543
return false;
3644

src/SimpleStateMachine.StructuralSearch/ConfigurationFile.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54
using YamlDotNet.Serialization;
65
using YamlDotNet.Serialization.NamingConventions;
76

@@ -34,11 +33,22 @@ private ConfigurationFile() : this([])
3433
public List<Configuration> Configurations { get; init; } = configurations;
3534

3635
public bool Equals(ConfigurationFile? other)
37-
=> other?.Configurations != null && Configurations.SequenceEqual(other.Configurations);
36+
{
37+
if (other is null) return false;
38+
if (ReferenceEquals(this, other)) return true;
39+
return Configurations.Equals(other.Configurations);
40+
}
3841

3942
public override bool Equals(object? obj)
40-
=> obj?.GetType() == GetType() && Equals((ConfigurationFile)obj);
43+
{
44+
if (obj is null) return false;
45+
if (ReferenceEquals(this, obj)) return true;
46+
if (obj.GetType() != GetType()) return false;
47+
return Equals((ConfigurationFile)obj);
48+
}
4149

4250
public override int GetHashCode()
43-
=> Configurations.GetHashCode();
51+
{
52+
return Configurations.GetHashCode();
53+
}
4454
}

src/SimpleStateMachine.StructuralSearch/Extensions/StringParserExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ internal static class StringParserExtensions
99
{
1010
public static Parser<char, TResult> BetweenAnyParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
1111
{
12-
var parentheses= parser.BetweenParentheses(mapFunc);
13-
var curlyParentheses= parser.BetweenCurlyParentheses(mapFunc);
14-
var squareParentheses= parser.BetweenSquareParentheses(mapFunc);
12+
var parentheses = parser.BetweenParentheses(mapFunc);
13+
var curlyParentheses = parser.BetweenCurlyParentheses(mapFunc);
14+
var squareParentheses = parser.BetweenSquareParentheses(mapFunc);
1515
return Parser.OneOf(parentheses, curlyParentheses, squareParentheses);
1616
}
1717

1818
public static Parser<char, TResult> BetweenParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
1919
=> Parser.Map(mapFunc, CommonParser.LeftParenthesis, parser, CommonParser.RightParenthesis);
2020

21-
public static Parser<char, TResult> BetweenCurlyParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
21+
private static Parser<char, TResult> BetweenCurlyParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
2222
=> Parser.Map(mapFunc, CommonParser.LeftCurlyParenthesis, parser, CommonParser.RightCurlyParenthesis);
2323

24-
public static Parser<char, TResult> BetweenSquareParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
24+
private static Parser<char, TResult> BetweenSquareParentheses<T, TResult>(this Parser<char, T> parser, Func<char, T, char, TResult> mapFunc)
2525
=> Parser.Map(mapFunc, CommonParser.LeftSquareParenthesis, parser, CommonParser.RightSquareParenthesis);
2626

2727
public static T ParseToEnd<T>(this Parser<char, T> parser, string str)

src/SimpleStateMachine.StructuralSearch/Input/FileInput.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@
33

44
namespace SimpleStateMachine.StructuralSearch.Input;
55

6-
public class FileInput : IInput
6+
public class FileInput(FileInfo fileInfo) : IInput
77
{
8-
private readonly FileInfo _fileInfo;
9-
10-
public FileInput(FileInfo fileInfo)
11-
{
12-
_fileInfo = fileInfo;
13-
}
14-
158
public TextReader ReadData()
16-
=> _fileInfo.OpenText();
9+
=> fileInfo.OpenText();
1710

1811
public string GetProperty(string propertyName)
1912
{
2013
var lower = propertyName.ToLower();
2114

2215
return lower switch
2316
{
24-
"path" => Path.GetFullPath(_fileInfo.FullName),
25-
"extension" => _fileInfo.Extension,
26-
"name" => _fileInfo.Name,
27-
"length" => _fileInfo.Length.ToString(),
17+
"path" => Path.GetFullPath(fileInfo.FullName),
18+
"extension" => fileInfo.Extension,
19+
"name" => fileInfo.Name,
20+
"length" => fileInfo.Length.ToString(),
2821
_ => throw new ArgumentOutOfRangeException(propertyName)
2922
};
3023
}

src/SimpleStateMachine.StructuralSearch/Input/StringInput.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33

44
namespace SimpleStateMachine.StructuralSearch.Input;
55

6-
public class StringInput : IInput
6+
public class StringInput(string str) : IInput
77
{
8-
private readonly string _str;
9-
10-
public StringInput(string str)
8+
public TextReader ReadData()
119
{
12-
_str = str;
10+
return new StringReader(str);
1311
}
1412

15-
public TextReader ReadData()
16-
=> new StringReader(_str);
17-
1813
public string GetProperty(string propertyName)
1914
{
2015
var lower = propertyName.ToLower();
2116

2217
return lower switch
2318
{
24-
"length" => _str.Length.ToString(),
19+
"length" => str.Length.ToString(),
2520
_ => throw new ArgumentOutOfRangeException(propertyName)
2621
};
2722
}

src/SimpleStateMachine.StructuralSearch/Parsing/PlaceholderParser.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,29 @@ internal class PlaceholderParser(string name) : ParserWithLookahead<char, string
2121

2222
private IParsingContext Context => _context ?? throw new ArgumentNullException(nameof(_context));
2323

24-
protected override Parser<char, string> BuildParser(Func<Parser<char, string>?> next, Func<Parser<char, string>?> nextNext)
24+
public void SetContext(ref IParsingContext context)
25+
{
26+
_context = context;
27+
}
28+
29+
protected override Parser<char, string> BuildParser(Func<Parser<char, string>?> next,
30+
Func<Parser<char, string>?> nextNext)
2531
{
2632
var nextParser = next();
2733
var nextNextParser = nextNext();
2834

2935
Parser<char, Unit> lookahead;
3036
if (nextNextParser is not null && nextParser is not null)
31-
{
3237
lookahead = nextParser.Then(nextNextParser, (s1, s2) =>
3338
{
3439
OnLookahead = () => new List<LookaheadResult<char, string>>
3540
{
3641
new(nextParser, s1, s1.Length),
37-
new(nextNextParser, s2, s2.Length),
42+
new(nextNextParser, s2, s2.Length)
3843
};
3944
return Unit.Value;
4045
}).Try().Lookahead();
41-
}
4246
else if (nextParser is not null)
43-
{
4447
lookahead = nextParser.Select(s =>
4548
{
4649
OnLookahead = () => new List<LookaheadResult<char, string>>
@@ -49,11 +52,8 @@ protected override Parser<char, string> BuildParser(Func<Parser<char, string>?>
4952
};
5053
return Unit.Value;
5154
}).Try().Lookahead();
52-
}
5355
else
54-
{
55-
lookahead = Parser<char>.End.Select(x => Unit.Value);
56-
}
56+
lookahead = Parser<char>.End.Select(_ => Unit.Value);
5757

5858
return CreateParser(lookahead);
5959
}
@@ -80,7 +80,7 @@ internal static Parser<char, string> CreateParser(Parser<char, Unit> terminator)
8080
var parser = prdsAndTokens.Or(anyString);
8181
return parser;
8282
}
83-
83+
8484
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected,
8585
out string result)
8686
{
@@ -99,8 +99,8 @@ public override bool TryParse(ref ParseState<char> state, ref PooledList<Expecte
9999
{
100100
var placeholderObj = new Placeholder.Placeholder
101101
(
102-
name: name,
103-
match: match
102+
name,
103+
match
104104
);
105105

106106
Context[name] = placeholderObj;
@@ -116,9 +116,4 @@ public override bool TryParse(ref ParseState<char> state, ref PooledList<Expecte
116116

117117
return res;
118118
}
119-
120-
public void SetContext(ref IParsingContext context)
121-
{
122-
_context = context;
123-
}
124119
}

0 commit comments

Comments
 (0)