Skip to content

Commit

Permalink
Final draft of SobaScript, Mapper, Z.Core, Z.Ext, Z.VS /part of #55
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed Sep 10, 2019
1 parent ca0f2c7 commit 60a6702
Show file tree
Hide file tree
Showing 231 changed files with 13,880 additions and 11,649 deletions.
10 changes: 5 additions & 5 deletions E-MSBuild/EvMSBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ string h(string _data, char qtype)
return Regex.Replace
(
_data,
(qtype == '"') ? RPattern.DoubleQuotesContent : RPattern.SingleQuotesContent,
(qtype == '"') ? Pattern.DoubleQuotesContent : Pattern.SingleQuotesContent,
(Match m) =>
{
string content = m.Groups[1].Value;
Expand Down Expand Up @@ -416,7 +416,7 @@ protected string GetUVarValue(string ident)
/// <exception cref="IncorrectSyntaxException"></exception>
protected Analysis Prepare(string raw)
{
Match m = RPattern.PItem.Match(raw.Trim());
Match m = Pattern.PItem.Match(raw.Trim());
if(!m.Success) {
throw new IncorrectSyntaxException($"prepare: failed: {raw}");
}
Expand Down Expand Up @@ -547,7 +547,7 @@ protected Analysis Prepare(string raw)
/// <returns></returns>
private protected string ContainerIn(string data, StringHandler sh, uint limit)
{
Regex con = RPattern.ContainerInCompiled;
Regex con = Pattern.ContainerInCompiled;
int maxRep = 1; // rule of depth, e.g.: $(p1 = $(Platform))$(p2 = $(p1))$(p2)
//TODO: it's slowest but fully compatible with classic rules with minimal programming.. so, improve performance

Expand Down Expand Up @@ -617,7 +617,7 @@ private protected string VSignOperation(Analysis prepared, string val)
}

var left = UVars.GetValue(prepared.variable.name, prepared.variable.scope) ?? "0";
bool isNumber = RPattern.IsNumber.IsMatch(left);
bool isNumber = Pattern.IsNumber.IsMatch(left);

LSender.Send(this, $"vSignOperation: '{prepared.variable.vSign}'; `{left}` (isNumber: {isNumber})", MsgLevel.Trace);

Expand Down Expand Up @@ -783,7 +783,7 @@ void unlink(string _name)
}
}

data = RPattern.ContainerInNamedCompiled.Replace(data, (Match m) =>
data = Pattern.ContainerInNamedCompiled.Replace(data, (Match m) =>
{
string found = m.Groups["name"].Value;
Expand Down
3 changes: 2 additions & 1 deletion E-MSBuild/IEvMSBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Build.Evaluation;
using net.r_eg.Varhead;

namespace net.r_eg.EvMSBuild
Expand All @@ -37,6 +36,8 @@ namespace net.r_eg.EvMSBuild
/// Advanced Evaluator of MSBuild scripts aka Advanced MSBuild
/// with user-variables support through Varhead and more.
/// https://github.com/3F/E-MSBuild
///
/// Please note: initially it was part of https://github.com/3F/vsSolutionBuildEvent
/// </summary>
[Guid("958B9A32-BE6F-4B74-A98A-AC99099A63A5")]
public interface IEvMSBuild: IEvaluator
Expand Down
54 changes: 27 additions & 27 deletions E-MSBuild/RPattern.cs → E-MSBuild/Pattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@

namespace net.r_eg.EvMSBuild
{
public static class RPattern
public static class Pattern
{
private static readonly Lazy<Regex> _ContainerInCompiled = new Lazy<Regex>(() => new Regex
private static readonly Lazy<Regex> _containerInCompiled = new Lazy<Regex>(() => new Regex
(
ContainerIn,
RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled
));

private static readonly Lazy<Regex> _ContainerInNamedCompiled = new Lazy<Regex>(() => new Regex
private static readonly Lazy<Regex> _containerInNamedCompiled = new Lazy<Regex>(() => new Regex
(
GetContainerIn(@"\s*(?'name'[^$\s).:]+)"), // $( name ...
RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled
));

private static readonly Lazy<Regex> _IsNumber = new Lazy<Regex>(() => new Regex
private static readonly Lazy<Regex> _isNumber = new Lazy<Regex>(() => new Regex
(
@"^\d+([.,]\d+)?$", RegexOptions.Compiled
));

private static readonly Lazy<Regex> _PItem = new Lazy<Regex>(() => new Regex
private static readonly Lazy<Regex> _pItem = new Lazy<Regex>(() => new Regex
(
string.Format
(@"^\(
Expand Down Expand Up @@ -77,88 +77,88 @@ public static class RPattern
RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled
));

private static readonly Lazy<string> _ContainerEscOuter = new Lazy<string>(() =>
private static readonly Lazy<string> _containerEscOuter = new Lazy<string>(() =>
Container(ContainerType.Escaped, false)
);

private static readonly Lazy<string> _ContainerIn = new Lazy<string>(() =>
private static readonly Lazy<string> _containerIn = new Lazy<string>(() =>
Container(ContainerType.Normal, true)
);

private static readonly Lazy<string> _ContainerOuter = new Lazy<string>(() =>
private static readonly Lazy<string> _containerOuter = new Lazy<string>(() =>
Container(ContainerType.Normal, false)
);

private static readonly Lazy<string> _DoubleQuotesContentFull = new Lazy<string>(() =>
private static readonly Lazy<string> _doubleQuotesContentFull = new Lazy<string>(() =>
QuotesContent('"', false)
);

private static readonly Lazy<string> _SingleQuotesContentFull = new Lazy<string>(() =>
private static readonly Lazy<string> _singleQuotesContentFull = new Lazy<string>(() =>
QuotesContent('\'', false)
);

private static readonly Lazy<string> _DoubleQuotesContent = new Lazy<string>(() =>
private static readonly Lazy<string> _doubleQuotesContent = new Lazy<string>(() =>
QuotesContent('"', true)
);

private static readonly Lazy<string> _SingleQuotesContent = new Lazy<string>(() =>
private static readonly Lazy<string> _singleQuotesContent = new Lazy<string>(() =>
QuotesContent('\'', true)
);

/// <summary>
/// Checks the numeric format.
/// </summary>
public static Regex IsNumber => _IsNumber.Value;
public static Regex IsNumber => _isNumber.Value;

/// <summary>
/// Escaped outer container, eg.: -} $$(.. $(..) ...) {-
/// </summary>
public static string ContainerEscOuter => _ContainerEscOuter.Value;
public static string ContainerEscOuter => _containerEscOuter.Value;

/// <summary>
/// Outer container, eg.: -} $(.. $(..) ...) {-
/// </summary>
public static string ContainerOuter => _ContainerOuter.Value;
public static string ContainerOuter => _containerOuter.Value;

/// <summary>
/// Content from double quotes.
/// Content from double quotes according to E-MSBuild.
/// </summary>
public static string DoubleQuotesContent => _DoubleQuotesContent.Value;
public static string DoubleQuotesContent => _doubleQuotesContent.Value;

/// <summary>
/// Content from single quotes.
/// Content from single quotes according to E-MSBuild.
/// </summary>
public static string SingleQuotesContent => _SingleQuotesContent.Value;
public static string SingleQuotesContent => _singleQuotesContent.Value;

/// <summary>
/// Double quotes with content.
/// Double quotes with content according to E-MSBuild.
/// </summary>
public static string DoubleQuotesContentFull => _DoubleQuotesContentFull.Value;
public static string DoubleQuotesContentFull => _doubleQuotesContentFull.Value;

/// <summary>
/// Single quotes with content.
/// Single quotes with content according to E-MSBuild.
/// </summary>
public static string SingleQuotesContentFull => _SingleQuotesContentFull.Value;
public static string SingleQuotesContentFull => _singleQuotesContentFull.Value;

/// <summary>
/// Compiled ContainerIn.
/// </summary>
internal static Regex ContainerInCompiled => _ContainerInCompiled.Value;
internal static Regex ContainerInCompiled => _containerInCompiled.Value;

/// <summary>
/// Compiled ContainerIn with naming the left definitions.
/// </summary>
internal static Regex ContainerInNamedCompiled => _ContainerInNamedCompiled.Value;
internal static Regex ContainerInNamedCompiled => _containerInNamedCompiled.Value;

/// <summary>
/// An expression of property item.
/// </summary>
internal static Regex PItem => _PItem.Value;
internal static Regex PItem => _pItem.Value;

/// <summary>
/// Deepest container, eg.: $(.. -} $(..) {- ...)
/// </summary>
internal static string ContainerIn => _ContainerIn.Value;
internal static string ContainerIn => _containerIn.Value;

/// <summary>
/// Deepest container, eg.: $(.. -} $(..) {- ...)
Expand Down
6 changes: 3 additions & 3 deletions E-MSBuild/StringHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ internal class StringHandler: SProtectorAbstract
/// <summary>
/// Specific format of double quotes with content
/// </summary>
public override string DoubleQuotesContentFull => RPattern.DoubleQuotesContentFull;
public override string DoubleQuotesContentFull => Pattern.DoubleQuotesContentFull;

/// <summary>
/// Specific format of single quotes with content
/// </summary>
public override string SingleQuotesContentFull => RPattern.SingleQuotesContentFull;
public override string SingleQuotesContentFull => Pattern.SingleQuotesContentFull;

/// <summary>
/// Protects escaped MSBuild data.
Expand All @@ -53,7 +53,7 @@ public string ProtectEscContainer(string data)
return Regex.Replace
(
data,
RPattern.ContainerEscOuter,
Pattern.ContainerEscOuter,
(Match m) =>
{
uint ident = IdentNext;
Expand Down
4 changes: 2 additions & 2 deletions E-MSBuildTest/ParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ParserTest
[Fact]
public void BasicParseTest1()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

string actual = target.Eval("FooBar");
string expected = "FooBar";
Expand Down Expand Up @@ -76,7 +76,7 @@ public void BasicParseTest5()
[Fact]
public void BasicParseTest6()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

string actual = target.Eval("$$(Path.Replace('\', '/'):project)");
string expected = "$(Path.Replace('\', '/'):project)";
Expand Down
16 changes: 8 additions & 8 deletions E-MSBuildTest/QuotesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class QuotesTest
[Fact]
public void QuotesTest1()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

Assert.Equal(string.Empty, target.Eval("$(name = \" $([System.Math]::Pow(2, 16)) \")"));
Assert.Equal(" 65536 ", target.UVars.GetValue("name", null));
Expand All @@ -22,7 +22,7 @@ public void QuotesTest1()
[Fact]
public void QuotesTest2()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();
Assert.Equal(" left '123' right ", target.Eval("$([System.String]::Format(\" left '{0}' right \", \"123\"))"));
Assert.Equal(" left '123' ) right ", target.Eval("$([System.String]::Format(\" left '{0}' ) right \", \"123\"))"));

Expand All @@ -33,7 +33,7 @@ public void QuotesTest2()
[Fact]
public void QuotesTest3()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

Assert.Equal(string.Empty, target.Eval("$(tpl = \"My version - '%Ver%'\")"));
Assert.Equal("My version - '%Ver%'", target.UVars.GetValue("tpl", null));
Expand All @@ -51,7 +51,7 @@ public void QuotesTest3()
[Fact]
public void QuotesTest4()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

target.UVars.SetVariable("name", "project", "test123");
target.UVars.Evaluate("name", "project", new EvaluatorBlank(), true);
Expand All @@ -63,7 +63,7 @@ public void QuotesTest4()
[Fact]
public void QuotesTest5()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

target.UVars.SetVariable("name", null, "test123");
target.UVars.Evaluate("name", null, new EvaluatorBlank(), true);
Expand All @@ -75,7 +75,7 @@ public void QuotesTest5()
[Fact]
public void QuotesTest6()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

Assert.Equal(string.Empty, target.Eval("$(version = \"1.2.3\")"));
Assert.Equal(string.Empty, target.Eval("$(tpl = \"My version - $(version), \\\"$(version)\\\", '$(version)' end.\")"));
Expand Down Expand Up @@ -130,7 +130,7 @@ public void QuotesTest9()
[Fact]
public void QuotesTest10()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();

target.UVars.SetVariable("name", null, "test123");
target.UVars.Evaluate("name", null, new EvaluatorBlank(), true);
Expand All @@ -151,7 +151,7 @@ public void QuotesTest10()
[Fact]
public void QuotesTest11()
{
var target = new EvMSBuilderStub();
var target = new EvMSBuilderAcs();
Assert.Equal("simply \"text\" data", target.Eval("simply \"text\" data"));
Assert.Equal("simply \\\"text\\\" data", target.Eval("simply \\\"text\\\" data"));
Assert.Equal("simply \\\\\"text\\\\\" data", target.Eval("simply \\\\\"text\\\\\" data"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace EvMSBuildTest.Stubs
{
internal class EvMSBuilderStub: EvMSBuilder
internal class EvMSBuilderAcs: EvMSBuilder
{
public EvMSBuilderStub()
public EvMSBuilderAcs()
: base(new EnvStub())
{

Expand Down
2 changes: 1 addition & 1 deletion E-MSBuildTest/Stubs/StubEvaluatingProperty.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace EvMSBuildTest.Stubs
{
internal class StubEvaluatingProperty: EvMSBuilderStub
internal class StubEvaluatingProperty: EvMSBuilderAcs
{
public override string GetPropValue(string name, string project)
{
Expand Down
Loading

0 comments on commit 60a6702

Please sign in to comment.