private string FormatLogicalExpression(IFilterTree tree, bool isolate) { var operatorText = TokenMappings.TokenTypeToDefaultValueMap[tree.Token.Type]; string resultExpression; if (TokenMappings.IsBinaryLogicalOperation(tree.Token)) { var operandTexts = new List <string>(); foreach (var childItem in tree.GetChildren()) { operandTexts.Add(FormatExpression(childItem, true)); } resultExpression = string.Join($" {operatorText} ", operandTexts); } else if (TokenMappings.IsUnaryLogicalOperation(tree.Token)) { var childNode = tree.GetChild(0); var operandText = FormatExpression(childNode, false); resultExpression = TokenMappings.IsBinaryLogicalOperation(childNode.Token) ? $"{operatorText} ({operandText})" : $"{operatorText} {operandText}"; } else { throw new FormaterException($"Encountered unexpected node of type {tree.Token.Type}."); } return(isolate ? $"({resultExpression})" : resultExpression); }
private static string FormatValueList(IFilterTree tree) { var elementTexts = new List <string>(); foreach (var treeItem in tree.GetChildren()) { var text = FormatValue(treeItem); if (NeedsEscaping(text)) { text = EscapeText(text); } elementTexts.Add(text); } return(string.Join(", ", elementTexts)); }
private static string FormatValueList(IFilterTree tree) { if (tree.Token.Type != TokenType.ValueList) { throw new UnsupportedTokenException(tree.Token); } var elementTexts = new List <string>(); foreach (var treeItem in tree.GetChildren()) { var text = FormatValue(treeItem); elementTexts.Add(text); } var innerList = string.Join(", ", elementTexts); return($"({innerList})"); }
private string FormatLogicalExpression(IFilterTree tree) { if (tree.Token.Type != TokenType.And) { throw new UnsupportedTokenException(tree.Token); } var operatorText = TokenMappings.TokenTypeToLegacyValueMap[tree.Token.Type]; var operandTexts = new List <string>(); foreach (var childItem in tree.GetChildren()) { operandTexts.Add(FormatExpression(childItem)); } var resultExpression = string.Join($" {operatorText} ", operandTexts); return(resultExpression); }