- All Superinterfaces:
Scope
A publicly available API for the internal parse context that allows for
parsing SQL fragements.
- Author:
- Lukas Eder
-
Method Summary
Modifier and TypeMethodDescriptioncharThe character at the currentposition().charcharacter(int pos)The character at positionposition(int).@NotNull ParserExceptionAn exception that can be thrown from the current position.@NotNull LanguageContextThe current language context.booleanparse(char c)Parse a single character or fail if it cannot be parsed.booleanParse a string or fail if it cannot be parsed.@NotNull ConditionParse aConditionexpression or fail if the current expression is not a condition.@NotNull DataType<?>Parse aDataTypeexpression or fail if the current expression is not a data type.@NotNull SQLDialectConvenient access toSettings.getParseDialect().@NotNull SQLDialectConvenient access toSettings.getParseDialect()'s family.@NotNull Field<?>Parse aFieldexpression or fail if the current expression is not a field.booleanparseFunctionNameIf(String name)Try parsing a function name.booleanparseFunctionNameIf(String... names)Try parsing any function name.@NotNull NameParse an (unqualified) identifier or fail if the current token is not an identifier.@Nullable NameTry parsing an (unqualified) identifier.booleanparseIf(char c)Try parsing a single character.booleanTry parsing a string.booleanparseKeyword(String keyword)Parse a keyword or fail if the keyword cannot be parsed.booleanparseKeyword(String... keywords)Parse any keyword or fail if none of the keywords could be parsed.booleanparseKeywordIf(String keyword)Try parsing a keyword.booleanparseKeywordIf(String... keywords)Try parsing any keyword.<T> @NotNull List<T>parseList(String separator, Function<? super ParseContext,? extends T> element)Convenience method to parse a list of at least 1 elements.<T> @NotNull List<T>parseList(Predicate<? super ParseContext> separator, Function<? super ParseContext,? extends T> element)Convenience method to parse a list of at least 1 elements.@NotNull NameParse a name (a qualified identifier) or fail if the current token is not a name.@Nullable NameTry parsing a name (a qualified identifier).<T> TparseParenthesised(char open, Function<? super ParseContext,? extends T> content, char close)Convenience method to parse parenthesised content.<T> TparseParenthesised(String open, Function<? super ParseContext,? extends T> content, String close)Convenience method to parse parenthesised content.<T> TparseParenthesised(Function<? super ParseContext,? extends T> content)Convenience method to parse parenthesised content.@NotNull LongParse a signed integer literal or fail if the current token is not a signed integer literal.@Nullable LongTry parsing an signed integer literal.@NotNull SortField<?>Parse aSortFieldexpression or fail if the current expression is not a sort field.@NotNull StringParse a string literal or fail if the current token is not a string literal.@Nullable StringTry parsing a string literal.@NotNull Table<?>Parse aTableexpression or fail if the current expression is not a table.@NotNull LongParse an unsigned integer literal or fail if the current token is not an unsigned integer literal.@Nullable LongTry parsing an unsigned integer literal.booleanpeek(char c)Peek at the next character.booleanPeek at the next characters.booleanpeekKeyword(String keyword)Peek at the next keyword.booleanpeekKeyword(String... keywords)Peek at the next keyword.intposition()The current position.booleanposition(int newPosition)Set the current position to a new one.
-
Method Details
-
parseDialect
Convenient access toSettings.getParseDialect(). -
parseFamily
Convenient access toSettings.getParseDialect()'s family. -
languageContext
The current language context. -
character
char character()The character at the currentposition(). -
character
char character(int pos)The character at positionposition(int). -
position
int position()The current position. -
position
boolean position(int newPosition)Set the current position to a new one.- Returns:
- Always returns true.
-
peek
boolean peek(char c)Peek at the next character.- Returns:
- Whether the next character is the expected one.
- See Also:
parse(char)
-
peek
Peek at the next characters.- Returns:
- Whether the next characters are the expected ones.
- See Also:
parse(String)
-
peekKeyword
Peek at the next keyword.- Returns:
- Whether the next keyword is the expected one.
- See Also:
parseKeywordIf(String)
-
peekKeyword
Peek at the next keyword.- Returns:
- Whether the next keyword is any of the expected ones.
- See Also:
peekKeyword(String),parseKeywordIf(String)
-
parse
Parse a single character or fail if it cannot be parsed.- Returns:
- Always returns true.
- Throws:
ParserException- if the character could not be parsed.
-
parseIf
boolean parseIf(char c)Try parsing a single character.- Returns:
- Whether the character could be parsed.
-
parse
Parse a string or fail if it cannot be parsed.- Returns:
- Always returns true.
- Throws:
ParserException- if the string could not be parsed.
-
parseIf
Try parsing a string.- Returns:
- Whether the string could be parsed.
-
parseKeyword
Parse a keyword or fail if the keyword cannot be parsed.The argument keyword should be in UPPER CASE and is allowed to contain spaces. Spaces separating keyword parts are interpreted as any arbitrary amount of whitespace. For example, when parsing
"ORDER BY", then"order by"will be parsed as well.- Returns:
- Always returns true.
- Throws:
ParserException- if the keyword could not be parsed.
-
parseKeywordIf
Try parsing a keyword.The argument keyword should be in UPPER CASE and is allowed to contain spaces. Spaces separating keyword parts are interpreted as any arbitrary amount of whitespace. For example, when parsing
"ORDER BY", then"order by"will be parsed as well.- Returns:
- Whether the keyword could be parsed.
-
parseKeywordIf
Try parsing any keyword.- Returns:
- Whether any of the keywords could be parsed.
-
parseKeyword
Parse any keyword or fail if none of the keywords could be parsed.- Returns:
- Always returns true.
- Throws:
ParserException- if none of the keywords could be parsed.
-
parseIdentifier
Parse an (unqualified) identifier or fail if the current token is not an identifier.- Returns:
- The parsed identifier.
- Throws:
ParserException- if no identifier could be parsed.
-
parseIdentifierIf
Try parsing an (unqualified) identifier.- Returns:
- The identifier if it could be parsed, or
nullif the current token is not an identifier.
-
parseName
Parse a name (a qualified identifier) or fail if the current token is not a name.- Returns:
- The parsed name.
- Throws:
ParserException- if no name could be parsed.
-
parseNameIf
Try parsing a name (a qualified identifier).- Returns:
- The name if it could be parsed, or
nullif the current token is not a name.
-
parseFunctionNameIf
Try parsing a function name.- Returns:
- Whether the function name could be parsed.
-
parseFunctionNameIf
Try parsing any function name.- Returns:
- Whether any function name could be parsed.
-
parseStringLiteral
Parse a string literal or fail if the current token is not a string literal.- Returns:
- The parsed string literal.
- Throws:
ParserException- if no string literal could be parsed.
-
parseStringLiteralIf
Try parsing a string literal.- Returns:
- The string literal if it could be parsed, or
nullif the current token is not a string literal.
-
parseUnsignedIntegerLiteral
Parse an unsigned integer literal or fail if the current token is not an unsigned integer literal.- Returns:
- The unsigned integer literal.
- Throws:
ParserException- if no unsigned integer literal could be parsed.
-
parseUnsignedIntegerLiteralIf
Try parsing an unsigned integer literal.- Returns:
- The unsigned integer literal if it could be parsed, or
nullif the current token is not an unsigned integer literal.
-
parseSignedIntegerLiteral
Parse a signed integer literal or fail if the current token is not a signed integer literal.- Returns:
- The signed integer literal.
- Throws:
ParserException- if no signed integer literal could be parsed.
-
parseSignedIntegerLiteralIf
Try parsing an signed integer literal.- Returns:
- The signed integer literal if it could be parsed, or
nullif the current token is not an signed integer literal.
-
parseDataType
Parse aDataTypeexpression or fail if the current expression is not a data type.- Returns:
- The data type.
- Throws:
ParserException- if no data type expression could be parsed.
-
parseField
Parse aFieldexpression or fail if the current expression is not a field.- Returns:
- The parsed field.
- Throws:
ParserException- if no field expression could be parsed.
-
parseSortField
Parse aSortFieldexpression or fail if the current expression is not a sort field.- Returns:
- The parsed sort field.
- Throws:
ParserException- if no sort field expression could be parsed.
-
parseCondition
Parse aConditionexpression or fail if the current expression is not a condition.- Returns:
- The parsed condition.
- Throws:
ParserException- if no condition expression could be parsed.
-
parseTable
Parse aTableexpression or fail if the current expression is not a table.- Returns:
- The parsed table.
- Throws:
ParserException- if no table expression could be parsed.
-
parseList
@NotNull <T> @NotNull List<T> parseList(String separator, Function<? super ParseContext,? extends T> element)Convenience method to parse a list of at least 1 elements. -
parseList
@NotNull <T> @NotNull List<T> parseList(Predicate<? super ParseContext> separator, Function<? super ParseContext,? extends T> element)Convenience method to parse a list of at least 1 elements. -
parseParenthesised
Convenience method to parse parenthesised content. -
parseParenthesised
<T> T parseParenthesised(char open, Function<? super ParseContext,? extends T> content, char close)Convenience method to parse parenthesised content. -
parseParenthesised
<T> T parseParenthesised(String open, Function<? super ParseContext,? extends T> content, String close)Convenience method to parse parenthesised content. -
exception
An exception that can be thrown from the current position.
-