Exemplo n.º 1
0
        string Calculate(ContentExpression expression, EvaluationContext context)
        {
            var sx = expression as SymbolExpression;

            if (sx != null)
            {
                string[] innerTokens;
                var      resolvedSymbol = context.ResolveOptional(sx, out innerTokens);
                _missingTokens.AddRange(innerTokens);
                return(resolvedSymbol);
            }

            var fx = expression as FunctionCallExpression;

            if (fx == null)
            {
                throw new NotImplementedException("Unknown expression type: " + expression);
            }

            var argument = Calculate(fx.Argument, context);

            var args = fx.Options.Select(opt => Resolve(opt, context)).ToArray();

            return(BuiltInFunctions.InvokeOrNull(fx.Function, argument, args));
        }
Exemplo n.º 2
0
 public FunctionCallExpression(bool filterSyntax, string function, ContentExpression argument, params TemplateToken[] options)
 {
     Options       = options;
     _filterSyntax = filterSyntax;
     Function      = function;
     Argument      = argument;
 }
Exemplo n.º 3
0
        static IEnumerable <SymbolExpression> GetSymbols(ContentExpression expression)
        {
            var sx = expression as SymbolExpression;

            if (sx != null)
            {
                yield return(sx);
            }
            else
            {
                var fx = expression as FunctionCallExpression;
                if (fx != null)
                {
                    foreach (var argument in fx.Arguments)
                    {
                        foreach (var symbol in GetSymbols(argument))
                        {
                            yield return(symbol);
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException("Unknown expression type: " + expression);
                }
            }
        }
Exemplo n.º 4
0
        string Calculate(ContentExpression expression, EvaluationContext context)
        {
            var sx = expression as SymbolExpression;

            if (sx != null)
            {
                string[] innerTokens;
                var      resolvedSymbol = context.ResolveOptional(sx, out innerTokens);
                _missingTokens.AddRange(innerTokens);
                return(resolvedSymbol);
            }

            var fx = expression as FunctionCallExpression;

            if (fx == null)
            {
                throw new NotImplementedException("Unknown expression type: " + expression);
            }

            var args = fx.Arguments.Select(a => Calculate(a, context)).ToArray();

            if (args.Any(a => a == null))
            {
                return(null); // If any argument is undefined, we fail the whole shebang
            }
            return(BuiltInFunctions.InvokeOrNull(fx.Function, args));
        }
Exemplo n.º 5
0
 public SubstitutionToken(ContentExpression expression)
 {
     this.expression = expression;
 }