/// <summary> /// Recupera o valor do termo condicional. /// </summary> /// <param name="enumerator"></param> /// <param name="configuration"></param> /// <returns></returns> private static ConditionalTerm GetTerm(ref IEnumerator <Text.InterpreterExpression.Expression> enumerator, Text.InterpreterExpression.ILexerConfiguration configuration) { var item = enumerator.Current; if (item.Token == (int)Text.InterpreterExpression.TokenID.Minus) { if (!enumerator.MoveNext()) { throw new ConditionalParserException("Expected expression after minus"); } return(new MinusTerm(GetTerm(ref enumerator, configuration))); } else if (item.Token == (int)Parser.SqlTokenID.kCase) { return(GetCaseConditional(ref enumerator, configuration)); } var container = item.Text.Length > 0 && item.Token != (int)Colosoft.Text.InterpreterExpression.TokenID.StringLiteral ? Array.Find(configuration.Containers, f => f.Start == item.Text[0]) : null; if (container != null) { enumerator.MoveNext(); return(GetContainer(ref enumerator, configuration, container)); } var expression = new Parser.SqlExpression(item); if (expression.Type == Parser.SqlExpressionType.Column) { return(new Column(expression)); } else if (expression.Type == Parser.SqlExpressionType.Variable) { return(new Variable(expression.Value.Text)); } return(new Constant(item.ToString())); }
/// <summary> /// Cria a instancia com base na expressão. /// </summary> /// <param name="expression"></param> internal Column(Parser.SqlExpression expression) { expression.Require("expression").NotNull(); var text = expression.Value.Text; text = text.Trim(); var lastEmpty = text.LastIndexOf(' '); var splittedExpression = text.Split('.'); for (var i = lastEmpty; i > 0; i--) { if (text[i] != ' ') { if (splittedExpression.Length > 1) { Name = splittedExpression[1].Substring(0, i + 1).Trim(); Owner = splittedExpression[0]; } else { Name = text.Substring(0, i + 1).Trim(); } } } if (splittedExpression.Length > 1) { Name = lastEmpty < 0 ? splittedExpression[1] : null; Owner = splittedExpression[0]; } else { Name = lastEmpty < 0 ? text : null; } }