-
Notifications
You must be signed in to change notification settings - Fork 63
Fixes parser for the top level tokens #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7d7e2e9
caebc9f
1a8ed3d
fec50de
a9de025
f375d2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2254,19 +2254,19 @@ class SqlParser(private val ion: IonSystem) : Parser { | |
} | ||
|
||
private fun ParseNode.throwTopLevelParserError(): Nothing = | ||
token?.err("Keyword $token only expected at the top level in the query", PARSE_UNEXPECTED_TERM) | ||
?: throw ParserException("Keyword $token only expected at the top level in the query", PARSE_UNEXPECTED_TERM, PropertyValueMap()) | ||
token?.err("Keyword ${token.text} only expected at the top level in the query", PARSE_UNEXPECTED_TERM) | ||
?: throw ParserException("Keyword ${token?.text} only expected at the top level in the query", PARSE_UNEXPECTED_TERM, PropertyValueMap()) | ||
|
||
/** | ||
* Validates tree to make sure that the top level tokens are not found below the top level | ||
* Validates tree to make sure that the top level tokens are not found below the top level. | ||
* Top level tokens are the tokens or keywords which are valid to be used only at the top level in the query. | ||
* i.e. these tokens cannot be used with a mix of other commands. Hence if more than one top level tokens are found | ||
* in the query then it is invalid. | ||
* [level] is the current traversal level in the parse tree. | ||
* If [topLevelTokenSeen] is true, it means it has been encountered at least once before while traversing the parse tree. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: description of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the variable name itself tells it all. |
||
*/ | ||
private fun validateTopLevelNodes(node: ParseNode, level: Int, topLevelTokens: Int) { | ||
val topTokens = topLevelTokens + when(node.type.isTopLevelType) { | ||
true -> 1 | ||
false -> 0 | ||
} | ||
|
||
if (topTokens > 1) { | ||
private fun validateTopLevelNodes(node: ParseNode, level: Int, topLevelTokenSeen: Boolean) { | ||
if (topLevelTokenSeen && node.type.isTopLevelType) { | ||
node.throwTopLevelParserError() | ||
} | ||
|
||
|
@@ -2280,7 +2280,7 @@ class SqlParser(private val ion: IonSystem) : Parser { | |
node.throwTopLevelParserError() | ||
} | ||
} | ||
node.children.map { validateTopLevelNodes(it, level + 1, topTokens) } | ||
node.children.map { validateTopLevelNodes(node = it, level = level + 1, topLevelTokenSeen = topLevelTokenSeen || node.type.isTopLevelType) } | ||
} | ||
|
||
/** Entry point into the parser. */ | ||
|
@@ -2296,7 +2296,7 @@ class SqlParser(private val ion: IonSystem) : Parser { | |
} | ||
} | ||
|
||
validateTopLevelNodes(node, 0, 0) | ||
validateTopLevelNodes(node = node, level = 0, topLevelTokenSeen = false) | ||
|
||
return node.toExprNode() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "i.e. these tokens cannot be used with a mix of other
commandstop level tokens"? "commands" seems too generalized.