Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0 Release #135

Merged
merged 33 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9cea8d6
Dev version bump [skip ci]
nblumhardt May 31, 2019
9c0f4d7
Add the seqcli extraction pattern example [skip ci]
nblumhardt Jun 2, 2019
a9637c4
Optimized Parse.Sequence(...) combinator
nblumhardt Jun 12, 2019
ad53375
Fix the JSON parser sample to allow strings ending in '\'.
fvbommel Jul 5, 2020
5d203c3
Merge pull request #115 from fvbommel/fix-json-string-tokenizer
nblumhardt Jul 6, 2020
a9922d0
Update NuGet.org key
nblumhardt Aug 19, 2020
ed5e4c0
Update build image
nblumhardt Aug 19, 2020
f04deea
Merge pull request #94 from nblumhardt/sequence
nblumhardt Dec 2, 2020
61d1429
Update tooling; add a net5.0 target
nblumhardt Dec 2, 2020
8043b23
Fix icon path
nblumhardt Dec 2, 2020
3b6c6ae
Merge pull request #122 from nblumhardt/tooling-updates
nblumhardt Dec 2, 2020
5cd01c4
added OneOf combinator and tests
AndrewSav Dec 4, 2020
3042a6b
Merge pull request #123 from AndrewSav/dev
nblumhardt Dec 7, 2020
cefcdd7
Demo had typo in code
Spaceman1861 Jan 30, 2021
886c160
Merge pull request #127 from Spaceman1861/patch-1
nblumhardt Feb 1, 2021
25e0b74
Added Span.Until to Superpower.Parsers
Ellested Feb 21, 2021
5de1fc8
Span.Until improvements according to PR comments
Ellested Mar 8, 2021
86fa1d1
Fixed calculation of the found position. The input position was never…
Ellested Mar 20, 2021
5f48738
Renamed Until to Except and removed the fail options. Span.Except sho…
Ellested Apr 10, 2021
21f53b2
Merge branch 'Ellested-dev' into dev
nblumhardt Apr 13, 2021
a20c9d4
Disallow zero-length matches in Span.Except(), use string.IndexOf(), …
nblumhardt Apr 13, 2021
2e86e70
Initial cut of <Nullable>enable</Nullable>
nblumhardt Dec 24, 2020
56be7fd
Fix nullability check in new code
nblumhardt Apr 13, 2021
0ced28c
Merge branch 'nblumhardt-nullable' into dev
nblumhardt Apr 13, 2021
aeeb2b2
Fix build - paper over some holes in the #nullable story; enable C# 9.0
nblumhardt Apr 13, 2021
4020695
Added optional error message to the Where combinator
AndrewSav Apr 13, 2021
4d1db1e
Add Matching method to Token class to support non-enum Tokens
AndrewSav Apr 13, 2021
97acd62
Merge pull request #132 from AndrewSav/matching
nblumhardt Apr 13, 2021
68c0b64
Added tests for Where combinator
AndrewSav Apr 14, 2021
09a8b92
Added a null check for the new `message` parameter of the Where combi…
AndrewSav Apr 14, 2021
9be4ea0
Merge pull request #131 from AndrewSav/where-message
nblumhardt Apr 14, 2021
e707659
Build from main
nblumhardt May 13, 2021
2598a4c
Publish from main
nblumhardt May 13, 2021
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
2 changes: 1 addition & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if(Test-Path .\artifacts) {

$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]

echo "build: Version suffix is $suffix"

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var expression = "1 * (2 + 3)";

// 1.
var tokenizer = new ArithmeticExpressionTokenizer();
var tokenList = tokenizer.Tokenize(expresssion);
var tokenList = tokenizer.Tokenize(expression);

// 2.
var parser = ArithmeticExpressionParser.Lambda; // parser built with combinators
Expand Down Expand Up @@ -245,7 +245,8 @@ Superpower is introduced, with a worked example, in [this blog post](https://nbl
**Real-world** projects built with Superpower:

* [_Serilog.Filters.Expressions_](https://github.com/serilog/serilog-filters-expressions) uses Superpower to implement a filtering language for structured log events
* The query language of [Seq](https://getseq.net) is implemented using Superpower
* The query language of [Seq](https://datalust.co/seq) is implemented using Superpower
* `seqcli` [extraction patterns](https://github.com/datalust/seqcli#extraction-patterns) use Superpower for plain-text log parsing

_Have an example we can add to this list? [Let us know](https://github.com/datalust/superpower/issues/new)._

Expand Down
5 changes: 5 additions & 0 deletions Superpower.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{66B005
Build.ps1 = Build.ps1
LICENSE = LICENSE
README.md = README.md
global.json = global.json
EndProjectSection
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}"
ProjectSection(SolutionItems) = preProject
asset\Superpower.snk = asset\Superpower.snk
asset\Superpower.svg = asset\Superpower.svg
asset\Superpower-Transparent-400px.png = asset\Superpower-Transparent-400px.png
asset\Superpower-White-200px.png = asset\Superpower-White-200px.png
asset\Superpower-White-400px.png = asset\Superpower-White-400px.png
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{7533E145-1C93-4348-A70D-E68746C5438C}"
Expand Down
2 changes: 2 additions & 0 deletions Superpower.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=allocs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=errloc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=expsign/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=frac/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lparen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Numerics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=opvalue/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rparen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sprache/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stopword/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tokenized/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tokenizers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
9 changes: 4 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2017
configuration: Release
image: Visual Studio 2019
build_script:
- ps: ./Build.ps1
test: off
Expand All @@ -10,14 +9,14 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: Xi+qouQ6+cOJ85PMOQKEGy+MC1EKyYJCoF2YfuE9Rcj6lvNtm08TIZllTJCqId+M
secure: h13+FoLtFJdwNtYdIUsr0xJZCtxwTBKsFKCp5jFjyx5DxqeZN4MwWZhgL+enTOJq
skip_symbols: true
on:
branch: /^(master|dev)$/
branch: /^(main|dev)$/
- provider: GitHub
auth_token:
secure: hX+cZmW+9BCXy7vyH8myWsYdtQHyzzil9K5yvjJv7dK9XmyrGYYDj/DPzMqsXSjo
artifact: /Superpower.*\.nupkg/
tag: v$(appveyor_build_version)
on:
branch: master
branch: main
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "5.0.100",
"rollForward": "latestFeature"
}
}
6 changes: 5 additions & 1 deletion sample/DateTimeTextParser/DateTimeParser.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
2 changes: 1 addition & 1 deletion sample/IntCalc/ArithmeticExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static TokenListParser<ArithmeticExpressionToken, ExpressionType> Operator(Arith

static readonly TokenListParser<ArithmeticExpressionToken, Expression> Factor =
(from lparen in Token.EqualTo(ArithmeticExpressionToken.LParen)
from expr in Parse.Ref(() => Expr)
from expr in Parse.Ref(() => Expr!)
from rparen in Token.EqualTo(ArithmeticExpressionToken.RParen)
select expr)
.Or(Constant);
Expand Down
26 changes: 5 additions & 21 deletions sample/IntCalc/IntCalc.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>


<PropertyGroup>
<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>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

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

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


</Project>
19 changes: 0 additions & 19 deletions sample/IntCalc/Properties/AssemblyInfo.cs

This file was deleted.

3 changes: 2 additions & 1 deletion sample/JsonParser/JsonParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
31 changes: 16 additions & 15 deletions sample/JsonParser/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Superpower;
using Superpower.Display;
using Superpower.Model;
Expand Down Expand Up @@ -99,7 +100,7 @@ static class JsonTokenizer
// drops the items that it matches.
static TextParser<Unit> JsonStringToken { get; } =
from open in Character.EqualTo('"')
from content in Span.EqualTo("\\\"").Value(Unit.Value).Try()
from content in Character.EqualTo('\\').IgnoreThen(Character.AnyChar).Value(Unit.Value).Try()
.Or(Character.Except('"').Value(Unit.Value))
.IgnoreMany()
from close in Character.EqualTo('"')
Expand Down Expand Up @@ -257,7 +258,7 @@ from begin in Token.EqualTo(JsonToken.LBracket)
from properties in JsonString
.Named("property name")
.Then(name => Token.EqualTo(JsonToken.Colon)
.IgnoreThen(Parse.Ref(() => JsonValue)
.IgnoreThen(Parse.Ref(() => JsonValue!)
.Select(value => KeyValuePair.Create((string)name, value))))
.ManyDelimitedBy(Token.EqualTo(JsonToken.Comma),
end: Token.EqualTo(JsonToken.RBracket))
Expand All @@ -268,7 +269,7 @@ from properties in JsonString
// expectations like "expected (item) or (close delimiter)" when no content matches.
static TokenListParser<JsonToken, object> JsonArray { get; } =
from begin in Token.EqualTo(JsonToken.LSquareBracket)
from values in Parse.Ref(() => JsonValue)
from values in Parse.Ref(() => JsonValue!)
.ManyDelimitedBy(Token.EqualTo(JsonToken.Comma),
end: Token.EqualTo(JsonToken.RSquareBracket))
select (object)values;
Expand All @@ -279,26 +280,26 @@ from values in Parse.Ref(() => JsonValue)
static TokenListParser<JsonToken, object> JsonFalse { get; } =
Token.EqualToValue(JsonToken.Identifier, "false").Value((object)false);

static TokenListParser<JsonToken, object> JsonNull { get; } =
Token.EqualToValue(JsonToken.Identifier, "null").Value((object)null);
static TokenListParser<JsonToken, object?> JsonNull { get; } =
Token.EqualToValue(JsonToken.Identifier, "null").Value((object?)null);

static TokenListParser<JsonToken, object> JsonValue { get; } =
JsonString
.Or(JsonNumber)
.Or(JsonObject)
.Or(JsonArray)
.Or(JsonTrue)
.Or(JsonFalse)
static TokenListParser<JsonToken, object?> JsonValue { get; } =
JsonString.AsNullable()
.Or(JsonNumber.AsNullable())
.Or(JsonObject.AsNullable())
.Or(JsonArray.AsNullable())
.Or(JsonTrue.AsNullable())
.Or(JsonFalse.AsNullable())
.Or(JsonNull)
.Named("JSON value");

static TokenListParser<JsonToken, object> JsonDocument { get; } = JsonValue.AtEnd();
static TokenListParser<JsonToken, object?> JsonDocument { get; } = JsonValue.AtEnd();

// `TryParse` is just a helper method. It's useful to write one of these, where
// the tokenization and parsing phases remain distinct, because it's often very
// handy to place a breakpoint between the two steps to check out what the
// token list looks like.
public static bool TryParse(string json, out object value, out string error, out Position errorPosition)
public static bool TryParse(string json, out object? value, [MaybeNullWhen(true)] out string error, out Position errorPosition)
{
var tokens = JsonTokenizer.Instance.TryTokenize(json);
if (!tokens.HasValue)
Expand Down Expand Up @@ -357,7 +358,7 @@ static void Main()
}
}

static void Print(object value, int indent = 0)
static void Print(object? value, int indent = 0)
{
switch (value)
{
Expand Down
Loading