private ExpressionFnOuter Lexer(TokenStream stream) { if (stream.TryTokenType(ExpressionTokenType.Element, out ExpressionToken token)) { return(Element(stream, token)); } if (stream.TryTokenType(ExpressionTokenType.String, out token)) { return(String(token)); } if (stream.TryTokenType(ExpressionTokenType.Numeric, out token)) { return(Numeric(token)); } return(null); }
private ExpressionFnOuter Inner(TokenStream stream) { ExpressionFnOuter result = null; if (stream.TryTokenType(ExpressionTokenType.String, out ExpressionToken token)) { return(String(token)); } if (stream.TryTokenType(ExpressionTokenType.Numeric, out token)) { return(Numeric(token)); } if (stream.TryTokenType(ExpressionTokenType.Element, out token)) { result = Element(stream, token); } return(result); }
private ExpressionFnOuter Element(TokenStream stream, ExpressionToken element) { ExpressionFnOuter result = null; // function if (stream.Skip(ExpressionTokenType.GroupStart)) { if (!_Functions.TryDescriptor(element.Content, out IFunctionDescriptor descriptor)) { throw new NotImplementedException(string.Format(PSRuleResources.FunctionNotFound, element.Content)); } var fnParams = new List <ExpressionFnOuter>(); while (!stream.Skip(ExpressionTokenType.GroupEnd)) { fnParams.Add(Inner(stream)); } var aParams = fnParams.ToArray(); result = (context) => descriptor.Invoke(context, aParams); while (stream.TryTokenType(ExpressionTokenType.IndexStart, out ExpressionToken token) || stream.TryTokenType(ExpressionTokenType.Property, out token)) { if (token.Type == ExpressionTokenType.IndexStart) { // Invert: index(fn1(p1, p2), 0) var inner = Inner(stream); ExpressionFnOuter outer = AddIndex(result, inner); result = outer; stream.Skip(ExpressionTokenType.IndexEnd); } else if (token.Type == ExpressionTokenType.Property) { // Invert: property(fn1(p1, p2), "name") ExpressionFnOuter outer = AddProperty(result, token.Content); result = outer; } } } // integer else { result = (context) => element.Content; } return(result); }