Permalink
Browse files

Expose UriQueryExpressionParser.ParseFilter as a public API (#805)

Expose UriQueryExpressionParser and QueryToken object model publicly
  • Loading branch information...
mabdelmonemali authored and robward-ms committed May 2, 2017
1 parent 170827a commit 0b54111ee7909e71263b83fc60268de0de817986
Showing with 853 additions and 97 deletions.
  1. +2 −1 src/Microsoft.OData.Client/ALinq/ResourceBinder.cs
  2. +2 −2 src/Microsoft.OData.Client/Build.Portable/Microsoft.OData.Client.Portable.csproj
  3. +2 −2 src/Microsoft.OData.Client/Microsoft.OData.Client.csproj
  4. +3 −3 src/Microsoft.OData.Core/Build.Net35/Microsoft.OData.Core.NetFX35.csproj
  5. +1 −1 src/Microsoft.OData.Core/Microsoft.OData.Core.csproj
  6. +31 −1 src/Microsoft.OData.Core/UriParser/Aggregation/AggregateExpressionToken.cs
  7. +14 −1 src/Microsoft.OData.Core/UriParser/Aggregation/AggregateToken.cs
  8. +1 −1 src/Microsoft.OData.Core/UriParser/Aggregation/ApplyTransformationToken.cs
  9. +16 −2 src/Microsoft.OData.Core/UriParser/Aggregation/GroupByToken.cs
  10. +7 −7 src/Microsoft.OData.Core/UriParser/Binders/ExpandTreeNormalizer.cs
  11. +1 −1 src/Microsoft.OData.Core/UriParser/Binders/SelectExpandBinder.cs
  12. +1 −1 src/Microsoft.OData.Core/UriParser/NamedValue.cs
  13. +2 −2 src/Microsoft.OData.Core/UriParser/Parsers/SelectExpandParser.cs
  14. +20 −11 src/Microsoft.OData.Core/UriParser/Parsers/UriQueryExpressionParser.cs
  15. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/AllToken.cs
  16. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/AnyToken.cs
  17. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/BinaryOperatorToken.cs
  18. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/CustomQueryOptionToken.cs
  19. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/DottedIdentifierToken.cs
  20. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/EndPathToken.cs
  21. +14 −14 src/Microsoft.OData.Core/UriParser/SyntacticAst/ExpandTermToken.cs
  22. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/ExpandToken.cs
  23. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/FunctionCallToken.cs
  24. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/FunctionParameterToken.cs
  25. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/InnerPathToken.cs
  26. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/LambdaToken.cs
  27. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/LiteralToken.cs
  28. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/NonSystemToken.cs
  29. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/OrderByToken.cs
  30. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/PathSegmentToken.cs
  31. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/PathToken.cs
  32. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/QueryToken.cs
  33. +2 −1 src/Microsoft.OData.Core/UriParser/{TreeNodeKinds → SyntacticAst}/QueryTokenKind.cs
  34. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/RangeVariableToken.cs
  35. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/SelectToken.cs
  36. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/StarToken.cs
  37. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/SystemToken.cs
  38. +1 −1 src/Microsoft.OData.Core/UriParser/SyntacticAst/UnaryOperatorToken.cs
  39. +2 −2 src/Microsoft.OData.Core/UriParser/Visitors/IPathSegmentTokenVisitor.cs
  40. +1 −1 src/Microsoft.OData.Core/UriParser/Visitors/ISyntacticTreeVisitor.cs
  41. +7 −7 test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Binders/ExpandTreeNormalizerTests.cs
  42. +6 −6 test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/ExpandOptionParserTests.cs
  43. +4 −4 test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/Parsers/SelectExpandParserTests.cs
  44. +2 −2 test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/SyntacticAst/ExpandTermTokenTests.cs
  45. +2 −2 test/FunctionalTests/Microsoft.OData.Core.Tests/UriParser/TokenAssertions.cs
  46. +688 −0 test/FunctionalTests/Tests/DataOData/Tests/OData.Common.Tests/PublicApi/PublicApi.bsl
@@ -21,7 +21,8 @@ namespace Microsoft.OData.Client
using Microsoft.OData;
using Microsoft.OData.UriParser;
using Microsoft.OData.Edm;
using PathSegmentToken = Microsoft.OData.Client.ALinq.UriParser.PathSegmentToken;
using NonSystemToken = Microsoft.OData.Client.ALinq.UriParser.NonSystemToken;
#endregion Namespaces
/// <summary>
@@ -160,8 +160,8 @@
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\SyntacticAst\QueryToken.cs">
<Link>ALinq\UriParser\SyntacticAst\QueryToken.cs</Link>
</Compile>
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\TreeNodeKinds\QueryTokenKind.cs">
<Link>ALinq\UriParser\TreeNodeKinds\QueryTokenKind.cs</Link>
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\SyntacticAst\QueryTokenKind.cs">
<Link>ALinq\UriParser\SyntacticAst\QueryTokenKind.cs</Link>
</Compile>
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\SyntacticAst\RangeVariableToken.cs">
<Link>ALinq\UriParser\SyntacticAst\RangeVariableToken.cs</Link>
@@ -166,8 +166,8 @@
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\SyntacticAst\QueryToken.cs">
<Link>ALinq\UriParser\SyntacticAst\QueryToken.cs</Link>
</Compile>
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\TreeNodeKinds\QueryTokenKind.cs">
<Link>ALinq\UriParser\TreeNodeKinds\QueryTokenKind.cs</Link>
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\SyntacticAst\QueryTokenKind.cs">
<Link>ALinq\UriParser\SyntacticAst\QueryTokenKind.cs</Link>
</Compile>
<Compile Include="$(EnlistmentRoot)\src\Microsoft.OData.Core\UriParser\SyntacticAst\RangeVariableToken.cs">
<Link>ALinq\UriParser\SyntacticAst\RangeVariableToken.cs</Link>
@@ -1312,6 +1312,9 @@
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\SyntacticAst\QueryToken.cs">
<Link>Microsoft\OData\Core\UriParser\SyntacticAst\QueryToken.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\SyntacticAst\QueryTokenKind.cs">
<Link>Microsoft\OData\Core\UriParser\SyntacticAst\QueryTokenKind.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\SyntacticAst\RangeVariableToken.cs">
<Link>Microsoft\OData\Core\UriParser\SyntacticAst\RangeVariableToken.cs</Link>
</Compile>
@@ -1339,9 +1342,6 @@
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\TreeNodeKinds\QueryNodeKind.cs">
<Link>Microsoft\OData\Core\UriParser\TreeNodeKinds\QueryNodeKind.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\TreeNodeKinds\QueryTokenKind.cs">
<Link>Microsoft\OData\Core\UriParser\TreeNodeKinds\QueryTokenKind.cs</Link>
</Compile>
<Compile Include="$(ODataCrossTargettingSourcePath)\UriParser\TreeNodeKinds\RequestTargetKind.cs">
<Link>Microsoft\OData\Core\UriParser\TreeNodeKinds\RequestTargetKind.cs</Link>
</Compile>
@@ -542,7 +542,7 @@
<Compile Include="UriParser\TreeNodeKinds\BinaryOperatorKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\ExpressionTokenKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\QueryNodeKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\QueryTokenKind.cs" />
<Compile Include="UriParser\SyntacticAst\QueryTokenKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\RequestTargetKind.cs" />
<Compile Include="UriParser\TreeNodeKinds\UnaryOperatorKind.cs" />
<Compile Include="UriParser\TypePromotionUtils.cs" />
@@ -14,7 +14,10 @@ namespace Microsoft.OData.UriParser.Aggregation
#endif
using Microsoft.OData.UriParser;
internal sealed class AggregateExpressionToken : QueryToken
/// <summary>
/// Query token representing an Aggregate expression.
/// </summary>
public sealed class AggregateExpressionToken : QueryToken
{
private readonly QueryToken expression;
@@ -24,6 +27,12 @@ internal sealed class AggregateExpressionToken : QueryToken
private readonly string alias;
/// <summary>
/// Create an AggregateExpressionToken.
/// </summary>
/// <param name="expression">The aggregate expression.</param>
/// <param name="method">The aggregation method.</param>
/// <param name="alias">The alias for this query token.</param>
public AggregateExpressionToken(QueryToken expression, AggregationMethod method, string alias)
{
ExceptionUtils.CheckArgumentNotNull(expression, "expression");
@@ -34,32 +43,53 @@ public AggregateExpressionToken(QueryToken expression, AggregationMethod method,
this.alias = alias;
}
/// <summary>
/// Create an AggregateExpressionToken.
/// </summary>
/// <param name="expression">The aggregate expression.</param>
/// <param name="methodDefinition">The aggregate method definition.</param>
/// <param name="alias">The alias for this query token.</param>
public AggregateExpressionToken(QueryToken expression, AggregationMethodDefinition methodDefinition, string alias)
: this(expression, methodDefinition.MethodKind, alias)
{
this.methodDefinition = methodDefinition;
}
/// <summary>
/// Gets the kind of this token.
/// </summary>
public override QueryTokenKind Kind
{
get { return QueryTokenKind.AggregateExpression; }
}
/// <summary>
/// Gets the AggregationMethod of this token.
/// </summary>
public AggregationMethod Method
{
get { return this.method; }
}
/// <summary>
/// Gets the aggregate method definition.
/// </summary>
public AggregationMethodDefinition MethodDefinition
{
get { return this.methodDefinition; }
}
/// <summary>
/// Gets the expression.
/// </summary>
public QueryToken Expression
{
get { return this.expression; }
}
/// <summary>
/// Gets the alias.
/// </summary>
public string Alias
{
get { return this.alias; }
@@ -13,21 +13,34 @@ namespace Microsoft.OData.UriParser.Aggregation
using System.Collections.Generic;
using Microsoft.OData.UriParser;
internal sealed class AggregateToken : ApplyTransformationToken
/// <summary>
/// Query token representing an Aggregate token.
/// </summary>
public sealed class AggregateToken : ApplyTransformationToken
{
private readonly IEnumerable<AggregateExpressionToken> expressions;
/// <summary>
/// Create an AggregateToken.
/// </summary>
/// <param name="expressions">The list of AggregateExpressionToken.</param>
public AggregateToken(IEnumerable<AggregateExpressionToken> expressions)
{
ExceptionUtils.CheckArgumentNotNull(expressions, "expressions");
this.expressions = expressions;
}
/// <summary>
/// Gets the kind of this token.
/// </summary>
public override QueryTokenKind Kind
{
get { return QueryTokenKind.Aggregate; }
}
/// <summary>
/// Gets the list of AggregateExpressionToken.
/// </summary>
public IEnumerable<AggregateExpressionToken> Expressions
{
get
@@ -15,7 +15,7 @@ namespace Microsoft.OData.UriParser.Aggregation
/// <summary>
/// Base class for Apply transformation tokens
/// </summary>
internal abstract class ApplyTransformationToken : QueryToken
public abstract class ApplyTransformationToken : QueryToken
{
}
}
@@ -13,12 +13,20 @@ namespace Microsoft.OData.UriParser.Aggregation
using System.Collections.Generic;
using Microsoft.OData.UriParser;
internal sealed class GroupByToken : ApplyTransformationToken
/// <summary>
/// Query token representing a GroupBy token.
/// </summary>
public sealed class GroupByToken : ApplyTransformationToken
{
private readonly IEnumerable<EndPathToken> properties;
private readonly ApplyTransformationToken child;
/// <summary>
/// Create a GroupByToken.
/// </summary>
/// <param name="properties">The list of group by properties.</param>
/// <param name="child">The child of this token.</param>
public GroupByToken(IEnumerable<EndPathToken> properties, ApplyTransformationToken child)
{
ExceptionUtils.CheckArgumentNotNull(properties, "properties");
@@ -28,18 +36,24 @@ public GroupByToken(IEnumerable<EndPathToken> properties, ApplyTransformationTok
}
/// <summary>
/// The kind of the query token.
/// Gets the kind of this token.
/// </summary>
public override QueryTokenKind Kind
{
get { return QueryTokenKind.AggregateGroupBy; }
}
/// <summary>
/// Gets the list of group by properties.
/// </summary>
public IEnumerable<EndPathToken> Properties
{
get { return this.properties; }
}
/// <summary>
/// Gets the child of this token.
/// </summary>
public ApplyTransformationToken Child
{
get { return this.child; }
@@ -44,7 +44,7 @@ public ExpandToken NormalizePaths(ExpandToken treeToInvert)
foreach (ExpandTermToken term in treeToInvert.ExpandTerms)
{
PathReverser pathReverser = new PathReverser();
PathSegmentToken reversedPath = term.PathToNavProp.Accept(pathReverser);
PathSegmentToken reversedPath = term.PathToNavigationProp.Accept(pathReverser);
// we also need to call the select token normalizer for this level to reverse the select paths
SelectToken newSelectToken = term.SelectOption;
@@ -86,7 +86,7 @@ public ExpandToken CombineTerms(ExpandToken treeToCollapse)
{
ExpandToken newSubExpand = CombineTerms(termToken.ExpandOption);
finalTermToken = new ExpandTermToken(
termToken.PathToNavProp,
termToken.PathToNavigationProp,
termToken.FilterOption,
termToken.OrderByOptions,
termToken.TopOption,
@@ -112,12 +112,12 @@ public ExpandToken CombineTerms(ExpandToken treeToCollapse)
/// <returns>the combined token, or, if the two are mutually exclusive, the same tokens</returns>
public ExpandTermToken CombineTerms(ExpandTermToken existingToken, ExpandTermToken newToken)
{
Debug.Assert(new PathSegmentTokenEqualityComparer().Equals(existingToken.PathToNavProp, newToken.PathToNavProp), "Paths should be equal.");
Debug.Assert(new PathSegmentTokenEqualityComparer().Equals(existingToken.PathToNavigationProp, newToken.PathToNavigationProp), "Paths should be equal.");
List<ExpandTermToken> childNodes = CombineChildNodes(existingToken, newToken).ToList();
SelectToken combinedSelects = CombineSelects(existingToken, newToken);
return new ExpandTermToken(
existingToken.PathToNavProp,
existingToken.PathToNavigationProp,
existingToken.FilterOption,
existingToken.OrderByOptions,
existingToken.TopOption,
@@ -177,13 +177,13 @@ private void AddChildOptionsToDictionary(ExpandTermToken newToken, Dictionary<Pa
private void AddOrCombine(IDictionary<PathSegmentToken, ExpandTermToken> combinedTerms, ExpandTermToken expandedTerm)
{
ExpandTermToken existingTerm;
if (combinedTerms.TryGetValue(expandedTerm.PathToNavProp, out existingTerm))
if (combinedTerms.TryGetValue(expandedTerm.PathToNavigationProp, out existingTerm))
{
combinedTerms[expandedTerm.PathToNavProp] = CombineTerms(expandedTerm, existingTerm);
combinedTerms[expandedTerm.PathToNavigationProp] = CombineTerms(expandedTerm, existingTerm);
}
else
{
combinedTerms.Add(expandedTerm.PathToNavProp, expandedTerm);
combinedTerms.Add(expandedTerm.PathToNavigationProp, expandedTerm);
}
}
@@ -180,7 +180,7 @@ private SelectItem GenerateExpandItem(ExpandTermToken tokenIn)
{
ExceptionUtils.CheckArgumentNotNull(tokenIn, "tokenIn");
PathSegmentToken currentToken = tokenIn.PathToNavProp;
PathSegmentToken currentToken = tokenIn.PathToNavigationProp;
IEdmStructuredType currentLevelEntityType = this.EdmType;
List<ODataPathSegment> pathSoFar = new List<ODataPathSegment>();
@@ -13,7 +13,7 @@ namespace Microsoft.OData.UriParser
/// <summary>
/// Class representing a single named value (name and value pair).
/// </summary>
internal sealed class NamedValue
public sealed class NamedValue
{
/// <summary>
/// The name of the value. Or null if the name was not used for this value.
@@ -270,7 +270,7 @@ private ExpandToken ParseCommaSeperatedExpandList(Func<IEnumerable<ExpandTermTok
List<string> explicitedTokens = new List<string>();
foreach (var tmpTokens in termTokens)
{
var pathToNav = tmpTokens.PathToNavProp;
var pathToNav = tmpTokens.PathToNavigationProp;
if (pathToNav.Identifier != UriQueryConstants.RefSegment)
{
explicitedTokens.Add(pathToNav.Identifier);
@@ -284,7 +284,7 @@ private ExpandToken ParseCommaSeperatedExpandList(Func<IEnumerable<ExpandTermTok
// Add navigation path if it is not in list yet
foreach (var tmpTokens in starTermTokens)
{
var pathToNav = tmpTokens.PathToNavProp;
var pathToNav = tmpTokens.PathToNavigationProp;
if (pathToNav.Identifier != UriQueryConstants.RefSegment && !explicitedTokens.Contains(pathToNav.Identifier))
{
termTokens.Add(tmpTokens);
@@ -20,7 +20,7 @@ namespace Microsoft.OData.UriParser
/// <summary>
/// Parser which consumes the query expression ($filter, $orderby) and produces the lexical object model.
/// </summary>
internal sealed class UriQueryExpressionParser
public sealed class UriQueryExpressionParser
{
/// <summary>
/// The maximum number of recursion nesting allowed.
@@ -55,6 +55,15 @@ internal sealed class UriQueryExpressionParser
/// </summary>
private bool enableCaseInsensitiveBuiltinIdentifier = false;
/// <summary>
/// Creates a UriQueryExpressionParser.
/// </summary>
/// <param name="maxDepth">The maximum depth of each part of the query - a recursion limit.</param>
public UriQueryExpressionParser(int maxDepth)
: this(maxDepth, false)
{
}
/// <summary>
/// Constructor.
/// </summary>
@@ -95,6 +104,16 @@ internal ExpressionLexer Lexer
get { return this.lexer; }
}
/// <summary>
/// Parses the $filter expression.
/// </summary>
/// <param name="filter">The $filter expression string to parse.</param>
/// <returns>The lexical token representing the filter.</returns>
public QueryToken ParseFilter(string filter)
{
return this.ParseExpressionText(filter);
}
/// <summary>
/// Parses a literal.
/// </summary>
@@ -186,16 +205,6 @@ internal static string GetEdmConstantNames(IEdmTypeReference edmTypeReference)
}
}
/// <summary>
/// Parses the $filter expression.
/// </summary>
/// <param name="filter">The $filter expression string to parse.</param>
/// <returns>The lexical token representing the filter.</returns>
internal QueryToken ParseFilter(string filter)
{
return this.ParseExpressionText(filter);
}
internal IEnumerable<QueryToken> ParseApply(string apply)
{
Debug.Assert(apply != null, "apply != null");
@@ -16,7 +16,7 @@ namespace Microsoft.OData.UriParser
/// <summary>
/// Lexical token representing the All Query
/// </summary>
internal sealed class AllToken : LambdaToken
public sealed class AllToken : LambdaToken
{
/// <summary>
/// Create a AllToken given the expression, parameter, and parent
@@ -16,7 +16,7 @@ namespace Microsoft.OData.UriParser
/// <summary>
/// Lexical token representing the Any Query
/// </summary>
internal sealed class AnyToken : LambdaToken
public sealed class AnyToken : LambdaToken
{
/// <summary>
/// Create a AnyToken given the expression, parameter, and parent
Oops, something went wrong.

0 comments on commit 0b54111

Please sign in to comment.