diff --git a/SimpleStateMachine.StructuralSearch.Action/Program.cs b/SimpleStateMachine.StructuralSearch.Action/Program.cs index 11b3660..60f2ff4 100644 --- a/SimpleStateMachine.StructuralSearch.Action/Program.cs +++ b/SimpleStateMachine.StructuralSearch.Action/Program.cs @@ -17,7 +17,7 @@ static TService Get(IHost host) where TService : notnull => host.Services.GetRequiredService(); -static async Task StartAnalysisAsync(ActionInputs inputs, IHost host) +static Task StartAnalysisAsync(ActionInputs inputs, IHost host) { // using ProjectWorkspace workspace = Get(host); using CancellationTokenSource tokenSource = new(); @@ -85,6 +85,7 @@ static async Task StartAnalysisAsync(ActionInputs inputs, IHost host) // Console.WriteLine($"::set-output name=summary-details::{summary}"); Environment.Exit(0); + return Task.CompletedTask; } var parser = Default.ParseArguments(() => new ActionInputs(), args); diff --git a/src/SimpleStateMachine.StructuralSearch.Tests/Mock/Configuration.cs b/src/SimpleStateMachine.StructuralSearch.Tests/Mock/Configuration.cs index ab529ff..c365561 100644 --- a/src/SimpleStateMachine.StructuralSearch.Tests/Mock/Configuration.cs +++ b/src/SimpleStateMachine.StructuralSearch.Tests/Mock/Configuration.cs @@ -22,6 +22,7 @@ public static Configuration GetConfigurationFromFiles(string name) ReplaceTemplate = replaceTemplate, ReplaceRules = replaceRules }; + return config; string? FileOrNull(string folder, string name) diff --git a/src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs b/src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs index c294ed7..dd5151f 100644 --- a/src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs +++ b/src/SimpleStateMachine.StructuralSearch.Tests/ReplaceTemplateTests.cs @@ -15,7 +15,7 @@ public void ReplaceTemplateParsingShouldHaveStepCount(string templatePath, int s { var replaceTemplate = File.ReadAllText(templatePath); var replaceBuilder = StructuralSearch.ParseReplaceTemplate(replaceTemplate); - var result = replaceBuilder.Build(new EmptyParsingContext()); + var result = replaceBuilder.Build(ParsingContext.Empty); Assert.NotNull(replaceTemplate); Assert.Equal(replaceBuilder.Steps.Count(), stepsCount); diff --git a/src/SimpleStateMachine.StructuralSearch/Configurations/Configuration.cs b/src/SimpleStateMachine.StructuralSearch/Configurations/Configuration.cs index 244bd77..192d9bf 100644 --- a/src/SimpleStateMachine.StructuralSearch/Configurations/Configuration.cs +++ b/src/SimpleStateMachine.StructuralSearch/Configurations/Configuration.cs @@ -7,11 +7,8 @@ namespace SimpleStateMachine.StructuralSearch.Configurations public class Configuration : IEquatable { public string FindTemplate { get; init; } - public List? FindRules { get; init; } - public string ReplaceTemplate { get; init; } - public List? ReplaceRules { get; init; } public bool Equals(Configuration? other) @@ -25,8 +22,7 @@ public bool Equals(Configuration? other) public override bool Equals(object? obj) { - if (obj.GetType() != this.GetType()) return false; - return Equals((Configuration)obj); + return obj?.GetType() == GetType() && Equals((Configuration)obj); } public override int GetHashCode() diff --git a/src/SimpleStateMachine.StructuralSearch/Configurations/ConfigurationFile.cs b/src/SimpleStateMachine.StructuralSearch/Configurations/ConfigurationFile.cs index d1a5d76..b64512c 100644 --- a/src/SimpleStateMachine.StructuralSearch/Configurations/ConfigurationFile.cs +++ b/src/SimpleStateMachine.StructuralSearch/Configurations/ConfigurationFile.cs @@ -6,7 +6,7 @@ namespace SimpleStateMachine.StructuralSearch.Configurations { public class ConfigurationFile: IEquatable { - public List Configurations { get; set; } + public List Configurations { get; init; } public bool Equals(ConfigurationFile? other) { @@ -15,8 +15,7 @@ public bool Equals(ConfigurationFile? other) public override bool Equals(object? obj) { - if (obj.GetType() != this.GetType()) return false; - return Equals((ConfigurationFile)obj); + return obj?.GetType() == GetType() && Equals((ConfigurationFile)obj); } public override int GetHashCode() diff --git a/src/SimpleStateMachine.StructuralSearch/Constant.cs b/src/SimpleStateMachine.StructuralSearch/Constant.cs index 4b446e2..ad7334f 100644 --- a/src/SimpleStateMachine.StructuralSearch/Constant.cs +++ b/src/SimpleStateMachine.StructuralSearch/Constant.cs @@ -95,7 +95,7 @@ public static partial class Constant /// /// Char: '=' /// - public const char Equals = '='; + private const char Equals = '='; /// /// Char: '>' diff --git a/src/SimpleStateMachine.StructuralSearch/EmptyParsingContext.cs b/src/SimpleStateMachine.StructuralSearch/EmptyParsingContext.cs index c80ddd0..99fd037 100644 --- a/src/SimpleStateMachine.StructuralSearch/EmptyParsingContext.cs +++ b/src/SimpleStateMachine.StructuralSearch/EmptyParsingContext.cs @@ -5,6 +5,11 @@ namespace SimpleStateMachine.StructuralSearch public class EmptyParsingContext : IParsingContext { public IInput Input { get; } + + public EmptyParsingContext(IInput input) + { + Input = input; + } public bool TryGetPlaceholder(string name, out IPlaceholder value) { diff --git a/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableCharExtensions.cs b/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableCharExtensions.cs index 82c85d3..cd1d113 100644 --- a/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableCharExtensions.cs +++ b/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableCharExtensions.cs @@ -6,19 +6,19 @@ namespace SimpleStateMachine.StructuralSearch.Extensions { public static class EnumerableCharExtensions { - public static Parser AsString(this Parser> parser) + public static Parser AsString(this Parser> parser) { return parser.Select(x => new string(x.ToArray())); } - public static Parser> MergerMany( - this Parser>> parser) + public static Parser> MergerMany( + this Parser>> parser) { return parser.Select(x => x.SelectMany(y => y)); } - public static Parser> MergerMany( - this Parser>> parser) + public static Parser> MergerMany( + this Parser>> parser) { return parser.Select(x => x.SelectMany(y => y)); } diff --git a/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableStringExtensions.cs b/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableStringExtensions.cs index 8f6cb72..912f1a3 100644 --- a/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableStringExtensions.cs +++ b/src/SimpleStateMachine.StructuralSearch/Extensions/EnumerableStringExtensions.cs @@ -4,12 +4,12 @@ namespace SimpleStateMachine.StructuralSearch.Extensions { public static class EnumerableStringExtensions { - public static string JoinToString(this IEnumerable enumerable, string separator = null) + public static string JoinToString(this IEnumerable enumerable, string? separator = null) { return string.Join(separator, enumerable); } - public static string JoinToString(this List enumerable, string separator = null) + public static string JoinToString(this List enumerable, string? separator = null) { return string.Join(separator, enumerable); } diff --git a/src/SimpleStateMachine.StructuralSearch/Extensions/IEnumerableSourceMatchExtensions.cs b/src/SimpleStateMachine.StructuralSearch/Extensions/IEnumerableSourceMatchExtensions.cs index d330153..6b0ce08 100644 --- a/src/SimpleStateMachine.StructuralSearch/Extensions/IEnumerableSourceMatchExtensions.cs +++ b/src/SimpleStateMachine.StructuralSearch/Extensions/IEnumerableSourceMatchExtensions.cs @@ -7,9 +7,10 @@ public static class IEnumerableSourceMatchExtensions { public static SourceMatch Concatenate(this IEnumerable matches) { - int start = matches.First().Start; - int end = matches.Last().End; - var value = string.Join(string.Empty, matches.Select(x => x.Value)); + var sourceMatches = matches as SourceMatch[] ?? matches.ToArray(); + int start = sourceMatches.First().Start; + int end = sourceMatches.Last().End; + var value = string.Join(string.Empty, sourceMatches.Select(x => x.Value)); return new SourceMatch(value, start, end); } } diff --git a/src/SimpleStateMachine.StructuralSearch/Extensions/StringParserExtensions.cs b/src/SimpleStateMachine.StructuralSearch/Extensions/StringParserExtensions.cs index e0c4674..5446659 100644 --- a/src/SimpleStateMachine.StructuralSearch/Extensions/StringParserExtensions.cs +++ b/src/SimpleStateMachine.StructuralSearch/Extensions/StringParserExtensions.cs @@ -40,13 +40,13 @@ public static Parser> ToMany(this Parser new List() { x }).ToIEnumerable(); } - public static Parser JoinToString(this Parser> parser, string separator = null) + public static Parser JoinToString(this Parser> parser, string? separator = null) { separator ??= string.Empty; return parser.Select(x => string.Join(separator, x)); } - public static Parser JoinToString(this Parser> parser, string separator = null) + public static Parser JoinToString(this Parser> parser, string? separator = null) { separator ??= string.Empty; return parser.Select(x => string.Join(separator, x)); diff --git a/src/SimpleStateMachine.StructuralSearch/Helper/EnumHelper.cs b/src/SimpleStateMachine.StructuralSearch/Helper/EnumHelper.cs index a0d78df..303987f 100644 --- a/src/SimpleStateMachine.StructuralSearch/Helper/EnumHelper.cs +++ b/src/SimpleStateMachine.StructuralSearch/Helper/EnumHelper.cs @@ -72,7 +72,5 @@ public static bool TryGetValue(string value, bool ignoreCase, out TEnum r { return Enum.TryParse(value, ignoreCase, out result); } - - } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Helper/LogicalHelper.cs b/src/SimpleStateMachine.StructuralSearch/Helper/LogicalHelper.cs index 2cd92d5..f1c70ce 100644 --- a/src/SimpleStateMachine.StructuralSearch/Helper/LogicalHelper.cs +++ b/src/SimpleStateMachine.StructuralSearch/Helper/LogicalHelper.cs @@ -3,7 +3,7 @@ namespace SimpleStateMachine.StructuralSearch.Helper { - public static class LogicalHelper + public static class LogicalHelper { public static bool Calculate(BinaryRuleType type, bool left, bool right) { diff --git a/src/SimpleStateMachine.StructuralSearch/Helper/StreamExtensions.cs b/src/SimpleStateMachine.StructuralSearch/Helper/StreamExtensions.cs index 41bdc22..66afdb9 100644 --- a/src/SimpleStateMachine.StructuralSearch/Helper/StreamExtensions.cs +++ b/src/SimpleStateMachine.StructuralSearch/Helper/StreamExtensions.cs @@ -11,6 +11,7 @@ public static class StreamExtensions /// /// The source stream. /// The destination stream. + /// /// The number of bytes to copy. /// The size of the buffer to use. /// The default is 4096. @@ -34,6 +35,7 @@ public static void CopyPartTo(this Stream source, Stream destination, int offset /// /// The source stream. /// The destination stream. + /// /// The number of bytes to copy. public static void CopyPartTo(this Stream source, Stream destination, int offset, int count) { diff --git a/src/SimpleStateMachine.StructuralSearch/Input/Input.cs b/src/SimpleStateMachine.StructuralSearch/Input/Input.cs index bd5e47f..0775829 100644 --- a/src/SimpleStateMachine.StructuralSearch/Input/Input.cs +++ b/src/SimpleStateMachine.StructuralSearch/Input/Input.cs @@ -5,9 +5,7 @@ namespace SimpleStateMachine.StructuralSearch public static class Input { public static readonly IInput Empty = new EmptyInput(); - public static IInput String(string input) => new StringInput(input); - public static IInput File(FileInfo fileInfo) => new FileInput(fileInfo); } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Input/StringInput.cs b/src/SimpleStateMachine.StructuralSearch/Input/StringInput.cs index 7f30966..7273124 100644 --- a/src/SimpleStateMachine.StructuralSearch/Input/StringInput.cs +++ b/src/SimpleStateMachine.StructuralSearch/Input/StringInput.cs @@ -4,16 +4,16 @@ namespace SimpleStateMachine.StructuralSearch { public class StringInput : IInput { + private readonly string _input; + public StringInput(string input) { - Input = input; + _input = input; } - - public readonly string Input; - + public Result ParseBy(Parser parser) { - return parser.Parse(Input); + return parser.Parse(_input); } public void Replace(Match match, string value) @@ -25,6 +25,6 @@ public void Replace(Match match, string value) public string Path => string.Empty; public string Name => string.Empty; public string Data => string.Empty; - public long Lenght => Input.Length; + public long Lenght => _input.Length; } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Output/FileOutput.cs b/src/SimpleStateMachine.StructuralSearch/Output/FileOutput.cs index 8d119ad..a566fb2 100644 --- a/src/SimpleStateMachine.StructuralSearch/Output/FileOutput.cs +++ b/src/SimpleStateMachine.StructuralSearch/Output/FileOutput.cs @@ -6,11 +6,11 @@ namespace SimpleStateMachine.StructuralSearch; public class FileOutput : IOutput { - public readonly FileInfo FileInfo; + private readonly FileInfo _fileInfo; public FileOutput(FileInfo fileInfo) { - FileInfo = fileInfo; + _fileInfo = fileInfo; } public void Replace(IInput input, IEnumerable replaceMatches) @@ -22,7 +22,7 @@ public void Replace(IInput input, IEnumerable replaceMatches) File.WriteAllText(Path, text); } - public string Extension => FileInfo.Extension; - public string Path => System.IO.Path.GetFullPath(FileInfo.FullName); - public string Name => System.IO.Path.GetFileNameWithoutExtension(FileInfo.Name); + public string Extension => _fileInfo.Extension; + public string Path => System.IO.Path.GetFullPath(_fileInfo.FullName); + public string Name => System.IO.Path.GetFileNameWithoutExtension(_fileInfo.Name); } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Parsers/DebugParser.cs b/src/SimpleStateMachine.StructuralSearch/Parsers/DebugParser.cs index 3c2cfe7..7c4ff59 100644 --- a/src/SimpleStateMachine.StructuralSearch/Parsers/DebugParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/Parsers/DebugParser.cs @@ -4,7 +4,7 @@ namespace SimpleStateMachine.StructuralSearch { public class DebugParser: Parser { - private Parser _parser; + private readonly Parser _parser; public DebugParser(Parser parser) { _parser = parser; diff --git a/src/SimpleStateMachine.StructuralSearch/Parsers/EmptyStringParser.cs b/src/SimpleStateMachine.StructuralSearch/Parsers/EmptyStringParser.cs index 590d324..3b199e5 100644 --- a/src/SimpleStateMachine.StructuralSearch/Parsers/EmptyStringParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/Parsers/EmptyStringParser.cs @@ -4,18 +4,18 @@ namespace SimpleStateMachine.StructuralSearch { public class EmptyStringParser : Parser { - public bool Value { get; } + private readonly bool _value; public EmptyStringParser(bool value) { - Value = value; + _value = value; } public override bool TryParse(ref ParseState state, ref PooledList> expecteds, out string result) { result = string.Empty; - return Value; + return _value; } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Parsers/EnumParser.cs b/src/SimpleStateMachine.StructuralSearch/Parsers/EnumParser.cs index 3c74a2f..ca99b86 100644 --- a/src/SimpleStateMachine.StructuralSearch/Parsers/EnumParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/Parsers/EnumParser.cs @@ -9,7 +9,7 @@ namespace SimpleStateMachine.StructuralSearch public class EnumParser : Parser where TEnum : struct, Enum { - private Parser _parser; + private readonly Parser _parser; public EnumParser(bool ignoreCase, params TEnum [] excluded) { diff --git a/src/SimpleStateMachine.StructuralSearch/Parsers/Parsers.cs b/src/SimpleStateMachine.StructuralSearch/Parsers/Parsers.cs index 3e26160..7c89093 100644 --- a/src/SimpleStateMachine.StructuralSearch/Parsers/Parsers.cs +++ b/src/SimpleStateMachine.StructuralSearch/Parsers/Parsers.cs @@ -19,13 +19,7 @@ public static Parser After(TEnum value, bool ignoreCase = fa { return Parsers.String(value.ToString(), ignoreCase).AsEnum(ignoreCase); } - - // public static Parser EnumValue(TEnum value, bool ignoreCase = false) - // where TEnum : struct, Enum - // { - // return Parsers.String(value.Name(), ignoreCase).AsEnum(); - // } - + public static Parser> MapToMany(Parser parser1, Parser parser2, Parser parser3) { @@ -88,12 +82,6 @@ public static Parser> BetweenOneOfChars(Func BetweenOneOf(Func> leftRight, - // Parser expr, params (char, char)[] values) - // { - // return OneOf(values.Select(x => expr.Between(leftRight(x.Item1), leftRight(x.Item2)))); - // } - public static Parser> BetweenOneOfChars(Func> leftRight, Parser expr, params (char, char)[] values) { @@ -141,29 +129,5 @@ public static Parser> Match(Parser parser) parser, Parser.CurrentPos, Parser.CurrentOffset); } - - - // public static string Match(Parser parser, ref ParseState state, - // ref PooledList> expected, out string result) - // { - // Parser.CurrentPos.Then(Parser.CurrentOffset, (pos, i) => (oldPos, oldOffset)) - // .Then() - // .TryParse(ref state, ref expected, out var oldPos); - // .TryParse(ref state, ref expected, out var oldOffset); - // var res = parser.TryParse(ref state, ref expected, out result); - // - // if (res) - // { - // Parser.CurrentPos.TryParse(ref state, ref expected, out var newPos); - // Parser.CurrentOffset.TryParse(ref state, ref expected, out var newOffset); - // - // var line = new LinePosition(oldPos.Line, newPos.Line); - // var column = new ColumnPosition(oldPos.Col, newPos.Col); - // var offset = new OffsetPosition(oldOffset, newOffset); - // - // } - // - // return null; - // } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Parsers/PlaceholderParser.cs b/src/SimpleStateMachine.StructuralSearch/Parsers/PlaceholderParser.cs index 28087a1..b128523 100644 --- a/src/SimpleStateMachine.StructuralSearch/Parsers/PlaceholderParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/Parsers/PlaceholderParser.cs @@ -21,9 +21,7 @@ public override Parser BuildParser(Func?> nex { var _next = next(); var _nextNext = nextNext(); - // ?? Parser.OneOf(Parser.End.ThenReturn(string.Empty), Parser.Any.ThenReturn(string.Empty)); - // Parser.End.ThenReturn(string.Empty) - + Parser lookahead; if (_nextNext is not null) { @@ -98,35 +96,7 @@ public override bool TryParse(ref ParseState state, ref PooledList GetParser() - // { - // - // } - // public override Parser BuildParser(Func> next, Func> nextNext) - // { - // var _next = next(); - // var _nextNext = nextNext(); - // var lookahead = Parser.Lookahead(_next.Then(_nextNext).Try()); - // var anyString = Parser.Any.AtLeastOnceAsStringUntil(lookahead) - // .Try(); - // - // var simpleString = CommonTemplateParser.StringWithoutParenthesisedAndWhiteSpaces; - // var token = Parser.OneOf(simpleString, CommonParser.WhiteSpaces) - // .AtLeastOnce(); - // Parser> term = null; - // - // var parenthesised = Parsers.BetweenOneOfChars(Parsers.Stringc, - // Parser.Rec(() => term), - // Constant.AllParenthesised); - // - // term = Parser.OneOf(token, parenthesised).AtLeastOnce().MergerMany(); - // - // // var parser = Parser.OneOf(term.JoinToString(), anyString).AsMatch(); - // var parser = term.JoinToString().AsMatch(); - // return parser; - // } + public void SetContext(ref IParsingContext context) { _context = context; diff --git a/src/SimpleStateMachine.StructuralSearch/ParsingContext.cs b/src/SimpleStateMachine.StructuralSearch/ParsingContext.cs index e90bc0e..66348d0 100644 --- a/src/SimpleStateMachine.StructuralSearch/ParsingContext.cs +++ b/src/SimpleStateMachine.StructuralSearch/ParsingContext.cs @@ -5,8 +5,8 @@ namespace SimpleStateMachine.StructuralSearch { public class ParsingContext : IParsingContext { - public static IParsingContext Empty = new EmptyParsingContext(); - + public static IParsingContext Empty = new EmptyParsingContext(SimpleStateMachine.StructuralSearch.Input.Empty); + public ParsingContext(IInput input) { Input = input; diff --git a/src/SimpleStateMachine.StructuralSearch/Placeholder/LinePosition.cs b/src/SimpleStateMachine.StructuralSearch/Placeholder/LinePosition.cs index 1ed42d1..91c7f73 100644 --- a/src/SimpleStateMachine.StructuralSearch/Placeholder/LinePosition.cs +++ b/src/SimpleStateMachine.StructuralSearch/Placeholder/LinePosition.cs @@ -4,7 +4,7 @@ public readonly record struct LinePosition(int Start, int End) { public readonly int Start = Start; public readonly int End = End; - + public static readonly LinePosition Empty = new(0, 0); } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinaryRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinaryRule.cs index be73e89..10eff58 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinaryRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinaryRule.cs @@ -4,36 +4,34 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class BinaryRule : IRule { - public BinaryRuleType Type { get; } - - public IRule Left { get; } - - public IRule Right { get; } + private readonly BinaryRuleType _type; + private readonly IRule _left; + private readonly IRule _right; public BinaryRule(BinaryRuleType type, IRule left, IRule right) { - Type = type; - Left = left; - Right = right; + _type = type; + _left = left; + _right = right; } public bool Execute() { - var left = Left.Execute(); - var right = Right.Execute(); + var left = _left.Execute(); + var right = _right.Execute(); - return LogicalHelper.Calculate(Type, left, right); + return LogicalHelper.Calculate(_type, left, right); } public override string ToString() { - return $"{Left}{Constant.Space}{Type}{Constant.Space}{Right}"; + return $"{_left}{Constant.Space}{_type}{Constant.Space}{_right}"; } public void SetContext(ref IParsingContext context) { - Left.SetContext(ref context); - Right.SetContext(ref context); + _left.SetContext(ref context); + _right.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinarySubRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinarySubRule.cs index 4697df0..a503fda 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinarySubRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/BinarySubRule.cs @@ -5,25 +5,23 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class BinarySubRule : IRule { - public SubRuleType Type { get; } - - public IRuleParameter Left { get; } - - public IRuleParameter Right { get; } + private readonly SubRuleType _type; + private readonly IRuleParameter _left; + private readonly IRuleParameter _right; public BinarySubRule(SubRuleType type, IRuleParameter left, IRuleParameter right) { - Type = type; - Left = left; - Right = right; + _type = type; + _left = left; + _right = right; } public bool Execute() { - var left = Left.GetValue(); - var right = Right.GetValue(); + var left = _left.GetValue(); + var right = _right.GetValue(); - return Type switch + return _type switch { SubRuleType.Equals => left.Equals(right), SubRuleType.Contains => left.Contains(right), @@ -36,13 +34,13 @@ public bool Execute() public override string ToString() { - return $"{Left}{Constant.Space}{Type}{Constant.Space}{Right}"; + return $"{_left}{Constant.Space}{_type}{Constant.Space}{_right}"; } public void SetContext(ref IParsingContext context) { - Left.SetContext(ref context); - Right.SetContext(ref context); + _left.SetContext(ref context); + _right.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/EmptySubRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/EmptySubRule.cs index d18eafe..ad68450 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/EmptySubRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/EmptySubRule.cs @@ -14,6 +14,5 @@ public override string ToString() public void SetContext(ref IParsingContext context) { - } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/InSubRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/InSubRule.cs index ce8b2ae..a539f67 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/InSubRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/InSubRule.cs @@ -5,24 +5,24 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class InSubRule : IRule { - public IRuleParameter Parameter { get; } - - public IEnumerable Arguments { get; } + private readonly IRuleParameter _parameter; + + private readonly IEnumerable _arguments; public InSubRule(IRuleParameter parameter, IEnumerable arguments) { - Parameter = parameter; + _parameter = parameter; - Arguments = arguments; + _arguments = arguments; } public bool Execute() { - var value = Parameter.GetValue(); - var result = Arguments.Any(parameter => + var value = _parameter.GetValue(); + var result = _arguments.Any(parameter => { - var value_ = parameter.GetValue(); - var equal = Equals(value, value_); + var valueForResult = parameter.GetValue(); + var equal = Equals(value, valueForResult); return equal; }); return result; @@ -30,14 +30,14 @@ public bool Execute() public override string ToString() { - return $"{Parameter}{Constant.Space}{SubRuleType.In}{Constant.Space}{string.Join(Constant.Comma, Arguments.Select(x=>x.ToString()))}"; + return $"{_parameter}{Constant.Space}{SubRuleType.In}{Constant.Space}{string.Join(Constant.Comma, _arguments.Select(x=>x.ToString()))}"; } public void SetContext(ref IParsingContext context) { - Parameter.SetContext(ref context); + _parameter.SetContext(ref context); - foreach (var argument in Arguments) + foreach (var argument in _arguments) { argument.SetContext(ref context); } diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/IsSubRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/IsSubRule.cs index 636450f..0a988f2 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/IsSubRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/IsSubRule.cs @@ -5,21 +5,20 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class IsSubRule : IRule { - public PlaceholderType Argument { get; } - - public IRuleParameter Parameter { get; } + private readonly PlaceholderType _argument; + private readonly IRuleParameter _parameter; public IsSubRule(IRuleParameter parameter, PlaceholderType argument) { - Parameter = parameter; - Argument = argument; + _parameter = parameter; + _argument = argument; } public bool Execute() { - var value = Parameter.GetValue(); + var value = _parameter.GetValue(); - return Argument switch + return _argument switch { PlaceholderType.Var => CommonParser.Identifier.TryParse(value, out _), PlaceholderType.Int => int.TryParse(value, out _), @@ -32,12 +31,12 @@ public bool Execute() public override string ToString() { - return $"{Parameter}{Constant.Space}{SubRuleType.Is}{Constant.Space}{Argument}"; + return $"{_parameter}{Constant.Space}{SubRuleType.Is}{Constant.Space}{_argument}"; } public void SetContext(ref IParsingContext context) { - Parameter.SetContext(ref context); + _parameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/UnaryRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/UnaryRule.cs index 7d1ca29..2b3b467 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/UnaryRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/FindRule/UnaryRule.cs @@ -4,21 +4,20 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class UnaryRule : IRule { - public UnaryRuleType Type { get; } - - public IRule Parameter { get; } + private readonly UnaryRuleType _type; + private readonly IRule _parameter; public UnaryRule(UnaryRuleType type, IRule parameter) { - Type = type; - Parameter = parameter; + _type = type; + _parameter = parameter; } public bool Execute() { - var result = Parameter.Execute(); + var result = _parameter.Execute(); - return Type switch + return _type switch { UnaryRuleType.Not => !result, _ => throw new ArgumentOutOfRangeException() @@ -27,12 +26,12 @@ public bool Execute() public override string ToString() { - return $"{Type}{Constant.Space}{Parameter}"; + return $"{_type}{Constant.Space}{_parameter}"; } public void SetContext(ref IParsingContext context) { - Parameter.SetContext(ref context); + _parameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/ParenthesisedParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/ParenthesisedParameter.cs index f8915a4..554f0ba 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/ParenthesisedParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/ParenthesisedParameter.cs @@ -6,29 +6,29 @@ namespace SimpleStateMachine.StructuralSearch.Rules.Parameters; public class ParenthesisedParameter : IRuleParameter { - public readonly IEnumerable Parameters; - public readonly ParenthesisType ParenthesisType; - public readonly string Template; + private readonly IEnumerable _parameters; + private readonly ParenthesisType _parenthesisType; + private readonly string _template; public ParenthesisedParameter(ParenthesisType parenthesisType, IEnumerable parameters) { - ParenthesisType = parenthesisType; - Parameters = parameters; - Template = GetTemplate(parenthesisType); + _parenthesisType = parenthesisType; + _parameters = parameters; + _template = GetTemplate(parenthesisType); } public string GetValue() { - return string.Format(Template, string.Join(string.Empty, Parameters.Select(x => x.GetValue()))); + return string.Format(_template, string.Join(string.Empty, _parameters.Select(x => x.GetValue()))); } public override string ToString() { - return string.Format(Template, string.Join(string.Empty, Parameters.Select(x=> x.ToString()))); + return string.Format(_template, string.Join(string.Empty, _parameters.Select(x=> x.ToString()))); } public void SetContext(ref IParsingContext context) { - foreach (var parameter in Parameters) + foreach (var parameter in _parameters) { parameter.SetContext(ref context); } diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderColumnParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderColumnParameter.cs index b88e6f7..e872d2b 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderColumnParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderColumnParameter.cs @@ -4,20 +4,20 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class PlaceholderColumnParameter : IRuleParameter { - public PlaceholderParameter PlaceholderParameter { get; } - public ColumnProperty Property { get; } + private readonly PlaceholderParameter _placeholderParameter; + private readonly ColumnProperty _property; public PlaceholderColumnParameter(PlaceholderParameter parameter, ColumnProperty property) { - PlaceholderParameter = parameter; - Property = property; + _placeholderParameter = parameter; + _property = property; } public string GetValue() { - var column = PlaceholderParameter.GetPlaceholder().Column; + var column = _placeholderParameter.GetPlaceholder().Column; - var value = Property switch + var value = _property switch { ColumnProperty.Start => column.Start, ColumnProperty.End => column.End, @@ -29,12 +29,12 @@ public string GetValue() public override string ToString() { - return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.Column}{Constant.Dote}{Property}"; + return $"{_placeholderParameter}{Constant.Dote}{PlaceholderProperty.Column}{Constant.Dote}{_property}"; } public void SetContext(ref IParsingContext context) { - PlaceholderParameter.SetContext(ref context); + _placeholderParameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderFileParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderFileParameter.cs index 9545ddd..ab99179 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderFileParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderFileParameter.cs @@ -4,19 +4,19 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class PlaceholderFileParameter : IRuleParameter { - public PlaceholderParameter PlaceholderParameter { get; } - public FileProperty Property { get; } + private readonly PlaceholderParameter _placeholderParameter; + private readonly FileProperty _property; public PlaceholderFileParameter(PlaceholderParameter parameter, FileProperty property) { - PlaceholderParameter = parameter; - Property = property; + _placeholderParameter = parameter; + _property = property; } public string GetValue() { - var input = PlaceholderParameter.GetPlaceholder().Input; - return Property switch + var input = _placeholderParameter.GetPlaceholder().Input; + return _property switch { FileProperty.Path => input.Path, FileProperty.Data => input.Data, @@ -29,12 +29,12 @@ public string GetValue() public override string ToString() { - return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.File}{Constant.Dote}{Property}"; + return $"{_placeholderParameter}{Constant.Dote}{PlaceholderProperty.File}{Constant.Dote}{_property}"; } public void SetContext(ref IParsingContext context) { - PlaceholderParameter.SetContext(ref context); + _placeholderParameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLenghtParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLenghtParameter.cs index 621e520..4c83c7b 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLenghtParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLenghtParameter.cs @@ -2,28 +2,28 @@ { public class PlaceholderLenghtParameter: IRuleParameter { - public PlaceholderParameter PlaceholderParameter { get; } - public PlaceholderProperty Property { get; } + private readonly PlaceholderParameter _placeholderParameter; + private readonly PlaceholderProperty _property; public PlaceholderLenghtParameter(PlaceholderParameter parameter, PlaceholderProperty property) { - PlaceholderParameter = parameter; - Property = property; + _placeholderParameter = parameter; + _property = property; } public string GetValue() { - return PlaceholderParameter.GetPlaceholder().Lenght.ToString(); + return _placeholderParameter.GetPlaceholder().Lenght.ToString(); } public override string ToString() { - return $"{PlaceholderParameter}{Constant.Dote}{Property}"; + return $"{_placeholderParameter}{Constant.Dote}{_property}"; } public void SetContext(ref IParsingContext context) { - PlaceholderParameter.SetContext(ref context); + _placeholderParameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLineParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLineParameter.cs index 7b8cefc..8d296e1 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLineParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderLineParameter.cs @@ -4,20 +4,20 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class PlaceholderLineParameter : IRuleParameter { - public PlaceholderParameter PlaceholderParameter { get; } - public LineProperty Property { get; } + private readonly PlaceholderParameter _placeholderParameter; + private readonly LineProperty _property; public PlaceholderLineParameter(PlaceholderParameter parameter, LineProperty property) { - PlaceholderParameter = parameter; - Property = property; + _placeholderParameter = parameter; + _property = property; } public string GetValue() { - var line = PlaceholderParameter.GetPlaceholder().Line; + var line = _placeholderParameter.GetPlaceholder().Line; - var value = Property switch + var value = _property switch { LineProperty.Start => line.Start, LineProperty.End => line.End, @@ -29,12 +29,12 @@ public string GetValue() public override string ToString() { - return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.Line}{Constant.Dote}{Property}"; + return $"{_placeholderParameter}{Constant.Dote}{PlaceholderProperty.Line}{Constant.Dote}{_property}"; } public void SetContext(ref IParsingContext context) { - PlaceholderParameter.SetContext(ref context); + _placeholderParameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderOffsetParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderOffsetParameter.cs index 2f6454f..f6670a2 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderOffsetParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/PlaceholderOffsetParameter.cs @@ -4,19 +4,19 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class PlaceholderOffsetParameter : IRuleParameter { - public PlaceholderParameter PlaceholderParameter { get; } - public OffsetProperty Property { get; } + private readonly PlaceholderParameter _placeholderParameter; + private readonly OffsetProperty _property; public PlaceholderOffsetParameter(PlaceholderParameter parameter, OffsetProperty property) { - PlaceholderParameter = parameter; - Property = property; + _placeholderParameter = parameter; + _property = property; } public string GetValue() { - var offset = PlaceholderParameter.GetPlaceholder().Offset; + var offset = _placeholderParameter.GetPlaceholder().Offset; - var value = Property switch + var value = _property switch { OffsetProperty.Start => offset.Start, OffsetProperty.End => offset.End, @@ -28,12 +28,12 @@ public string GetValue() public override string ToString() { - return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.Offset}{Constant.Dote}{Property}"; + return $"{_placeholderParameter}{Constant.Dote}{PlaceholderProperty.Offset}{Constant.Dote}{_property}"; } public void SetContext(ref IParsingContext context) { - PlaceholderParameter.SetContext(ref context); + _placeholderParameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/StringParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/StringParameter.cs index 0ca302e..4bc8ad3 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/StringParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/Parameters/StringParameter.cs @@ -4,19 +4,20 @@ namespace SimpleStateMachine.StructuralSearch.Rules { public class StringParameter : IRuleParameter { - public string Value { get; } + private readonly string _value; + public StringParameter(string value) { - Value = value; + _value = value; } public string GetValue() { - return Value; + return _value; } public override string ToString() { - var value = EscapeHelper.EscapeChars(Value, c => $"{Constant.BackSlash}{c}", Constant.Parameter.Escape); + var value = EscapeHelper.EscapeChars(_value, c => $"{Constant.BackSlash}{c}", Constant.Parameter.Escape); return $"{value}"; } diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeBinaryParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeBinaryParameter.cs index e450325..8d20186 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeBinaryParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeBinaryParameter.cs @@ -5,19 +5,19 @@ namespace SimpleStateMachine.StructuralSearch; public class ChangeBinaryParameter : IRuleParameter { - public IRuleParameter Parameter { get; } - public ChangeType Type { get; } + private readonly IRuleParameter _parameter; + private readonly ChangeType _type; public ChangeBinaryParameter(IRuleParameter parameter, ChangeType type) { - Parameter = parameter; - Type = type; + _parameter = parameter; + _type = type; } public string GetValue() { - var value = Parameter.GetValue(); - return Type switch + var value = _parameter.GetValue(); + return _type switch { ChangeType.Trim => value.Trim(), ChangeType.TrimEnd => value.TrimEnd(), @@ -30,11 +30,11 @@ public string GetValue() public override string ToString() { - return $"{Parameter}{Constant.Dote}{Type}"; + return $"{_parameter}{Constant.Dote}{_type}"; } public void SetContext(ref IParsingContext context) { - Parameter.SetContext(ref context); + _parameter.SetContext(ref context); } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeParameter.cs index 7c4edd2..83a90ac 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeParameter.cs @@ -5,19 +5,19 @@ namespace SimpleStateMachine.StructuralSearch { public class ChangeParameter : IRuleParameter { - public IRuleParameter Parameter { get; } - public ChangeType Type { get; } + private readonly IRuleParameter _parameter; + private readonly ChangeType _type; public ChangeParameter(IRuleParameter parameter, ChangeType type) { - Parameter = parameter; - Type = type; + _parameter = parameter; + _type = type; } public string GetValue() { - var value = Parameter.GetValue(); - return Type switch + var value = _parameter.GetValue(); + return _type switch { ChangeType.Trim => value.Trim(), ChangeType.TrimEnd => value.TrimEnd(), @@ -30,12 +30,12 @@ public string GetValue() public override string ToString() { - return $"{Parameter}{Constant.Dote}{Type}"; + return $"{_parameter}{Constant.Dote}{_type}"; } public void SetContext(ref IParsingContext context) { - Parameter.SetContext(ref context); + _parameter.SetContext(ref context); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeUnaryParameter.cs b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeUnaryParameter.cs index b6293e6..d3e37da 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeUnaryParameter.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ChangeUnaryParameter.cs @@ -5,22 +5,22 @@ namespace SimpleStateMachine.StructuralSearch; public class ChangeUnaryParameter : IRuleParameter { - public IRuleParameter Parameter { get; } - public ChangeUnaryType Type { get; } - public IRuleParameter Arg { get; } + private readonly IRuleParameter _parameter; + private readonly ChangeUnaryType _type; + private readonly IRuleParameter _arg; public ChangeUnaryParameter(IRuleParameter parameter, ChangeUnaryType type, IRuleParameter arg) { - Parameter = parameter; - Type = type; - Arg = arg; + _parameter = parameter; + _type = type; + _arg = arg; } public string GetValue() { - var parameter = Parameter.GetValue(); - var arg = Arg.GetValue(); - return Type switch + var parameter = _parameter.GetValue(); + var arg = _arg.GetValue(); + return _type switch { ChangeUnaryType.RemoveSubStr => parameter.Replace(arg, string.Empty), _ => throw new ArgumentOutOfRangeException() @@ -29,12 +29,12 @@ public string GetValue() public override string ToString() { - return $"{Parameter}{Constant.Dote}{Type}{Constant.LeftParenthesis}{Arg}{Constant.RightParenthesis}"; + return $"{_parameter}{Constant.Dote}{_type}{Constant.LeftParenthesis}{_arg}{Constant.RightParenthesis}"; } public void SetContext(ref IParsingContext context) { - Parameter.SetContext(ref context); - Arg.SetContext(ref context); + _parameter.SetContext(ref context); + _arg.SetContext(ref context); } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceRule.cs index 71eca54..9582410 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceRule.cs @@ -5,7 +5,7 @@ namespace SimpleStateMachine.StructuralSearch { public class ReplaceRule: IContextDependent { - public IRule ConditionRule { get; } + public readonly IRule ConditionRule; public IEnumerable Rules { get; } diff --git a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceSubRule.cs b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceSubRule.cs index 4a93579..f609273 100644 --- a/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceSubRule.cs +++ b/src/SimpleStateMachine.StructuralSearch/Rules/ReplaceRule/ReplaceSubRule.cs @@ -4,8 +4,8 @@ namespace SimpleStateMachine.StructuralSearch; public class ReplaceSubRule: IContextDependent { - public PlaceholderParameter Placeholder { get; } - public IRuleParameter Parameter { get; } + public readonly PlaceholderParameter Placeholder; + public readonly IRuleParameter Parameter; public ReplaceSubRule(PlaceholderParameter placeholder, IRuleParameter parameter) { diff --git a/src/SimpleStateMachine.StructuralSearch/SeriesParser.cs b/src/SimpleStateMachine.StructuralSearch/SeriesParser.cs index 283e996..fc1ab85 100644 --- a/src/SimpleStateMachine.StructuralSearch/SeriesParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/SeriesParser.cs @@ -6,11 +6,11 @@ namespace SimpleStateMachine.StructuralSearch { public class SeriesParser : Parser>, IContextDependent { - public IEnumerable> Parsers { get; } + private readonly IEnumerable> _parsers; public SeriesParser(IEnumerable> parsers) { - Parsers = parsers; + _parsers = parsers; InitializeLookaheadParsers(); } @@ -19,11 +19,11 @@ public override bool TryParse(ref ParseState state, ref PooledList result) { var results = new List(); - var count = Parsers.Count(); + var count = _parsers.Count(); for (int i = 0; i < count; i++) { - var parser = Parsers.ElementAt(i); + var parser = _parsers.ElementAt(i); if (!parser.TryParse(ref state, ref expecteds, out var _result)) { result = results; @@ -63,7 +63,7 @@ void SkipLookedParsers(Parser parser, ref ParseState state) public void SetContext(ref IParsingContext parsingContext) { - foreach (var parser in Parsers) + foreach (var parser in _parsers) { if (parser is IContextDependent element) { @@ -74,16 +74,16 @@ public void SetContext(ref IParsingContext parsingContext) private void InitializeLookaheadParsers() { - var count = Parsers.Count(); + var count = _parsers.Count(); for (var i = count-1; i >= 0 ; i--) { - var parser = Parsers.ElementAt(i); + var parser = _parsers.ElementAt(i); if (parser is ParserWithLookahead lookaheadParser) { var number = i; - lookaheadParser.Lookahead(() => Parsers.ElementAtOrDefault(number + 1), () => - Parsers.ElementAtOrDefault(number + 2)); + lookaheadParser.Lookahead(() => _parsers.ElementAtOrDefault(number + 1), () => + _parsers.ElementAtOrDefault(number + 2)); } } } diff --git a/src/SimpleStateMachine.StructuralSearch/SourceMatch.cs b/src/SimpleStateMachine.StructuralSearch/SourceMatch.cs index 70f0421..06a277c 100644 --- a/src/SimpleStateMachine.StructuralSearch/SourceMatch.cs +++ b/src/SimpleStateMachine.StructuralSearch/SourceMatch.cs @@ -1,8 +1,12 @@ namespace SimpleStateMachine.StructuralSearch { - public struct SourceMatch + public readonly struct SourceMatch { - public static readonly SourceMatch Empty; + public readonly string Value; + public readonly int Start; + public readonly int End; + public readonly int Lenght; + public SourceMatch(string value, int start, int end) { Value = value; @@ -10,12 +14,6 @@ public SourceMatch(string value, int start, int end) End = end; Lenght = value.Length; } - - public string Value { get; } - public int Start { get; } - public int End { get; } - - public int Lenght { get; } public override string ToString() { diff --git a/src/SimpleStateMachine.StructuralSearch/StructuralSearchParser.cs b/src/SimpleStateMachine.StructuralSearch/StructuralSearchParser.cs index f0d41bc..d6bf563 100644 --- a/src/SimpleStateMachine.StructuralSearch/StructuralSearchParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/StructuralSearchParser.cs @@ -10,33 +10,30 @@ namespace SimpleStateMachine.StructuralSearch { public class StructuralSearchParser { - public IFindParser FindParser { get; set; } - - public IReadOnlyList FindRules { get; set; } - - public IReplaceBuilder ReplaceBuilder { get; set; } - - public IReadOnlyList ReplaceRules { get; set; } + private readonly IFindParser _findParser; + private readonly IReadOnlyList _findRules; + private readonly IReplaceBuilder _replaceBuilder; + private readonly IReadOnlyList _replaceRules; public StructuralSearchParser(Configuration configuration) { - FindParser = StructuralSearch.ParseFindTemplate(configuration.FindTemplate); + _findParser = StructuralSearch.ParseFindTemplate(configuration.FindTemplate); - FindRules = configuration.FindRules + _findRules = configuration.FindRules .EmptyIfNull() .Select(StructuralSearch.ParseFindRule).ToList(); if(!string.IsNullOrEmpty(configuration.ReplaceTemplate)) - ReplaceBuilder = StructuralSearch.ParseReplaceTemplate(configuration.ReplaceTemplate); + _replaceBuilder = StructuralSearch.ParseReplaceTemplate(configuration.ReplaceTemplate); - ReplaceRules = configuration.ReplaceRules + _replaceRules = configuration.ReplaceRules .EmptyIfNull() .Select(StructuralSearch.ParseReplaceRule).ToList(); } public IEnumerable Parse(ref IParsingContext context) { - var matches = FindParser.Parse(ref context); + var matches = _findParser.Parse(ref context); return matches; } @@ -47,7 +44,7 @@ public IEnumerable ApplyFindRule(ref IParsingContext context, foreach (var match in matches) { context.Fill(match.Placeholders); - var all = FindRules.All(x => x.Execute()); + var all = _findRules.All(x => x.Execute()); if (all) { result.Add(match); @@ -70,7 +67,7 @@ public IEnumerable ApplyReplaceRule(ref IParsingContext contex context.Fill(match.Placeholders); - var rules = ReplaceRules + var rules = _replaceRules .Where(x => { var result = x.ConditionRule.Execute(); @@ -96,7 +93,7 @@ public IEnumerable ApplyReplaceRule(ref IParsingContext contex public ReplaceMatch GetReplaceMatch(ref IParsingContext context, FindParserResult parserResult) { context.Fill(parserResult.Placeholders); - var replaceText = ReplaceBuilder.Build(context); + var replaceText = _replaceBuilder.Build(context); return new ReplaceMatch(parserResult.Match, replaceText); // context.Input.Replace(parserResult.Match, replaceText); //ReplaceBuilder.Build(context); @@ -118,7 +115,7 @@ public IEnumerable GetReplaceMatches(ref IParsingContext context, private void SetFindRulesContext(ref IParsingContext context) { - foreach (var findRule in FindRules) + foreach (var findRule in _findRules) { if(findRule is IContextDependent contextDependent) contextDependent.SetContext(ref context); @@ -127,7 +124,7 @@ private void SetFindRulesContext(ref IParsingContext context) private void SetReplaceRulesContext(ref IParsingContext context) { - foreach (var replaceRule in ReplaceRules) + foreach (var replaceRule in _replaceRules) { if(replaceRule is IContextDependent contextDependent) contextDependent.SetContext(ref context); diff --git a/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ConstantFindTemplate.cs b/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ConstantFindTemplate.cs index af08b28..19d6f4a 100644 --- a/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ConstantFindTemplate.cs +++ b/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ConstantFindTemplate.cs @@ -30,8 +30,7 @@ public static class Parameter Dote, }; - public static readonly char[] Excluded = AllParenthesisArray - .Add(Escape); + public static readonly char[] Excluded = AllParenthesisArray.Add(Escape); } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ParserToParser.cs b/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ParserToParser.cs index b9f9343..1f63736 100644 --- a/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ParserToParser.cs +++ b/src/SimpleStateMachine.StructuralSearch/Templates/FindTemplate/ParserToParser.cs @@ -10,17 +10,6 @@ public static Parser> CIChar(char token) return Parser.CIChar(token).Select(Parser.CIChar); } - // public static Parser> String(string token, bool ignoreCase = false) - // { - // return Parsers.String(token, ignoreCase).Select(x => Parsers.String(token, ignoreCase)); - // } - - // public static Parser> Stringc(char token, bool ignoreCase = false) - // { - // var _token = token.ToString(); - // return Parser.Char(_token, ignoreCase).Select(x => Parsers.String(_token, ignoreCase)); - // } - public static Parser> ResultAsParser(Parser parser, bool ignoreCase = false) { return parser.Select(value => Parsers.String(value, ignoreCase)); @@ -35,7 +24,5 @@ public static Parser> ResultAsMatch(Parser Parsers.String(x, ignoreCase).AsMatch()); } - - } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/PlaceholderReplace.cs b/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/PlaceholderReplace.cs index 639bb12..e1a0b3f 100644 --- a/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/PlaceholderReplace.cs +++ b/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/PlaceholderReplace.cs @@ -3,17 +3,17 @@ public class PlaceholderReplace : IReplaceStep, IContextDependent { private IParsingContext _context; - - public string Name { get; } + + private readonly string _name; public PlaceholderReplace(string name) { - Name = name; + _name = name; } public string GetValue() { - return _context.GetPlaceholder(Name).Value; + return _context.GetPlaceholder(_name).Value; } public void SetContext(ref IParsingContext context) @@ -23,7 +23,7 @@ public void SetContext(ref IParsingContext context) public override string ToString() { - return $"{Constant.PlaceholderSeparator}{Name}{Constant.PlaceholderSeparator}"; + return $"{Constant.PlaceholderSeparator}{_name}{Constant.PlaceholderSeparator}"; } } } \ No newline at end of file diff --git a/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/TokenReplace.cs b/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/TokenReplace.cs index 8333b1b..08c880c 100644 --- a/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/TokenReplace.cs +++ b/src/SimpleStateMachine.StructuralSearch/Templates/ReplaceTemplate/TokenReplace.cs @@ -2,20 +2,21 @@ { public class TokenReplace : IReplaceStep { - public string Token { get; } + private readonly string _token; + public TokenReplace(string token) { - Token = token; + _token = token; } public string GetValue() { - return Token; + return _token; } public override string ToString() { - return $"{Token}"; + return $"{_token}"; } } } \ No newline at end of file