Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class
        /// by parsing specified property expression string.
        /// </summary>
        /// <param name="expression">Property expression to parse.</param>
        internal static IExpression ParseProperty(string expression)
        {
            if (StringUtils.HasText(expression))
            {
                ExpressionLexer  lexer  = new ExpressionLexer(new StringReader(expression));
                ExpressionParser parser = new SpringExpressionParser(lexer);

                try
                {
                    parser.property();
                }
                catch (TokenStreamRecognitionException ex)
                {
                    throw new SyntaxErrorException(ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression);
                }
                return((IExpression)parser.getAST());
            }
            else
            {
                return(new Expression());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a list of Ant-style expressions from the specified text.
        /// </summary>
        /// <param name="text">The text to inspect.</param>
        /// <returns>
        /// A list of expressions that exist in the specified text.
        /// </returns>
        /// <exception cref="System.FormatException">
        /// If any of the expressions in the supplied <paramref name="text"/>
        /// is empty (<c>${}</c>).
        /// </exception>
        public static IList <string> GetAntExpressions(string text)
        {
            List <string> expressions = new List <string>();

            if (StringUtils.HasText(text))
            {
                int start = text.IndexOf(AntExpressionPrefix);
                while (start >= 0)
                {
                    int end = text.IndexOf(AntExpressionSuffix, start + 2);
                    if (end == -1)
                    {
                        // terminator character not found, so let's quit...
                        start = -1;
                    }
                    else
                    {
                        string exp = text.Substring(start + 2, end - start - 2);
                        if (StringUtils.IsNullOrEmpty(exp))
                        {
                            throw new FormatException(
                                      string.Format("Empty {0}{1} value found in text : '{2}'.",
                                                    AntExpressionPrefix,
                                                    AntExpressionSuffix,
                                                    text));
                        }
                        if (expressions.IndexOf(exp) < 0)
                        {
                            expressions.Add(exp);
                        }
                        start = text.IndexOf(AntExpressionPrefix, end);
                    }
                }
            }
            return(expressions);
        }