示例#1
0
        private ExpressionToken ParseExpression(
            Int32?line,
            Int32?column,
            String value,
            String[] allowedContext,
            out Exception ex)
        {
            var trimmed = value.Trim();

            // Check if the value is empty
            if (String.IsNullOrEmpty(trimmed))
            {
                ex = new ArgumentException(TemplateStrings.ExpectedExpression());
                return(null);
            }

            // Try to find a matching directive
            List <String> parameters;

            if (MatchesDirective(trimmed, TemplateConstants.InsertDirective, 0, out parameters, out ex))
            {
                return(new InsertExpressionToken(m_fileId, line, column));
            }
            else if (ex != null)
            {
                return(null);
            }

            // Check if the value is an expression
            if (!ExpressionToken.IsValidExpression(trimmed, allowedContext, out ex))
            {
                return(null);
            }

            // Return the expression
            return(new BasicExpressionToken(m_fileId, line, column, trimmed));
        }