Skip to content

Commit

Permalink
Merge pull request #18 from datalust/dev
Browse files Browse the repository at this point in the history
1.1.0 Release
  • Loading branch information
nblumhardt authored Nov 24, 2017
2 parents b773c75 + 179acef commit c3bf716
Show file tree
Hide file tree
Showing 23 changed files with 370 additions and 246 deletions.
8 changes: 6 additions & 2 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ echo "build: Version suffix is $suffix"
foreach ($src in ls src/*) {
Push-Location $src

echo "build: Packaging project in $src"
echo "build: Packaging project in $src"

& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
if ($suffix) {
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --include-source
} else {
& dotnet pack -c Release -o ..\..\artifacts --include-source
}
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
Expand Down
29 changes: 19 additions & 10 deletions Superpower.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AC295EEA-D319-4146-97E0-B978DF6F2557}"
EndProject
Expand All @@ -10,13 +10,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{66B005
appveyor.yml = appveyor.yml
Benchmark.ps1 = Benchmark.ps1
Build.ps1 = Build.ps1
global.json = global.json
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Superpower", "src\Superpower\Superpower.xproj", "{D4E037DE-9778-4E48-A4A7-E8C1751E637C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2ED926D3-7AC8-4BFD-A16B-74D942602968}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "asset", "asset", "{69238E6E-26AB-494B-8CBD-65F8C1F0696A}"
Expand All @@ -26,10 +23,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "asset", "asset", "{69238E6E
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{7533E145-1C93-4348-A70D-E68746C5438C}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Superpower.Tests", "test\Superpower.Tests\Superpower.Tests.xproj", "{CD473266-4AED-4207-89FD-0B185239F1C7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Superpower.Benchmarks", "test\Superpower.Benchmarks\Superpower.Benchmarks.xproj", "{1A9C8D7E-4DFC-48CD-99B0-63612197E95F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "results", "results", "{D8D9BA69-4FD8-4F31-9ECC-227D85733D15}"
ProjectSection(SolutionItems) = preProject
results\ArithmeticExpressionBenchmark-report-github.md = results\ArithmeticExpressionBenchmark-report-github.md
Expand All @@ -40,7 +33,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "results", "results", "{D8D9
results\NumberListBenchmark-report.html = results\NumberListBenchmark-report.html
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IntCalc", "sample\IntCalc\IntCalc.xproj", "{34BBD428-8297-484E-B771-0B72C172C264}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Superpower", "src\Superpower\Superpower.csproj", "{D4E037DE-9778-4E48-A4A7-E8C1751E637C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Superpower.Tests", "test\Superpower.Tests\Superpower.Tests.csproj", "{CD473266-4AED-4207-89FD-0B185239F1C7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Superpower.Benchmarks", "test\Superpower.Benchmarks\Superpower.Benchmarks.csproj", "{1A9C8D7E-4DFC-48CD-99B0-63612197E95F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntCalc", "sample\IntCalc\IntCalc.csproj", "{34BBD428-8297-484E-B771-0B72C172C264}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DateTimeParser", "sample\DateTimeTextParser\DateTimeParser.csproj", "{A842DA99-4EAB-423D-B532-7902FED0D8F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -64,6 +65,10 @@ Global
{34BBD428-8297-484E-B771-0B72C172C264}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34BBD428-8297-484E-B771-0B72C172C264}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34BBD428-8297-484E-B771-0B72C172C264}.Release|Any CPU.Build.0 = Release|Any CPU
{A842DA99-4EAB-423D-B532-7902FED0D8F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A842DA99-4EAB-423D-B532-7902FED0D8F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A842DA99-4EAB-423D-B532-7902FED0D8F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A842DA99-4EAB-423D-B532-7902FED0D8F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -73,5 +78,9 @@ Global
{CD473266-4AED-4207-89FD-0B185239F1C7} = {2ED926D3-7AC8-4BFD-A16B-74D942602968}
{1A9C8D7E-4DFC-48CD-99B0-63612197E95F} = {2ED926D3-7AC8-4BFD-A16B-74D942602968}
{34BBD428-8297-484E-B771-0B72C172C264} = {7533E145-1C93-4348-A70D-E68746C5438C}
{A842DA99-4EAB-423D-B532-7902FED0D8F1} = {7533E145-1C93-4348-A70D-E68746C5438C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F3941419-6499-4871-BEAA-861F4FE5D2D4}
EndGlobalSection
EndGlobal
10 changes: 2 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2015
image: Visual Studio 2017
configuration: Release
install:
- ps: mkdir -Force ".\build\" | Out-Null
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121'
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
build_script:
- ps: ./Build.ps1
test: off
Expand All @@ -16,7 +10,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: 7AS4wbHVs08D6so0JGAVczexCX9ST6CRbNToHZC08rtPqkQENpyNhhSAIX0FShzh
secure: 2APsxl7cOn94Y5lvJ0LshnVGefMpKu/JUG6IiM6BK9UWq1bN0Zv4X4OBXzkMPFm0
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand Down
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

9 changes: 9 additions & 0 deletions sample/DateTimeTextParser/DateTimeParser.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Superpower\Superpower.csproj" />
</ItemGroup>
</Project>
82 changes: 82 additions & 0 deletions sample/DateTimeTextParser/DateTimeTextParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using Superpower;
using Superpower.Model;
using Superpower.Parsers;

namespace DateTimeTextParser
{
static public class DateTimeTextParser
{
static TextParser<char[]> Repeat(this TextParser<char> parser, int count)
{
return input =>
{
List<char> result = new List<char>();

Result<char> next = input.ConsumeChar();
var beginning = next.Location;

for (int i = 0; i < count; i++)
{
var parserResult = parser.Invoke(next.Location);
if (parserResult.HasValue)
{
result.Add(parserResult.Value);
next = next.Remainder.ConsumeChar();
}
else
return Result.Empty<char[]>(input);
}

return Result.Value(result.ToArray(), beginning, next.Location);
};
}


static TextParser<string> TwoDigits =
Character.Digit.Repeat(2).Select(chs => new String(chs));

static TextParser<string> YearOfDate =
Character.Digit.Repeat(4).Select(chs => new String(chs));

static TextParser<string> MonthOfDate =
TwoDigits;

static TextParser<string> DayOfDate =
TwoDigits;

static TextParser<DateTime> Date =
from year in YearOfDate.Select(Int32.Parse)
from sep1 in Character.EqualTo('-')
from mon in MonthOfDate.Select(Int32.Parse)
from sep2 in Character.EqualTo('-')
from day in DayOfDate.Select(Int32.Parse)
select new DateTime(year, mon, day);

static TextParser<int> secondWithSep =
from sep in Character.EqualTo(':')
from second in TwoDigits.Select(Int32.Parse)
select second;

static TextParser<TimeSpan> Time =
from hour in TwoDigits.Select(Int32.Parse)
from sep1 in Character.EqualTo(':')
from minute in TwoDigits.Select(Int32.Parse)
from second in secondWithSep.OptionalOrDefault()
select new TimeSpan(hour, minute, second);

public static TextParser<DateTime> DateTime =
from q1 in Character.EqualTo('"').Optional()
from date in (from date in Date
from s in Character.In('T', ' ')
from time in Time
select date + time).Try()
.Or(from time in Time
select System.DateTime.Now.Date + time).Try()
.Or(Date)
from q2 in Character.EqualTo('"').Optional().AtEnd()
where (q1 == null && q2 == null) || (q1 != null && q2 != null)
select date;
}
}
38 changes: 38 additions & 0 deletions sample/DateTimeTextParser/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Superpower;

namespace DateTimeTextParser
{
class Program
{
static void ParseAndPrint(string input)
{
try
{
var dt = DateTimeTextParser.DateTime.Parse(input);
Console.WriteLine("Input: '{0}', ParsedValue: '{1}'", input, dt.ToString("o"));
}
catch (System.Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Input: '{0}'", input);
Console.WriteLine(ex.ToString());
Console.ForegroundColor = ConsoleColor.White;
}
}

static void Main(string[] args)
{
ParseAndPrint("12:38");
ParseAndPrint("12:38:10");
ParseAndPrint("2017-01-01");
ParseAndPrint("2017-01-01 05:28:10");
ParseAndPrint("2017-01-01 05:28");
ParseAndPrint("\"2017-01-01\"");
ParseAndPrint("\"2017-01-01");
ParseAndPrint("2017-01-01 05:x8:10");
ParseAndPrint("2017-01-01T05:28:10");
ParseAndPrint("2017-01-01T05:28");
}
}
}
58 changes: 58 additions & 0 deletions sample/DateTimeTextParser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Superpower sample / `DateTimeTextParser`

This example should shows how to build a simple text parser with Superpower.
It uses a simple and well known requirement: parsing date and time values
according to ISO-8601 format.

## The requirement

In a simple, custom query language a user enters multiple conditions where a
property is compared to a static value. The property identifier the
comparison operator and the static value had to be separated with spaces.
There are text properties and datetime properties to query.

The static text values had to be entered enclosed with `'"'` (double qoutes),
datetime static values can be entered as date, time or date and time. For
better usability not only text can be enclosed with `'"'`, also the date time
static values can be surrounded with double qoutes. When only time is entered
it should be considered as todays time. When only date is entered midnight is
the default time value.

For example:
- `2017-01-01 12:10`
- `"2017-01-01 12:10"`
- `12:10`
- `2017-01-01`

## The code

The `DateTimeTextParser` class contains the `DateTime` Superpower `TextParser`, which
covers all the requirements to parse a static datetime value.

```cs
public static TextParser<DateTime> DateTime =
from q1 in Character.EqualTo('"').Optional()
// ^- First we looking for a optional double quote
from date in (from date in Date
from s in Character.In('T', ' ')
from time in Time
select date + time).Try()
// ^- here we're looking for date and time values
.Or(from time in Time
select System.DateTime.Now.Date + time).Try()
// ^- when the first parser failed check for time only
// and add it to the current date
.Or(Date)
// ^- else it must be a date value
from q2 in Character.EqualTo('"').Optional().AtEnd()
// ^- then we check for a optional double quote at the end of the input
where (q1 == null && q2 == null) || (q1 != null && q2 != null)
// ^- now we're checking if both quote are either set or not set
select date;
```
24 changes: 24 additions & 0 deletions sample/IntCalc/IntCalc.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks>
<AssemblyName>IntCalc</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>IntCalc</PackageId>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Superpower\Superpower.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>
21 changes: 0 additions & 21 deletions sample/IntCalc/IntCalc.xproj

This file was deleted.

26 changes: 0 additions & 26 deletions sample/IntCalc/project.json

This file was deleted.

Loading

0 comments on commit c3bf716

Please sign in to comment.