-
Notifications
You must be signed in to change notification settings - Fork 63
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
Fix bag constructor parsing #1500
Changes from all commits
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 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -425,6 +425,7 @@ internal class PartiQLParserDefault : PartiQLParser { | |||||||||||||||||||
*/ | ||||||||||||||||||||
@OptIn(PartiQLValueExperimental::class) | ||||||||||||||||||||
private class Visitor( | ||||||||||||||||||||
private val tokens: CommonTokenStream, | ||||||||||||||||||||
private val locations: SourceLocations.Mutable, | ||||||||||||||||||||
private val parameters: Map<Int, Int> = mapOf(), | ||||||||||||||||||||
) : PartiQLParserBaseVisitor<AstNode>() { | ||||||||||||||||||||
|
@@ -442,7 +443,7 @@ internal class PartiQLParserDefault : PartiQLParser { | |||||||||||||||||||
tree: GeneratedParser.RootContext, | ||||||||||||||||||||
): PartiQLParser.Result { | ||||||||||||||||||||
val locations = SourceLocations.Mutable() | ||||||||||||||||||||
val visitor = Visitor(locations, tokens.parameterIndexes) | ||||||||||||||||||||
val visitor = Visitor(tokens, locations, tokens.parameterIndexes) | ||||||||||||||||||||
val root = visitor.visitAs<AstNode>(tree) as Statement | ||||||||||||||||||||
return PartiQLParser.Result( | ||||||||||||||||||||
source = source, | ||||||||||||||||||||
|
@@ -2022,6 +2023,12 @@ internal class PartiQLParserDefault : PartiQLParser { | |||||||||||||||||||
*/ | ||||||||||||||||||||
|
||||||||||||||||||||
override fun visitBag(ctx: GeneratedParser.BagContext) = translate(ctx) { | ||||||||||||||||||||
// Prohibit hidden characters between angle brackets | ||||||||||||||||||||
val startTokenIndex = ctx.start.tokenIndex | ||||||||||||||||||||
val endTokenIndex = ctx.stop.tokenIndex | ||||||||||||||||||||
if (tokens.getHiddenTokensToRight(startTokenIndex, GeneratedLexer.HIDDEN) != null || tokens.getHiddenTokensToLeft(endTokenIndex, GeneratedLexer.HIDDEN) != null) { | ||||||||||||||||||||
throw error(ctx, "Invalid bag expression") | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+2027
to
+2031
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 think we should also port the fix to the some of the binary ops. Lines 1616 to 1624 in 4dd0972
But feel free to leave this out for now. 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. Yeah good catch, for |
||||||||||||||||||||
val expressions = visitOrEmpty<Expr>(ctx.expr()) | ||||||||||||||||||||
exprCollection(Expr.Collection.Type.BAG, expressions) | ||||||||||||||||||||
} | ||||||||||||||||||||
|
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.
It is a little weird that two error code does not match:
PARSE_INVALID_QUERY and PARSE_UNEXPECTED_TOKEN below.
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.
partiql-lang-kotlin/partiql-lang/src/test/kotlin/org/partiql/lang/syntax/PartiQLParserTestBase.kt
Lines 164 to 166 in 4dd0972
Here if I remembered correctly the error code has not been implemented for the experimental parser and hence it should be a not equal operation.
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.
I was a bit tripped up by this testing method's (
checkInputThrowingParserException
) logic. For clarity,The
targets
parameter ofcheckInputThrowingParserException
is unused --partiql-lang-kotlin/partiql-lang/src/test/kotlin/org/partiql/lang/syntax/PartiQLParserTestBase.kt
Line 155 in 4dd0972
targets
property defined for the abstract parser test class is usedpartiql-lang-kotlin/partiql-lang/src/test/kotlin/org/partiql/lang/syntax/PartiQLParserTestBase.kt
Line 38 in 4dd0972
PartiQLParserTests
sets targets to bothParserTarget.DEFAULT
andParserTarget.EXPERIMENTAL
.This function currently just does two things:
ParserTarget.EXPERIMENTAL
, check for an error and validate the error code + error contextParserTarget.DEFAULT
, check for an error and do NO further validations.That is why the error codes differ between the two error tests and why the error tests use the
ParserTarget.EXPERIMENTAL
error code,PARSE_UNEXPECTED_TOKEN
.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.
Since we're going to get rid of
ParserTarget.DEFAULT
forv1
, I didn't want to alter the testing infrastructure further. I'll leave the tests as they are and add a couple comments for clarity.