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 {
@@ -59,7 +61,7 @@ from content in Parse.CharExcept('\'').Or(escapedCharacters).Many().Text()
5961 from nll in nullConditional
6062 from index in _method . Or ( stringLiteral ) . Or ( integer ) . Contained ( lBracket , rBracket )
6163 select new IndexRule ( index , nll ) ;
62-
64+
6365 Parser < IRule > dotIndices =
6466 from nll in nullConditional
6567 from dot in Parse . Char ( '.' )
@@ -69,7 +71,10 @@ from index in Parse.AnyChar.Except(
6971 . Or ( lParenthesis )
7072 . Or ( rParenthesis )
7173 . Or ( Parse . Char ( '@' ) )
72- ) . Many ( ) . Text ( )
74+ . Or ( Parse . Char ( ',' ) )
75+ . Or ( Parse . Char ( '.' ) )
76+ . Or ( Parse . Char ( '?' ) )
77+ ) . Many ( ) . Text ( )
7378 select new IndexRule ( new StringLiteralRule ( new ValueContainer ( index ) ) , nll ) ;
7479
7580 Parser < IRule > argument =
@@ -93,49 +98,49 @@ from args in arguments.Contained(lParenthesis, rParenthesis)
9398 Parse . Ref ( ( ) =>
9499 from func in function
95100 from indexes in bracketIndices . Or ( dotIndices ) . Many ( )
96- select ( IRule ) new AccessValueRule ( func , indexes ) ) ;
101+ select indexes . Aggregate ( func , ( acc , next ) => new AccessValueRule ( acc , next ) ) ) ;
97102
98- Parser < ValueContainer > enclosedExpression =
103+ Parser < ValueTask < ValueContainer > > enclosedExpression =
99104 _method . Contained (
100105 Parse . String ( "@{" ) ,
101106 Parse . Char ( '}' ) )
102107 . Select ( x => x . Evaluate ( ) ) ;
103108
104- Parser < ValueContainer > expression =
109+ Parser < ValueTask < ValueContainer > > expression =
105110 from at in Parse . Char ( '@' )
106111 from method in _method
107112 select method . Evaluate ( ) ;
108-
113+
109114 Parser < string > allowedString =
110115 from t in simpleString . Or ( allowedCharacters ) . Many ( )
111116 select string . Concat ( t ) ;
112117
113- Parser < ValueContainer > joinedString =
118+ Parser < ValueTask < ValueContainer > > joinedString =
114119 from e in (
115120 from preFix in allowedString
116121 from exp in enclosedExpression . Optional ( )
117122 select exp . IsEmpty ? preFix : preFix + exp . Get ( ) )
118123 . Many ( )
119- select new ValueContainer ( string . Concat ( e ) ) ;
124+ select new ValueTask < ValueContainer > ( new ValueContainer ( string . Concat ( e ) ) ) ;
120125
121- Parser < ValueContainer > charPrefixedString =
126+ Parser < ValueTask < ValueContainer > > charPrefixedString =
122127 from at in Parse . Char ( '@' )
123128 from str in Parse . LetterOrDigit . Many ( ) . Text ( ) . Except ( Parse . Chars ( '{' , '@' ) )
124- select new ValueContainer ( str ) ;
129+ select new ValueTask < ValueContainer > ( new ValueContainer ( str ) ) ;
125130
126131 _input = expression . Or ( charPrefixedString ) . Or ( joinedString ) ;
127132 }
128133
129- public string EvaluateToString ( string input )
134+ public async ValueTask < string > EvaluateToString ( string input )
130135 {
131- var output = _input . Parse ( input ) ;
136+ var output = await _input . Parse ( input ) ;
132137
133138 return output . GetValue < string > ( ) ;
134139 }
135140
136- public ValueContainer EvaluateToValueContainer ( string input )
141+ public async ValueTask < ValueContainer > EvaluateToValueContainer ( string input )
137142 {
138- return _input . Parse ( input ) ;
143+ return await _input . Parse ( input ) ;
139144 }
140145 }
141146}
0 commit comments