Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SimpleStateMachine.StructuralSearch.Action/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static TService Get<TService>(IHost host)
where TService : notnull =>
host.Services.GetRequiredService<TService>();

static async Task StartAnalysisAsync(ActionInputs inputs, IHost host)
static Task StartAnalysisAsync(ActionInputs inputs, IHost host)
{
// using ProjectWorkspace workspace = Get<ProjectWorkspace>(host);
using CancellationTokenSource tokenSource = new();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static Configuration GetConfigurationFromFiles(string name)
ReplaceTemplate = replaceTemplate,
ReplaceRules = replaceRules
};

return config;

string? FileOrNull(string folder, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ namespace SimpleStateMachine.StructuralSearch.Configurations
public class Configuration : IEquatable<Configuration>
{
public string FindTemplate { get; init; }

public List<string>? FindRules { get; init; }

public string ReplaceTemplate { get; init; }

public List<string>? ReplaceRules { get; init; }

public bool Equals(Configuration? other)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SimpleStateMachine.StructuralSearch.Configurations
{
public class ConfigurationFile: IEquatable<ConfigurationFile>
{
public List<Configuration> Configurations { get; set; }
public List<Configuration> Configurations { get; init; }

public bool Equals(ConfigurationFile? other)
{
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleStateMachine.StructuralSearch/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static partial class Constant
/// <summary>
/// Char: '='
/// </summary>
public const char Equals = '=';
private const char Equals = '=';

/// <summary>
/// Char: '>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ namespace SimpleStateMachine.StructuralSearch.Extensions
{
public static class EnumerableCharExtensions
{
public static Parser<Ttoken, string> AsString<Ttoken>(this Parser<Ttoken, IEnumerable<char>> parser)
public static Parser<TToken, string> AsString<TToken>(this Parser<TToken, IEnumerable<char>> parser)
{
return parser.Select(x => new string(x.ToArray()));
}

public static Parser<Ttoken, IEnumerable<T>> MergerMany<Ttoken, T>(
this Parser<Ttoken, IEnumerable<IEnumerable<T>>> parser)
public static Parser<TToken, IEnumerable<T>> MergerMany<TToken, T>(
this Parser<TToken, IEnumerable<IEnumerable<T>>> parser)
{
return parser.Select(x => x.SelectMany(y => y));
}

public static Parser<Ttoken, IEnumerable<T>> MergerMany<Ttoken, T>(
this Parser<Ttoken, IEnumerable<List<T>>> parser)
public static Parser<TToken, IEnumerable<T>> MergerMany<TToken, T>(
this Parser<TToken, IEnumerable<List<T>>> parser)
{
return parser.Select(x => x.SelectMany(y => y));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace SimpleStateMachine.StructuralSearch.Extensions
{
public static class EnumerableStringExtensions
{
public static string JoinToString(this IEnumerable<string> enumerable, string separator = null)
public static string JoinToString(this IEnumerable<string> enumerable, string? separator = null)
{
return string.Join(separator, enumerable);
}

public static string JoinToString(this List<string> enumerable, string separator = null)
public static string JoinToString(this List<string> enumerable, string? separator = null)
{
return string.Join(separator, enumerable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ public static class IEnumerableSourceMatchExtensions
{
public static SourceMatch Concatenate(this IEnumerable<SourceMatch> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public static Parser<TToken, IEnumerable<string>> ToMany<TToken>(this Parser<TTo
return parser.Select(x => new List<string>() { x }).ToIEnumerable();
}

public static Parser<TToken, string> JoinToString<TToken>(this Parser<TToken, IEnumerable<string>> parser, string separator = null)
public static Parser<TToken, string> JoinToString<TToken>(this Parser<TToken, IEnumerable<string>> parser, string? separator = null)
{
separator ??= string.Empty;
return parser.Select(x => string.Join(separator, x));
}

public static Parser<TToken, string> JoinToString<TToken>(this Parser<TToken, List<string>> parser, string separator = null)
public static Parser<TToken, string> JoinToString<TToken>(this Parser<TToken, List<string>> parser, string? separator = null)
{
separator ??= string.Empty;
return parser.Select(x => string.Join(separator, x));
Expand Down
2 changes: 0 additions & 2 deletions src/SimpleStateMachine.StructuralSearch/Helper/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,5 @@ public static bool TryGetValue<TEnum>(string value, bool ignoreCase, out TEnum r
{
return Enum.TryParse(value, ignoreCase, out result);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class StreamExtensions
/// </summary>
/// <param name="source">The source stream.</param>
/// <param name="destination">The destination stream.</param>
/// <param name="offset"></param>
/// <param name="count">The number of bytes to copy.</param>
/// <param name="bufferSize">The size of the buffer to use.
/// The default is 4096.</param>
Expand All @@ -34,6 +35,7 @@ public static void CopyPartTo(this Stream source, Stream destination, int offset
/// </summary>
/// <param name="source">The source stream.</param>
/// <param name="destination">The destination stream.</param>
/// <param name="offset"></param>
/// <param name="count">The number of bytes to copy.</param>
public static void CopyPartTo(this Stream source, Stream destination, int offset, int count)
{
Expand Down
2 changes: 0 additions & 2 deletions src/SimpleStateMachine.StructuralSearch/Input/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions src/SimpleStateMachine.StructuralSearch/Input/StringInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char, T> ParseBy<T>(Parser<char, T> parser)
{
return parser.Parse(Input);
return parser.Parse(_input);
}

public void Replace(Match<string> match, string value)
Expand All @@ -25,6 +25,6 @@ public void Replace(Match<string> 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;
}
}
10 changes: 5 additions & 5 deletions src/SimpleStateMachine.StructuralSearch/Output/FileOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReplaceMatch> replaceMatches)
Expand All @@ -22,7 +22,7 @@ public void Replace(IInput input, IEnumerable<ReplaceMatch> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SimpleStateMachine.StructuralSearch
{
public class DebugParser<TToken, T>: Parser<TToken, T>
{
private Parser<TToken, T> _parser;
private readonly Parser<TToken, T> _parser;
public DebugParser(Parser<TToken, T> parser)
{
_parser = parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace SimpleStateMachine.StructuralSearch
{
public class EmptyStringParser : Parser<char, string>
{
public bool Value { get; }
private readonly bool _value;

public EmptyStringParser(bool value)
{
Value = value;
_value = value;
}

public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expecteds,
out string result)
{
result = string.Empty;
return Value;
return _value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SimpleStateMachine.StructuralSearch
public class EnumParser<TEnum> : Parser<char, TEnum>
where TEnum : struct, Enum
{
private Parser<char, TEnum> _parser;
private readonly Parser<char, TEnum> _parser;

public EnumParser(bool ignoreCase, params TEnum [] excluded)
{
Expand Down
38 changes: 1 addition & 37 deletions src/SimpleStateMachine.StructuralSearch/Parsers/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ public static Parser<char, TEnum> After<TEnum>(TEnum value, bool ignoreCase = fa
{
return Parsers.String(value.ToString(), ignoreCase).AsEnum<TEnum>(ignoreCase);
}

// public static Parser<char, string> EnumValue<TEnum>(TEnum value, bool ignoreCase = false)
// where TEnum : struct, Enum
// {
// return Parsers.String(value.Name(), ignoreCase).AsEnum<TEnum>();
// }


public static Parser<TToken, IEnumerable<T>> MapToMany<TToken, T>(Parser<TToken, T> parser1,
Parser<TToken, T> parser2, Parser<TToken, T> parser3)
{
Expand Down Expand Up @@ -88,12 +82,6 @@ public static Parser<char, IEnumerable<T>> BetweenOneOfChars<T>(Func<char, Parse
);
}

// public static Parser<char, T> BetweenOneOf<T>(Func<char, Parser<char, T>> leftRight,
// Parser<char, T> expr, params (char, char)[] values)
// {
// return OneOf(values.Select(x => expr.Between(leftRight(x.Item1), leftRight(x.Item2))));
// }

public static Parser<char, IEnumerable<T>> BetweenOneOfChars<T>(Func<char, Parser<char, T>> leftRight,
Parser<char, T> expr, params (char, char)[] values)
{
Expand Down Expand Up @@ -141,29 +129,5 @@ public static Parser<char, Match<T>> Match<T>(Parser<char, T> parser)
parser,
Parser<char>.CurrentPos, Parser<char>.CurrentOffset);
}


// public static string Match(Parser<char, string> parser, ref ParseState<char> state,
// ref PooledList<Expected<char>> expected, out string result)
// {
// Parser<char>.CurrentPos.Then(Parser<char>.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<char>.CurrentPos.TryParse(ref state, ref expected, out var newPos);
// Parser<char>.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;
// }
}
}
Loading