11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Threading . Tasks ;
35using ExpressionEngine . Functions . Base ;
46using ExpressionEngine . Rules ;
57using Sprache ;
@@ -9,7 +11,7 @@ namespace ExpressionEngine
911 public class ExpressionGrammar
1012 {
1113 private readonly Parser < IRule > _method ;
12- private readonly Parser < ValueContainer > _input ;
14+ private readonly Parser < ValueTask < ValueContainer > > _input ;
1315
1416 public ExpressionGrammar ( IEnumerable < IFunction > functions )
1517 {
@@ -93,15 +95,15 @@ from args in arguments.Contained(lParenthesis, rParenthesis)
9395 Parse . Ref ( ( ) =>
9496 from func in function
9597 from indexes in bracketIndices . Or ( dotIndices ) . Many ( )
96- select ( IRule ) new AccessValueRule ( func , indexes ) ) ;
98+ select indexes . Aggregate ( func , ( acc , next ) => new AccessValueRule ( acc , next ) ) ) ;
9799
98- Parser < ValueContainer > enclosedExpression =
100+ Parser < ValueTask < ValueContainer > > enclosedExpression =
99101 _method . Contained (
100102 Parse . String ( "@{" ) ,
101103 Parse . Char ( '}' ) )
102104 . Select ( x => x . Evaluate ( ) ) ;
103105
104- Parser < ValueContainer > expression =
106+ Parser < ValueTask < ValueContainer > > expression =
105107 from at in Parse . Char ( '@' )
106108 from method in _method
107109 select method . Evaluate ( ) ;
@@ -110,32 +112,32 @@ from method in _method
110112 from t in simpleString . Or ( allowedCharacters ) . Many ( )
111113 select string . Concat ( t ) ;
112114
113- Parser < ValueContainer > joinedString =
115+ Parser < ValueTask < ValueContainer > > joinedString =
114116 from e in (
115117 from preFix in allowedString
116118 from exp in enclosedExpression . Optional ( )
117119 select exp . IsEmpty ? preFix : preFix + exp . Get ( ) )
118120 . Many ( )
119- select new ValueContainer ( string . Concat ( e ) ) ;
121+ select new ValueTask < ValueContainer > ( new ValueContainer ( string . Concat ( e ) ) ) ;
120122
121- Parser < ValueContainer > charPrefixedString =
123+ Parser < ValueTask < ValueContainer > > charPrefixedString =
122124 from at in Parse . Char ( '@' )
123125 from str in Parse . LetterOrDigit . Many ( ) . Text ( ) . Except ( Parse . Chars ( '{' , '@' ) )
124- select new ValueContainer ( str ) ;
126+ select new ValueTask < ValueContainer > ( new ValueContainer ( str ) ) ;
125127
126128 _input = expression . Or ( charPrefixedString ) . Or ( joinedString ) ;
127129 }
128130
129- public string EvaluateToString ( string input )
131+ public async ValueTask < string > EvaluateToString ( string input )
130132 {
131- var output = _input . Parse ( input ) ;
133+ var output = await _input . Parse ( input ) ;
132134
133135 return output . GetValue < string > ( ) ;
134136 }
135137
136- public ValueContainer EvaluateToValueContainer ( string input )
138+ public async ValueTask < ValueContainer > EvaluateToValueContainer ( string input )
137139 {
138- return _input . Parse ( input ) ;
140+ return await _input . Parse ( input ) ;
139141 }
140142 }
141143}
0 commit comments