diff --git a/.editorconfig b/.editorconfig
index 098f0142..d49be736 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -89,6 +89,9 @@ csharp_style_prefer_range_operator = false
dotnet_diagnostic.IDE1006.severity = silent
csharp_prefer_system_threading_lock = true:suggestion
+# IDE0078: Use pattern matching
+dotnet_diagnostic.IDE0078.severity = silent
+
[*.{cs,vb}]
#### Naming styles ####
diff --git a/Directory.Packages.props b/Directory.Packages.props
index d31ded29..cbb46506 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -16,7 +16,7 @@
-
+
diff --git a/Fluid.Benchmarks/FluidBenchmarks.cs b/Fluid.Benchmarks/FluidBenchmarks.cs
index 045f4904..c14c3103 100644
--- a/Fluid.Benchmarks/FluidBenchmarks.cs
+++ b/Fluid.Benchmarks/FluidBenchmarks.cs
@@ -1,13 +1,14 @@
-using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Attributes;
namespace Fluid.Benchmarks
{
- [MemoryDiagnoser, ShortRunJob]
+ [MemoryDiagnoser]
public class FluidBenchmarks : BaseBenchmarks
{
private readonly TemplateOptions _options = new TemplateOptions();
private readonly FluidParser _parser = new FluidParser();
private readonly IFluidTemplate _fluidTemplate;
+ private readonly FluidParser _compiledParser = new FluidParser().Compile();
public FluidBenchmarks()
{
@@ -28,6 +29,18 @@ public override object ParseBig()
return _parser.Parse(BlogPostTemplate);
}
+ [Benchmark]
+ public object ParseCompiled()
+ {
+ return _compiledParser.Parse(ProductTemplate);
+ }
+
+ [Benchmark]
+ public object ParseBigCompiled()
+ {
+ return _compiledParser.Parse(BlogPostTemplate);
+ }
+
[Benchmark]
public override string Render()
{
diff --git a/Fluid/FluidParser.cs b/Fluid/FluidParser.cs
index 2b00825c..46ac3267 100644
--- a/Fluid/FluidParser.cs
+++ b/Fluid/FluidParser.cs
@@ -4,7 +4,6 @@
using Fluid.Values;
using Parlot;
using Parlot.Fluent;
-using Parlot.Rewriting;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text.Encodings.Web;
@@ -52,8 +51,7 @@ public class FluidParser
protected readonly Parser> FunctionCallArgumentsList;
protected readonly Parser LogicalExpression;
protected readonly Parser CombinatoryExpression; // and | or
- protected readonly Parser Primary;
- protected readonly Deferred PrimaryInternal = Deferred();
+ protected readonly Deferred Primary = Deferred();
protected readonly Deferred FilterExpression = Deferred();
protected readonly Deferred> KnownTagsList = Deferred>();
protected readonly Deferred> AnyTagsList = Deferred>();
@@ -78,9 +76,6 @@ public FluidParser(FluidParserOptions parserOptions)
String.Name = "String";
Number.Name = "Number";
- // Build lookup for String/Member/Number/Range
- Primary = PrimaryInternal.Lookup((ISeekable)String, (ISeekable)new IdentifierParser(), (ISeekable)Number, (ISeekable)LParen);
-
var Integer = Terms.Integer().Then(x => new LiteralExpression(NumberValue.Create(x)));
Integer.Name = "Integer";
@@ -128,7 +123,7 @@ public FluidParser(FluidParserOptions parserOptions)
Range.Name = "Range";
// primary => NUMBER | STRING | property
- PrimaryInternal.Parser =
+ Primary.Parser =
String.Then(x => new LiteralExpression(StringValue.Create(x)))
.Or(Member.Then(static x =>
{