-
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
Conversation
Conformance comparison report-Cross Engine
Number failing in both: 231 Number passing in legacy engine but fail in eval engine: 527 Number failing in legacy engine but pass in eval engine: 203 Conformance comparison report-Cross Commit-LEGACY
Number failing in both: 434 Number passing in Base (4dd0972) but now fail: 0 Number failing in Base (4dd0972) but now pass: 0 Conformance comparison report-Cross Commit-EVAL
Number failing in both: 758 Number passing in Base (4dd0972) but now fail: 1 Number failing in Base (4dd0972) but now pass: 1 Click here to see
Click here to see
|
val startTokenIndex = ctx.start.tokenIndex | ||
val endTokenIndex = ctx.stop.tokenIndex | ||
if (tokens.getHiddenTokensToRight(startTokenIndex, PartiQLTokens.HIDDEN) != null || tokens.getHiddenTokensToLeft(endTokenIndex, PartiQLTokens.HIDDEN) != null) { | ||
throw ParserException("Invalid bag expression", ErrorCode.PARSE_INVALID_QUERY) |
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
if (assertContext && (this@forEachTarget == ParserTarget.EXPERIMENTAL)) { | |
checkErrorAndErrorContext(errorCode, ex, expectErrorContextValues) | |
} |
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,
- ParserTarget.DEFAULT -> refers to parser for PIG AST
- ParserTarget.EXPERIMENTAL -> refers to parser for partiql-ast
The targets
parameter of checkInputThrowingParserException
is unused --
partiql-lang-kotlin/partiql-lang/src/test/kotlin/org/partiql/lang/syntax/PartiQLParserTestBase.kt
Line 155 in 4dd0972
targets: Array<ParserTarget> = arrayOf(ParserTarget.DEFAULT), |
targets
property defined for the abstract parser test class is used partiql-lang-kotlin/partiql-lang/src/test/kotlin/org/partiql/lang/syntax/PartiQLParserTestBase.kt
Line 38 in 4dd0972
open val targets = arrayOf(ParserTarget.DEFAULT) |
PartiQLParserTests
sets targets to both ParserTarget.DEFAULT
and ParserTarget.EXPERIMENTAL
.
This function currently just does two things:
- for
ParserTarget.EXPERIMENTAL
, check for an error and validate the error code + error context - for
ParserTarget.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
for v1
, 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.
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") | ||
} |
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 think we should also port the fix to the some of the binary ops.
Lines 1616 to 1624 in 4dd0972
GeneratedParser.ANGLE_LEFT -> { | |
if (ctx.stop.type == GeneratedParser.ANGLE_RIGHT) Expr.Binary.Op.NE | |
else Expr.Binary.Op.LT | |
} | |
GeneratedParser.LT_EQ -> Expr.Binary.Op.LTE | |
GeneratedParser.ANGLE_RIGHT -> Expr.Binary.Op.GT | |
GeneratedParser.GT_EQ -> Expr.Binary.Op.GTE | |
GeneratedParser.BANG -> Expr.Binary.Op.NE | |
GeneratedParser.EQ -> Expr.Binary.Op.EQ |
But feel free to leave this out for now.
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.
Yeah good catch, for <>
and !=
this is also an issue. In the operator PR #1499, I'll fix the issues in that PR since there is a refactoring of the special symbol parsing.
Relevant Issues
Description
v1
allowed for inserting whitespace and comments between the angle brackets of a bag constructor. This PR corrects the behavior and gives an error for these scenarios.I looked at some other alternatives such as
mode
in the lexer (similar to what Ion lexer rules we currently have)but decided to keep the recommendation of the ANTLR reference book.
Other Information
Updated Unreleased Section in CHANGELOG: [NO]
v1
branchAny backward-incompatible changes? [NO]
Any new external dependencies? [NO]
Do your changes comply with the Contributing Guidelines
and Code Style Guidelines? [YES]
License Information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.