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
12 changes: 7 additions & 5 deletions src/SimpleStateMachine.StructuralSearch.Sandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ internal static class Program
{
static void Main(string[] args)
{
var tesds = ParametersParser.StringFormatParameter.ParseOrThrow("\"tfasdfa\\\"sd$var$.Lenght\"");
var rule = StructuralSearch.ParseFindRule("$var$ equals $var$.Lenght and Not StartsWith \"123\"");
//var tesds = ParametersParser.StringFormatParameter.ParseOrThrow("\"tfasdfa\\\"sd$var$.Lenght\"");
var replaceRule = StructuralSearch.ParseReplaceRule("$var$ equals $var$ => $var$.Trim");

var rule = StructuralSearch.ParseFindRule("$var$ equals $var$.Lenght and Not StartsWith \"123\\\" $var$ \\\"\"");
var rule2 = StructuralSearch.ParseFindRule("$var$ equals $var$.Offset.Start and Not StartsWith \"123\"");
var result1 = rule.Execute("test");
var result2 = rule.Execute("10");
var result3 = rule.Execute("5.3");
// var result1 = rule.Execute("test");
// var result2 = rule.Execute("10");
// var result3 = rule.Execute("5.3");

var t = ExprParser.ParseOrThrow("2 + 2 + 2");
var resw = t.Invoke();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Linq;
using Pidgin;
using Xunit;

namespace SimpleStateMachine.StructuralSearch.Tests
{
public class FindRuleParserTests
{
[Theory]
[InlineData("equals $var$")]
[InlineData("equals \"\\$\"")]
[InlineData("Not equals $var$.Lenght")]
[InlineData("Not equals $var$.offset.Start")]
[InlineData("equals $var$.Lenght and Not StartsWith \"123\"")]
[InlineData("equals $var$.Lenght and Not StartsWith \"\\\"Test\"")]
public void FindRuleParsingShouldBeSuccess(string ruleStr)
{
var rule = FindRuleParser.Expr.ParseOrThrow(ruleStr);
var _ruleStr = rule.ToString()?.ToLower();
Assert.NotNull(rule);
Assert.Equal(_ruleStr, ruleStr.ToLower());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Linq;
using Pidgin;
using Xunit;

namespace SimpleStateMachine.StructuralSearch.Tests
{
public class ReplaceRuleParserTests
{
[Theory]
[InlineData("equals $var$", "$var$")]
[InlineData("equals \"\\$\"", "\"\\$\"")]
[InlineData("Not equals $var$.Lenght", "$var$.Lenght")]
[InlineData("Not equals $var$.offset.Start", "$var$.offset.Start")]
[InlineData("equals $var$.Lenght and Not StartsWith \"123\"", "$var$.offset.Start.Trim")]
[InlineData("equals $var$.Lenght and Not StartsWith \"\\\"Test\"", "$var$.offset.Start.ToUpper")]
public void FindRuleParsingShouldBeSuccess(string findRule, string replaceRule)
{
var placeholder = "$var$";
var replaceRuleStr = $"{placeholder} {findRule} => {replaceRule}";
var rule = StructuralSearch.ParseReplaceRule(replaceRuleStr);
var _ruleStr = rule.ToString().ToLower();
Assert.NotNull(rule);
Assert.Equal(_ruleStr, replaceRuleStr.ToLower());
}
}
}

This file was deleted.

15 changes: 15 additions & 0 deletions src/SimpleStateMachine.StructuralSearch/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ public static partial class Constant
/// </summary>
public static readonly char Dote = '.';

/// <summary>
/// Char: '='
/// </summary>
public static readonly char Equals = '=';

/// <summary>
/// Char: '>'
/// </summary>
public static readonly char More = '>';

/// <summary>
/// String: "=>"
/// </summary>
public static readonly string Should = $"{Equals}{More}";

/// <summary>
/// Parenthesis chars: '(' and ')'
/// </summary>
Expand Down
14 changes: 0 additions & 14 deletions src/SimpleStateMachine.StructuralSearch/Helper/CharHelper.cs

This file was deleted.

38 changes: 38 additions & 0 deletions src/SimpleStateMachine.StructuralSearch/Helper/EscapeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Linq;

namespace SimpleStateMachine.StructuralSearch.Helper
{
public static class EscapeHelper
{
public static string Escape(string str, Func<char, char> replaceRule)
{
return new string(str.Select(replaceRule).ToArray());
}

public static string EscapeChars(string str, Func<char, char> replaceRule, params char[] filter)
{
return new string(str.Select(c => filter.Contains(c) ? replaceRule(c) : c).ToArray());
}

public static string EscapeExclude(string str, Func<char, char> replaceRule, params char[] excluded)
{
return new string(str.Select(c => excluded.Contains(c) ? c : replaceRule(c)).ToArray());
}

public static string Escape(string str, Func<char, string> replaceRule)
{
return string.Join(string.Empty, str.Select(replaceRule));
}

public static string EscapeChars(string str, Func<char, string> replaceRule, params char[] filter)
{
return string.Join(string.Empty, str.Select(c => filter.Contains(c) ? replaceRule(c) : c.ToString()));
}

public static string EscapeExclude(string str, Func<char, string> replaceRule, params char[] excluded)
{
return string.Join(string.Empty, str.Select(c => excluded.Contains(c) ? c.ToString() : replaceRule(c)));
}
}
}
20 changes: 0 additions & 20 deletions src/SimpleStateMachine.StructuralSearch/Rule/FindRule/Rule.cs

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions src/SimpleStateMachine.StructuralSearch/Rule/RuleParser.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public bool Execute(string value)

return LogicalHelper.Calculate(Type, left, right);
}

public override string ToString()
{
return $"{Left}{Constant.Space}{Type}{Constant.Space}{Right}";
}
}
}
20 changes: 20 additions & 0 deletions src/SimpleStateMachine.StructuralSearch/Rules/FindRule/FindRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace SimpleStateMachine.StructuralSearch.Rules
{
public class FindRule
{
public IRuleParameter Placeholder { get; }

private IRule _rule { get; }

public FindRule(IRuleParameter placeholder, IRule rule)
{
Placeholder = placeholder;
_rule = rule;
}

public override string ToString()
{
return $"{Placeholder}{Constant.Space}{_rule}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ public bool Execute(string value)
{
return Parameters.Any(parameter => Equals(value, parameter.GetValue()));
}

public override string ToString()
{
return $"{Type}{Constant.Space}{string.Join(Constant.Space, Parameters.Select(x=>x.ToString()))}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ public bool Execute(string value)
_ => throw new ArgumentOutOfRangeException()
};
}

public override string ToString()
{
return $"{Type}{Constant.Space}{PlaceholderType}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public bool Execute(string value)
_ => throw new ArgumentOutOfRangeException()
};
}

public override string ToString()
{
return $"{Type}{Constant.Space}{Parameter}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ public bool Execute(string value)
_ => throw new ArgumentOutOfRangeException()
};
}

public override string ToString()
{
return $"{Type}{Constant.Space}{Parameter}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ public static class ParametersParser
.TrimStart()
.Try();

public static readonly Parser<char, IRuleParameter> Parameter =
Parser.OneOf(PlaceholderPropertyParser.PlaceholderPropertyParameter, PlaceholderParameter);

public static readonly Parser<char, IEnumerable<IRuleParameter>> Parameters =
Parameter.AtLeastOnce();

public static readonly Parser<char, IRuleParameter> StringParameter =
CommonParser.Escaped(Constant.DoubleQuotes, Constant.PlaceholderSeparator)
.Or(Parser.AnyCharExcept(Constant.DoubleQuotes, Constant.PlaceholderSeparator))
.AtLeastOnceString()
.Select(x => new StringParameter(x))
.As<char, StringParameter, IRuleParameter>()
.TrimStart()
.Try();

public static readonly Parser<char, IRuleParameter> StringFormatParameter =
Expand All @@ -36,5 +31,14 @@ public static class ParametersParser
.As<char, StringFormatParameter, IRuleParameter>()
.TrimStart()
.Try();

public static readonly Parser<char, IRuleParameter> Parameter =
Parser.OneOf(PlaceholderPropertyParser.PlaceholderPropertyParameter, PlaceholderParameter, StringFormatParameter)
.TrimStart()
.Try();

public static readonly Parser<char, IEnumerable<IRuleParameter>> Parameters =
Parameter.AtLeastOnce();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public string GetValue()
{
throw new System.NotImplementedException();
}

public override string ToString()
{
return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.Column}{Constant.Dote}{Property}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public string GetValue()
{
throw new System.NotImplementedException();
}

public override string ToString()
{
return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.File}{Constant.Dote}{Property}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public string GetValue()
{
throw new System.NotImplementedException();
}

public override string ToString()
{
return $"{PlaceholderParameter}{Constant.Dote}{Property}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public string GetValue()
{
throw new System.NotImplementedException();
}

public override string ToString()
{
return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.Line}{Constant.Dote}{Property}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public string GetValue()
{
throw new System.NotImplementedException();
}

public override string ToString()
{
return $"{PlaceholderParameter}{Constant.Dote}{PlaceholderProperty.Offset}{Constant.Dote}{Property}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ public string GetValue()
{
throw new System.NotImplementedException();
}

public override string ToString()
{
return $"{Constant.PlaceholderSeparator}{Name}{Constant.PlaceholderSeparator}";
}
}
}
Loading