Class QueryExpressionParser
- Namespace
- JsonApiDotNetCore.Queries.Parsing
- Assembly
- JsonApiDotNetCore.dll
The base class for parsing query string parameters, using the Recursive Descent algorithm.
[PublicAPI]
public abstract class QueryExpressionParser
- Inheritance
-
QueryExpressionParser
- Derived
- Inherited Members
Remarks
A tokenizer populates a stack of tokens from the source text, which is then recursively popped by various parsing routines. A QueryParseException is expected to be thrown on invalid input.
Properties
Source
Contains the source text that tokens were produced from, after Tokenize(string) has been called.
protected string Source { get; }
Property Value
TokenStack
Contains the tokens produced from the source text, after Tokenize(string) has been called.
protected Stack<Token> TokenStack { get; }
Property Value
Remarks
The various parsing methods typically pop tokens while producing QueryExpressions.
Methods
AssertTokenStackIsEmpty()
Throws a QueryParseException when TokenStack is not empty. Derived types should call this when parsing has completed, to ensure all input has been processed.
protected void AssertTokenStackIsEmpty()
EatSingleCharacterToken(TokenKind)
Consumes the expected token kind from the top of TokenStack. Throws a QueryParseException if a different token kind is at the top, or if there are no more tokens available.
protected virtual void EatSingleCharacterToken(TokenKind kind)
Parameters
kind
TokenKind
EatText(string)
Consumes a token containing the expected text from the top of TokenStack. Throws a QueryParseException if a different token kind is at the top, it contains a different text, or if there are no more tokens available.
protected void EatText(string text)
Parameters
text
string
GetNextTokenPositionOrEnd()
Gets the zero-based position of the token at the top of TokenStack, or the position at the end of the source text if there are no more tokens available.
protected int GetNextTokenPositionOrEnd()
Returns
GetRelativePositionOfLastFieldInChain(ResourceFieldChainExpression)
Gets the zero-based position of the last field in the specified resource field chain.
protected int GetRelativePositionOfLastFieldInChain(ResourceFieldChainExpression fieldChain)
Parameters
fieldChain
ResourceFieldChainExpression
Returns
ParseCommaSeparatedSequenceOfRelationshipChains(ResourceType)
Parses a comma-separated sequence of relationship chains, taking relationships on derived types into account.
protected IncludeExpression ParseCommaSeparatedSequenceOfRelationshipChains(ResourceType resourceType)
Parameters
resourceType
ResourceType
Returns
ParseFieldChain(FieldChainPattern, FieldChainPatternMatchOptions, ResourceType, string?)
Parses a dot-separated path of field names into a chain of resource fields, while matching it against the specified pattern.
protected ResourceFieldChainExpression ParseFieldChain(FieldChainPattern pattern, FieldChainPatternMatchOptions options, ResourceType resourceType, string? alternativeErrorMessage)
Parameters
pattern
FieldChainPatternoptions
FieldChainPatternMatchOptionsresourceType
ResourceTypealternativeErrorMessage
string
Returns
ParseRelationshipChainEndingInToMany(ResourceType, string?)
Parses a relationship chain that ends in a to-many relationship, taking relationships on derived types into account.
protected IncludeExpression ParseRelationshipChainEndingInToMany(ResourceType resourceType, string? alternativeErrorMessage)
Parameters
resourceType
ResourceTypealternativeErrorMessage
string
Returns
Tokenize(string)
Populates TokenStack from the source text using QueryTokenizer.
protected virtual void Tokenize(string source)
Parameters
source
string
Remarks
To use a custom tokenizer, override this method and consider overriding EatSingleCharacterToken(TokenKind).
ValidateField(ResourceFieldAttribute, int)
Enables derived types to throw a QueryParseException when usage of a JSON:API field inside a field chain is not permitted.
protected virtual void ValidateField(ResourceFieldAttribute field, int position)
Parameters
field
ResourceFieldAttributeposition
int