Skip to content

Commit

Permalink
upgrade to 0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 30, 2016
1 parent bd28f41 commit b480c38
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 168 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.2:
- [core] Support Verbatium String(@"\/")
- [vstool] update to supoort verbatium string

## 0.8.1:
- [core] Reduce .NET version request to 4.5.1
- [ex] Reduce .NET version request to 4.5.1
Expand Down
4 changes: 2 additions & 2 deletions sdmap/src/sdmap.ext/project.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": "0.8.1",
"version": "0.8.2",

"dependencies": {
"sdmap": "0.8.1",
"sdmap": "0.8.2",
"Dapper": "1.50.2"
},
"frameworks": {
Expand Down
4 changes: 2 additions & 2 deletions sdmap/src/sdmap.vstool/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<package id="Microsoft.VisualStudio.Text.Logic" version="14.3.25407" targetFramework="net452" />
<package id="Microsoft.VisualStudio.Text.UI" version="14.3.25407" targetFramework="net452" />
<package id="Microsoft.VisualStudio.Text.UI.Wpf" version="14.3.25407" targetFramework="net452" />
<package id="Microsoft.VSSDK.BuildTools" version="14.3.25407" targetFramework="net452" developmentDependency="true" />
<package id="sdmap" version="0.6.0" targetFramework="net452" />
<package id="Microsoft.VSSDK.BuildTools" version="14.3.25420" targetFramework="net452" developmentDependency="true" />
<package id="sdmap" version="0.8.2" targetFramework="net452" />
</packages>
12 changes: 6 additions & 6 deletions sdmap/src/sdmap.vstool/sdmap.vstool.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.props')" />
<Import Project="..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down Expand Up @@ -94,8 +94,8 @@
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="sdmap, Version=0.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\sdmap.0.6.0\lib\net452\sdmap.dll</HintPath>
<Reference Include="sdmap, Version=0.8.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\sdmap.0.8.2\lib\net451\sdmap.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -112,10 +112,10 @@
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.targets'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.targets'))" />
</Target>
<Import Project="..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25407\build\Microsoft.VSSDK.BuildTools.targets')" />
<Import Project="..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\..\packages\Microsoft.VSSDK.BuildTools.14.3.25420\build\Microsoft.VSSDK.BuildTools.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion sdmap/src/sdmap.vstool/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="sdmap.vstool.sdcb.e19a593c-36ce-4a09-b4d9-63af7887887f" Version="0.6.0" Language="en-US" Publisher="sdcb" />
<Identity Id="sdmap.vstool.sdcb.e19a593c-36ce-4a09-b4d9-63af7887887f" Version="0.8.2" Language="en-US" Publisher="sdcb" />
<DisplayName>sdmap.vstool</DisplayName>
<Description xml:space="preserve">Visual Studio tool for sdmap.</Description>
<MoreInfo>https://github.com/sdcb/sdmap</MoreInfo>
Expand Down
1 change: 1 addition & 0 deletions sdmap/src/sdmap/Parser/G4/SdmapLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CloseCurlyBrace:
'}'{bracePrefix = "";};

STRING:
'@"' (~'"' | '""')* '"' |
'"' (('\\' (["\\/bfnrt] | UNICODE)) | ~ ["\\])* '"' |
'\'' (('\\' (['\\/bfnrt] | UNICODE)) | ~ ['\\])* '\'';

Expand Down
164 changes: 93 additions & 71 deletions sdmap/src/sdmap/Utils/StringUtil.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,93 @@
using sdmap.Functional;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace sdmap.Utils
{
public class StringUtil
{
public static Result<string> Parse(string input)
{
if (string.IsNullOrWhiteSpace(input))
return Result.Fail<string>($"string literial must not be empty.");

if (input.Length <= 2)
return Result.Fail<string>($"string literial length must > 2.");

if (input.First() != input.Last())
return Result.Fail<string>($"string literial's first and last char must be the same.");

var firstChar = input[0];
var escapedChar = Details.GetEscapedChar(firstChar);
if (escapedChar.IsFailure)
return Result.Fail<string>(escapedChar.Error);

var inner = input.Substring(1, input.Length - 2);
return Result.Ok(Details.EscapeNoCheck(inner, escapedChar.Value));
}

public class Details
{
public static Result<char> GetEscapedChar(char ch)
{
if (ch == '\'')
{
return Result.Ok('"');
}
else if (ch == '"')
{
return Result.Ok('\'');
}
else
{
return Result.Fail<char>($"char {ch} not escappable.");
}
}

public static string EscapeNoCheck(string input, char escapeChar)
{
var unicodeRegex = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");

var result = input
.Replace(@"\\", @"\")
.Replace(@"\/", @"/")
.Replace(@"\t", "\t")
.Replace(@"\b", "\b")
.Replace(@"\f", "\f")
.Replace(@"\n", "\n")
.Replace(@"\r", "\r")
.Replace(@"\t", "\t")
.Replace($@"\{escapeChar}", escapeChar.ToString());

return unicodeRegex.Replace(result, match =>
((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
}
}
}
}
using sdmap.Functional;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace sdmap.Utils
{
public class StringUtil
{
public static Result<string> Parse(string input)
{
if (string.IsNullOrWhiteSpace(input))
return Result.Fail<string>($"string literial must not be empty.");

if (input[0] == '@')
{
return AtStringParse(input);
}
else
{
return RegularStringParse(input);
}
}

private static Result<string> RegularStringParse(string input)
{
if (input.Length < 2)
return Result.Fail<string>($"string literial length must > 2.");

if (input.First() != input.Last())
return Result.Fail<string>($"string literial's first and last char must be the same.");

var firstChar = input[0];
var escapedChar = Details.GetEscapedChar(firstChar);
if (escapedChar.IsFailure)
return Result.Fail<string>(escapedChar.Error);

var inner = input.Substring(1, input.Length - 2);
return Result.Ok(Details.EscapeNoCheck(inner, escapedChar.Value));
}

private static Result<string> AtStringParse(string input)
{
if (input.Length < 3)
return Result.Fail<string>($"AtString literial length must > 3.");

var inner = input.Substring(2, input.Length - 3);
var escaped = inner.Replace("\"\"", "\"");
return Result.Ok(escaped);
}

public class Details
{
public static Result<char> GetEscapedChar(char ch)
{
if (ch == '\'')
{
return Result.Ok('"');
}
else if (ch == '"')
{
return Result.Ok('\'');
}
else
{
return Result.Fail<char>($"char {ch} not escappable.");
}
}

public static string EscapeNoCheck(string input, char escapeChar)
{
var unicodeRegex = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");

var result = input
.Replace(@"\\", @"\")
.Replace(@"\/", @"/")
.Replace(@"\t", "\t")
.Replace(@"\b", "\b")
.Replace(@"\f", "\f")
.Replace(@"\n", "\n")
.Replace(@"\r", "\r")
.Replace(@"\t", "\t")
.Replace($@"\{escapeChar}", escapeChar.ToString());

return unicodeRegex.Replace(result, match =>
((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
}
}
}
}
2 changes: 1 addition & 1 deletion sdmap/src/sdmap/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.8.1",
"version": "0.8.2",
"description": "A template engine for writing dynamic sql.",

"dependencies": {
Expand Down
16 changes: 0 additions & 16 deletions sdmap/test/sdmap.test/LexerTest/SimpleTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ namespace sdmap.test.LexerTest
{
public class SimpleTokenTest : LexerTestBase
{
[Fact]
public void String1()
{
var tokens = GetAllTokens("\"Test\"");
Assert.Equal(1, tokens.Count);
Assert.Equal(STRING, tokens[0].Type);
}

[Fact]
public void String2()
{
var tokens = GetAllTokens("'Test'");
Assert.Equal(1, tokens.Count);
Assert.Equal(STRING, tokens[0].Type);
}

[Fact]
public void Number()
{
Expand Down
46 changes: 46 additions & 0 deletions sdmap/test/sdmap.test/LexerTest/StringTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

using static sdmap.Parser.G4.SdmapLexer;

namespace sdmap.test.LexerTest
{
public class StringTest : LexerTestBase
{
[Fact]
public void String1()
{
var tokens = GetAllTokens("\"Test\"");
Assert.Equal(1, tokens.Count);
Assert.Equal(STRING, tokens[0].Type);
}

[Fact]
public void String2()
{
var tokens = GetAllTokens("'Test'");
Assert.Equal(1, tokens.Count);
Assert.Equal(STRING, tokens[0].Type);
}

[Fact]
public void EmptyStringIsOk()
{
var tokens = GetAllTokens("''");
Assert.Equal(1, tokens.Count);
Assert.Equal(STRING, tokens[0].Type);
}

[Fact]
public void AtString()
{
var tokens = GetAllTokens(@"@""Hel\/lo""");
Assert.Equal(1, tokens.Count);
Assert.Equal(STRING, tokens[0].Type);
Assert.Equal(@"@""Hel\/lo""", tokens[0].Text);
}
}
}
Loading

0 comments on commit b480c38

Please sign in to comment.