-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bd9334
commit 1925b6a
Showing
7 changed files
with
183 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Fluid.Ast | ||
{ | ||
public class NamedExpressionList | ||
{ | ||
public static readonly NamedExpressionList Empty = new NamedExpressionList(); | ||
|
||
private List<Expression> _positional; | ||
private Dictionary<string, Expression> _named; | ||
|
||
public int Count => _positional?.Count ?? 0; | ||
|
||
public bool HasNamed(string name) | ||
{ | ||
return _named != null && _named.ContainsKey(name); | ||
} | ||
|
||
public Expression this[int index] | ||
{ | ||
get | ||
{ | ||
if (_positional == null || index >= _positional.Count) | ||
{ | ||
return null; | ||
} | ||
|
||
return _positional[index]; | ||
} | ||
} | ||
|
||
public Expression this[string name] | ||
{ | ||
get | ||
{ | ||
if (_named != null && _named.TryGetValue(name, out var value)) | ||
{ | ||
return value; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public Expression this[string name, int index] | ||
{ | ||
get | ||
{ | ||
return this[name] ?? this[index]; | ||
} | ||
} | ||
|
||
public NamedExpressionList() | ||
{ | ||
} | ||
|
||
public NamedExpressionList(params Expression[] values) | ||
{ | ||
_positional = new List<Expression>(values); | ||
} | ||
|
||
public NamedExpressionList(List<FilterArgument> arguments) | ||
{ | ||
foreach (var argument in arguments) | ||
{ | ||
Add(argument.Name, argument.Expression); | ||
} | ||
} | ||
|
||
public NamedExpressionList Add(string name, Expression value) | ||
{ | ||
if (name != null) | ||
{ | ||
if (_named == null) | ||
{ | ||
_named = new Dictionary<string, Expression>(); | ||
} | ||
|
||
_named.Add(name, value); | ||
} | ||
|
||
if (_positional == null) | ||
{ | ||
_positional = new List<Expression>(); | ||
} | ||
|
||
_positional.Add(value); | ||
|
||
return this; | ||
} | ||
|
||
public IEnumerable<string> Names => _named?.Keys ?? System.Linq.Enumerable.Empty<string>(); | ||
|
||
public IEnumerable<Expression> Values => _positional; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Fluid.Ast; | ||
using System; | ||
using System.IO; | ||
using System.Text.Encodings.Web; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fluid.Parser | ||
{ | ||
internal sealed class ParserTagStatement<T> : Statement | ||
{ | ||
private readonly Func<T, TextWriter, TextEncoder, TemplateContext, ValueTask<Completion>> _render; | ||
|
||
public ParserTagStatement(T value, Func<T, TextWriter, TextEncoder, TemplateContext, ValueTask<Completion>> render) | ||
{ | ||
Value = value; | ||
_render = render ?? throw new ArgumentNullException(nameof(render)); | ||
} | ||
|
||
public T Value { get; } | ||
|
||
public override ValueTask<Completion> WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) | ||
{ | ||
return _render(Value, writer, encoder, context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters