Skip to content

Commit 69a1750

Browse files
authored
Merge pull request #160 from datalust/dev
3.1.0 Release
2 parents accd8f0 + 14f8ea3 commit 69a1750

File tree

15 files changed

+140
-23
lines changed

15 files changed

+140
-23
lines changed

Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(Test-Path .\artifacts) {
1313

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

1818
echo "build: Version suffix is $suffix"
1919

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Superpower [![Build status](https://ci.appveyor.com/api/projects/status/7bj6if6tyc68urpy?svg=true)](https://ci.appveyor.com/project/datalust/superpower) [![Join the chat at https://gitter.im/datalust/superpower](https://img.shields.io/gitter/room/datalust/superpower.svg)](https://gitter.im/datalust/superpower) [![NuGet Version](https://img.shields.io/nuget/vpre/Superpower.svg?style=flat)](https://www.nuget.org/packages/Superpower/) [![Stack Overflow](https://img.shields.io/badge/stackoverflow-superpower-orange.svg)](http://stackoverflow.com/questions/tagged/superpower)
1+
# Superpower [![Build status](https://ci.appveyor.com/api/projects/status/7bj6if6tyc68urpy?svg=true)](https://ci.appveyor.com/project/datalust/superpower) [![NuGet Version](https://img.shields.io/nuget/vpre/Superpower.svg?style=flat)](https://www.nuget.org/packages/Superpower/) [![Stack Overflow](https://img.shields.io/badge/stackoverflow-superpower-orange.svg)](http://stackoverflow.com/questions/tagged/superpower)
22

33
A [parser combinator](https://en.wikipedia.org/wiki/Parser_combinator) library based on
44
[Sprache](https://github.com/sprache/Sprache). Superpower generates friendlier error messages through its support for
@@ -71,7 +71,7 @@ public enum ArithmeticExpressionToken
7171
```
7272

7373
A major benefit of driving parsing from tokens, instead of individual characters, is that errors can be reported in
74-
terms of tokens - _unexpected identifier \`frm\`, expected keyword \`from\`_ - instead of the cryptic _unexpected `m`_.
74+
terms of tokens - _unexpected identifier \`frm\`, expected keyword \`from\`_ - instead of the cryptic _unexpected \`m\`_.
7575

7676
Token-driven parsing takes place in two distinct steps:
7777

@@ -170,8 +170,8 @@ class ArithmeticExpressionParser
170170
static readonly TokenListParser<ArithmeticExpressionToken, Expression> Expr =
171171
Parse.Chain(Add.Or(Subtract), Term, Expression.MakeBinary);
172172

173-
public static readonly TokenListParser<ArithmeticExpressionToken, Expression<Func<int>>> Lambda =
174-
Expr.AtEnd().Select(body => Expression.Lambda<Func<int>>(body));
173+
public static readonly TokenListParser<ArithmeticExpressionToken, Expression<Func<int>>>
174+
Lambda = Expr.AtEnd().Select(body => Expression.Lambda<Func<int>>(body));
175175
}
176176
```
177177

@@ -244,14 +244,15 @@ Superpower is introduced, with a worked example, in [this blog post](https://nbl
244244
245245
**Real-world** projects built with Superpower:
246246

247-
* [_Serilog.Filters.Expressions_](https://github.com/serilog/serilog-filters-expressions) uses Superpower to implement a filtering language for structured log events
247+
* [_Serilog.Expressions_](https://github.com/serilog/serilog-expressions) uses Superpower to implement an expression and templating language for structured log events
248248
* The query language of [Seq](https://datalust.co/seq) is implemented using Superpower
249249
* `seqcli` [extraction patterns](https://github.com/datalust/seqcli#extraction-patterns) use Superpower for plain-text log parsing
250+
* [_PromQL.Parser_](https://github.com/djluck/PromQL.Parser) is a parser for the Prometheus Query Language
250251
251252
_Have an example we can add to this list? [Let us know](https://github.com/datalust/superpower/issues/new)._
252253
253254
### Getting help
254255

255-
Please post issues [to the issue tracker](https://github.com/datalust/superpower/issues), visit our [Gitter chat](https://gitter.im/datalust/superpower), or tag your [question on StackOverflow](http://stackoverflow.com/questions/tagged/superpower) with `superpower`.
256+
Please post issues [to the issue tracker](https://github.com/datalust/superpower/issues), or tag your [question on StackOverflow](http://stackoverflow.com/questions/tagged/superpower) with `superpower`.
256257
257258
_The repository's title arose out of a talk_ "Parsing Text: the Programming Superpower You Need at Your Fingertips" _given at [DDD Brisbane](http://dddbrisbane.com/) 2015._

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2019
3+
image: Visual Studio 2022
44
build_script:
55
- ps: ./Build.ps1
66
test: off
@@ -9,7 +9,7 @@ artifacts:
99
deploy:
1010
- provider: NuGet
1111
api_key:
12-
secure: YSrfzuVFe7i8NCMaPan+MN6TJ3nSU7vUG5jsXwy1gvvPtFQvPkYSdfYK8bCuftgE
12+
secure: wW4TJY85P9BSN53XNfB0IE2WqskPu0RdsWelB1tQco1wql3g8ov5yhmk5v8dXy81
1313
skip_symbols: true
1414
on:
1515
branch: /^(main|dev)$/

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "5.0.100",
3+
"version": "8.0.300",
44
"rollForward": "latestFeature"
55
}
66
}

sample/DateTimeTextParser/DateTimeParser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

sample/IntCalc/ArithmeticExpressionToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum ArithmeticExpressionToken
1818
[Token(Category = "operator", Example = "*")]
1919
Times,
2020

21-
[Token(Category = "operator", Example = "-")]
21+
[Token(Category = "operator", Example = "/")]
2222
Divide,
2323

2424
[Token(Example = "(")]

sample/IntCalc/IntCalc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

sample/JsonParser/JsonParser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

src/Superpower/Combinators.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static TokenListParser<TKind, T[]> Repeat<TKind, T>(this TokenListParser<
224224
remainder = r.Remainder;
225225
}
226226

227-
return TokenListParserResult.Value(result ?? new T[0], input, remainder);
227+
return TokenListParserResult.Value(result ?? Array.Empty<T>(), input, remainder);
228228
};
229229
}
230230

@@ -257,7 +257,7 @@ public static TextParser<T[]> Repeat<T>(this TextParser<T> parser, int count)
257257
remainder = r.Remainder;
258258
}
259259

260-
return Result.Value(result ?? new T[0], input, remainder);
260+
return Result.Value(result ?? Array.Empty<T>(), input, remainder);
261261
};
262262
}
263263

@@ -507,11 +507,11 @@ public static TokenListParser<TKind, T[]> ManyDelimitedBy<TKind, T, U>(
507507
return parser
508508
.AtLeastOnceDelimitedBy(delimiter)
509509
.Then(p => end.Value(p))
510-
.Or(end.Value(new T[0]));
510+
.Or(end.Value(Array.Empty<T>()));
511511

512512
return parser
513513
.Then(first => delimiter.IgnoreThen(parser).Many().Select(rest => ArrayEnumerable.Cons(first, rest)))
514-
.OptionalOrDefault(new T[0]);
514+
.OptionalOrDefault(Array.Empty<T>());
515515
}
516516

517517
/// <summary>
@@ -528,9 +528,25 @@ public static TextParser<T[]> ManyDelimitedBy<T, U>(this TextParser<T> parser, T
528528
if (delimiter == null) throw new ArgumentNullException(nameof(delimiter));
529529

530530
return parser.Then(first => delimiter.IgnoreThen(parser).Many().Select(rest => ArrayEnumerable.Cons(first, rest)))
531-
.OptionalOrDefault(new T[0]);
531+
.OptionalOrDefault(Array.Empty<T>());
532532
}
533533

534+
/// <summary>
535+
/// Constructs a parser that converts a char[]-parser to a string-parser.
536+
/// </summary>
537+
/// <param name="parser">The parser.</param>
538+
/// <returns>The resulting parser.</returns>
539+
public static TextParser<string> Text(this TextParser<char[]> parser)
540+
=> parser.Select(chars => new string(chars));
541+
542+
/// <summary>
543+
/// Constructs a parser that converts a TextSpan-parser to a string-parser.
544+
/// </summary>
545+
/// <param name="parser">The parser.</param>
546+
/// <returns>The resulting parser.</returns>
547+
public static TextParser<string> Text(this TextParser<TextSpan> parser)
548+
=> parser.Select(textSpan => textSpan.ToStringValue());
549+
534550
/// <summary>
535551
/// Construct a parser that fails with error message <paramref name="errorMessage"/> when <paramref name="parser"/> fails.
536552
/// </summary>

src/Superpower/Model/TextSpan.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,52 @@ public bool EqualsValueIgnoreCase(string otherValue)
270270
}
271271
return true;
272272
}
273+
274+
/// <summary>
275+
/// Gets the character at the specified index in the text span.
276+
/// </summary>
277+
/// <param name="index">
278+
/// The zero-based index of the character to get.
279+
/// </param>
280+
/// <returns>
281+
/// The character at the specified index in the text span.
282+
/// </returns>
283+
public char this[int index]
284+
{
285+
get
286+
{
287+
this.EnsureHasValue();
288+
#if CHECKED
289+
if ((uint)index >= (uint)Length)
290+
throw new ArgumentOutOfRangeException(nameof(index), index, "Index exceeds the source span's length.");
291+
#endif
292+
return Source![Position.Absolute + index];
293+
}
294+
}
295+
296+
/// <summary>
297+
/// Forms a slice out of the current text span starting at the specified index.
298+
/// </summary>
299+
/// <param name="index">
300+
/// The index at which to begin the slice.
301+
/// </param>
302+
/// <returns>
303+
/// An text span that consists of all elements of the current array segment from <paramref name="index"/> to the end of the text span.
304+
/// </returns>
305+
public TextSpan Slice(int index)
306+
{
307+
return Skip(index);
308+
}
309+
310+
/// <summary>
311+
/// Forms a slice of the specified length out of the current text span starting at the specified index.
312+
/// </summary>
313+
/// <param name="index">The index at which to begin the slice.</param>
314+
/// <param name="count">The desired length of the slice.</param>
315+
/// <returns>An text span of <paramref name="count"/> elements starting at <paramref name="index"/>.</returns>
316+
public TextSpan Slice(int index, int count)
317+
{
318+
return Skip(index).First(count);
319+
}
273320
}
274321
}

0 commit comments

Comments
 (0)