Skip to content

Commit 3dbc506

Browse files
authored
Merge pull request #35 from nblumhardt/intern-superpower
Intern the parts of Superpower used by this assembly
2 parents 8d57015 + 11b12a3 commit 3dbc506

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3073
-47
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,8 @@ var myFunctions = new StaticMemberNameResolver(typeof(MyFunctions));
370370
var expr = SerilogExpression.Compile("IsHello(User.Name)", new[] { myFunctions });
371371
// Filter events based on whether `User.Name` is `'Hello'` :-)
372372
```
373+
374+
## Acknowledgements
375+
376+
Includes the parser combinator implementation from [Superpower](https://github.com/datalust/superpower), copyright Datalust,
377+
Superpower Contributors, and Sprache Contributors; licensed under the Apache License, 2.0.

serilog-expressions.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<s:Boolean x:Key="/Default/UserDictionary/Words/=Existentials/@EntryIndexedValue">True</s:Boolean>
77
<s:Boolean x:Key="/Default/UserDictionary/Words/=formattable/@EntryIndexedValue">True</s:Boolean>
88
<s:Boolean x:Key="/Default/UserDictionary/Words/=nblumhardt/@EntryIndexedValue">True</s:Boolean>
9+
<s:Boolean x:Key="/Default/UserDictionary/Words/=ogham/@EntryIndexedValue">True</s:Boolean>
910
<s:Boolean x:Key="/Default/UserDictionary/Words/=Reorderable/@EntryIndexedValue">True</s:Boolean>
1011
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean>
1112
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subproperties/@EntryIndexedValue">True</s:Boolean>

src/Serilog.Expressions/Expressions/Ast/ConstantExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override string ToString()
2828
case IFormattable formattable:
2929
return formattable.ToString(null, CultureInfo.InvariantCulture);
3030
default:
31-
return (sv.Value ?? "null").ToString();
31+
return (sv.Value ?? "null").ToString() ?? "<ToString() returned null>";
3232
}
3333
}
3434

src/Serilog.Expressions/Expressions/Parsing/Combinators.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using Superpower;
3-
using Superpower.Model;
2+
using Serilog.ParserConstruction;
3+
using Serilog.ParserConstruction.Model;
44

55
namespace Serilog.Expressions.Parsing
66
{

src/Serilog.Expressions/Expressions/Parsing/ExpressionTextParsers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Superpower;
2-
using Superpower.Model;
3-
using Superpower.Parsers;
1+
using Serilog.ParserConstruction;
2+
using Serilog.ParserConstruction.Model;
3+
using Serilog.ParserConstruction.Parsers;
44

55
namespace Serilog.Expressions.Parsing
66
{
@@ -31,6 +31,6 @@ static class ExpressionTextParsers
3131
public static readonly TextParser<TextSpan> Real =
3232
Numerics.Integer
3333
.Then(n => Character.EqualTo('.').IgnoreThen(Numerics.Integer).OptionalOrDefault()
34-
.Select(f => f == TextSpan.None ? n : new TextSpan(n.Source, n.Position, n.Length + f.Length + 1)));
34+
.Select(f => f == TextSpan.None ? n : new TextSpan(n.Source!, n.Position, n.Length + f.Length + 1)));
3535
}
3636
}

src/Serilog.Expressions/Expressions/Parsing/ExpressionToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Superpower.Display;
1+
using Serilog.ParserConstruction.Display;
22

33
namespace Serilog.Expressions.Parsing
44
{

src/Serilog.Expressions/Expressions/Parsing/ExpressionTokenParsers.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Linq;
44
using Serilog.Events;
55
using Serilog.Expressions.Ast;
6-
using Superpower;
7-
using Superpower.Model;
8-
using Superpower.Parsers;
6+
using Serilog.ParserConstruction;
7+
using Serilog.ParserConstruction.Model;
8+
using Serilog.ParserConstruction.Parsers;
99

1010
namespace Serilog.Expressions.Parsing
1111
{
@@ -65,23 +65,23 @@ public static TokenListParserResult<ExpressionToken, Expression> TryPartialParse
6565

6666
static readonly TokenListParser<ExpressionToken, Func<Expression, Expression>> PropertyPathIndexerStep =
6767
from open in Token.EqualTo(ExpressionToken.LBracket)
68-
from indexer in Wildcard.Or(Parse.Ref(() => Expr))
68+
from indexer in Wildcard.Or(Parse.Ref(() => Expr!))
6969
from close in Token.EqualTo(ExpressionToken.RBracket)
7070
select new Func<Expression, Expression>(r => new IndexerExpression(r, indexer));
7171

7272
static readonly TokenListParser<ExpressionToken, Expression> Function =
7373
(from name in Token.EqualTo(ExpressionToken.Identifier)
7474
from lparen in Token.EqualTo(ExpressionToken.LParen)
75-
from expr in Parse.Ref(() => Expr).ManyDelimitedBy(Token.EqualTo(ExpressionToken.Comma))
75+
from expr in Parse.Ref(() => Expr!).ManyDelimitedBy(Token.EqualTo(ExpressionToken.Comma))
7676
from rparen in Token.EqualTo(ExpressionToken.RParen)
7777
from ci in Token.EqualTo(ExpressionToken.CI).Value(true).OptionalOrDefault()
7878
select (Expression)new CallExpression(ci, name.ToStringValue(), expr)).Named("function");
7979

8080
static readonly TokenListParser<ExpressionToken, Element> ArrayElement =
8181
Token.EqualTo(ExpressionToken.Spread)
82-
.IgnoreThen(Parse.Ref(() => Expr))
82+
.IgnoreThen(Parse.Ref(() => Expr!))
8383
.Select(content => (Element)new SpreadElement(content))
84-
.Or(Parse.Ref(() => Expr).Select(item => (Element) new ItemElement(item)));
84+
.Or(Parse.Ref(() => Expr!).Select(item => (Element) new ItemElement(item)));
8585

8686
static readonly TokenListParser<ExpressionToken, Expression> ArrayLiteral =
8787
(from lbracket in Token.EqualTo(ExpressionToken.LBracket)
@@ -92,7 +92,7 @@ from rbracket in Token.EqualTo(ExpressionToken.RBracket)
9292
static readonly TokenListParser<ExpressionToken, Member> IdentifierMember =
9393
from key in Token.EqualTo(ExpressionToken.Identifier).Or(Token.EqualTo(ExpressionToken.BuiltInIdentifier))
9494
from value in Token.EqualTo(ExpressionToken.Colon)
95-
.IgnoreThen(Parse.Ref(() => Expr))
95+
.IgnoreThen(Parse.Ref(() => Expr!))
9696
.Cast<ExpressionToken, Expression, Expression?>()
9797
.OptionalOrDefault()
9898
select (Member) new PropertyMember(
@@ -104,12 +104,12 @@ from value in Token.EqualTo(ExpressionToken.Colon)
104104
static readonly TokenListParser<ExpressionToken, Member> StringMember =
105105
from key in Token.EqualTo(ExpressionToken.String).Apply(ExpressionTextParsers.String)
106106
from colon in Token.EqualTo(ExpressionToken.Colon)
107-
from value in Parse.Ref(() => Expr)
107+
from value in Parse.Ref(() => Expr!)
108108
select (Member)new PropertyMember(key, value);
109109

110110
static readonly TokenListParser<ExpressionToken, Member> SpreadMember =
111111
from spread in Token.EqualTo(ExpressionToken.Spread)
112-
from content in Parse.Ref(() => Expr)
112+
from content in Parse.Ref(() => Expr!)
113113
select (Member) new SpreadMember(content);
114114

115115
static readonly TokenListParser<ExpressionToken, Member> ObjectMember =
@@ -146,11 +146,11 @@ from rbrace in Token.EqualTo(ExpressionToken.RBrace)
146146

147147
static readonly TokenListParser<ExpressionToken, Expression> Conditional =
148148
from _ in Token.EqualTo(ExpressionToken.If)
149-
from condition in Parse.Ref(() => Expr)
149+
from condition in Parse.Ref(() => Expr!)
150150
from __ in Token.EqualTo(ExpressionToken.Then)
151-
from consequent in Parse.Ref(() => Expr)
151+
from consequent in Parse.Ref(() => Expr!)
152152
from ___ in Token.EqualTo(ExpressionToken.Else)
153-
from alternative in Parse.Ref(() => Expr)
153+
from alternative in Parse.Ref(() => Expr!)
154154
select (Expression)new CallExpression(false, Operators.RuntimeOpIfThenElse, condition, consequent, alternative);
155155

156156
static readonly TokenListParser<ExpressionToken, Expression> Literal =
@@ -172,7 +172,7 @@ from alternative in Parse.Ref(() => Expr)
172172

173173
static readonly TokenListParser<ExpressionToken, Expression> Factor =
174174
(from lparen in Token.EqualTo(ExpressionToken.LParen)
175-
from expr in Parse.Ref(() => Expr)
175+
from expr in Parse.Ref(() => Expr!)
176176
from rparen in Token.EqualTo(ExpressionToken.RParen)
177177
select expr)
178178
.Or(Item);

src/Serilog.Expressions/Expressions/Parsing/ExpressionTokenizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Superpower;
4-
using Superpower.Model;
3+
using Serilog.ParserConstruction;
4+
using Serilog.ParserConstruction.Model;
55

66
namespace Serilog.Expressions.Parsing
77
{

src/Serilog.Expressions/Expressions/Parsing/ParserExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using Superpower;
3-
using Superpower.Model;
2+
using Serilog.ParserConstruction;
3+
using Serilog.ParserConstruction.Model;
44

55
namespace Serilog.Expressions.Parsing
66
{

src/Serilog.Expressions/Expressions/Runtime/Coerce.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static bool String(LogEventPropertyValue? value, [MaybeNullWhen(false)] o
6262

6363
if (sv.Value?.GetType().IsEnum ?? false)
6464
{
65-
str = sv.Value.ToString();
65+
str = sv.Value.ToString()!;
6666
return true;
6767
}
6868
}

src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,14 @@ public static LogEventPropertyValue _Internal_IsNotNull(LogEventPropertyValue? v
470470

471471
public static LogEventPropertyValue? ToString(LogEventPropertyValue? value, LogEventPropertyValue? format)
472472
{
473-
if (!(value is ScalarValue sv) ||
473+
if (value is not ScalarValue sv ||
474474
sv.Value == null ||
475-
!(Coerce.String(format, out var fmt) || format == null || format is ScalarValue { Value: null }))
475+
!(Coerce.String(format, out var fmt) || format is null or ScalarValue { Value: null }))
476476
{
477477
return null;
478478
}
479479

480-
string toString;
480+
string? toString;
481481
if (sv.Value is IFormattable formattable)
482482
{
483483
// TODO #19: formatting is culture-specific.

src/Serilog.Expressions/Expressions/StaticMemberNameResolver.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using System.Reflection;
56

@@ -27,9 +28,9 @@ public StaticMemberNameResolver(Type type)
2728
}
2829

2930
/// <inheritdoc />
30-
public override bool TryResolveFunctionName(string name, out MethodInfo implementation)
31+
public override bool TryResolveFunctionName(string name, [MaybeNullWhen(false)] out MethodInfo implementation)
3132
{
3233
return _methods.TryGetValue(name, out implementation);
3334
}
3435
}
35-
}
36+
}

0 commit comments

Comments
 (0)