Esempio n. 1
0
        public static IList <Element> Parse(string expression)
        {
            //TODO we may want to chache the expressions for better performance
            ParseContext context = new ParseContext(expression);

            while (context.TokenPosition < expression.Length)
            {
                string c = context.Expression.Substring(context.TokenPosition, 1);
                if (WhiteSpaceRegExp.IsMatch(c))
                {
                    context.TokenPosition++;
                    continue;
                }
                if (ElementGrouping.Parse(context))
                {
                    continue;
                }
                else if (ElementTernaryOperator.Parse(context))
                {
                    continue;
                }
                else if (ElementOperator.Parse(context))
                {
                    continue;
                }
                else if (ElementLiteral.Parse(context))
                {
                    continue;
                }
                else if (ElementVariable.Parse(context))
                {
                    continue;
                }
                else if (ElementSelector.Parse(context))
                {
                    continue;
                }
                else
                {
                    throw new ELException("Invalid character at position" + context.TokenPosition);
                }
            }

            Element.ValidateTokenOrder(context, TokenType.End);
            if (context.BpOrder.Count != 0)
            {
                throw new ELException("Not all parentesis or brakets were closed or ? with out :");
            }

            while (context.Stack.Count > 0)
            {
                context.Ouput.Push(context.Stack.Pop());
            }
            //reverse order
            List <Element> result = new List <Element>(context.Ouput);

            result.Reverse();
            return(result);
        }