-
Notifications
You must be signed in to change notification settings - Fork 62
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
[v1] Migrate parser to new AST #1626
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,7 +358,7 @@ excludeExprSteps | |
; | ||
|
||
fromClause | ||
: FROM tableReference; | ||
: FROM ( tableReference ( COMMA tableReference)* ); | ||
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. Made some ANTLR grammar changes to account for the new modeling of |
||
|
||
whereClauseSelect | ||
: WHERE arg=exprSelect; | ||
|
@@ -468,16 +468,16 @@ edgeAbbrev | |
*/ | ||
|
||
tableReference | ||
: lhs=tableReference joinType? CROSS JOIN rhs=joinRhs # TableCrossJoin | ||
| lhs=tableReference COMMA rhs=joinRhs # TableCrossJoin | ||
| lhs=tableReference joinType? JOIN rhs=joinRhs joinSpec # TableQualifiedJoin | ||
| tableNonJoin # TableRefBase | ||
| PAREN_LEFT tableReference PAREN_RIGHT # TableWrapped | ||
: tablePrimary # TableRefPrimary | ||
| lhs=tableReference LEFT CROSS JOIN rhs=tablePrimary # TableLeftCrossJoin // PartiQL spec defines LEFT CROSS JOIN; other variants are not defined yet | ||
| lhs=tableReference CROSS JOIN rhs=tablePrimary # TableCrossJoin // SQL99 defines just CROSS JOIN | ||
| lhs=tableReference joinType? JOIN rhs=tableReference joinSpec # TableQualifiedJoin | ||
; | ||
|
||
tableNonJoin | ||
tablePrimary | ||
: tableBaseReference | ||
| tableUnpivot | ||
| tableWrapped | ||
; | ||
|
||
tableBaseReference | ||
|
@@ -487,15 +487,11 @@ tableBaseReference | |
; | ||
|
||
tableUnpivot | ||
: UNPIVOT expr asIdent? atIdent? byIdent?; | ||
|
||
joinRhs | ||
: tableNonJoin # JoinRhsBase | ||
| PAREN_LEFT tableReference PAREN_RIGHT # JoinRhsTableJoined | ||
: UNPIVOT expr asIdent? atIdent? byIdent? | ||
; | ||
|
||
joinSpec | ||
: ON expr; | ||
tableWrapped | ||
: PAREN_LEFT tableReference PAREN_RIGHT; | ||
|
||
joinType | ||
: mod=INNER | ||
|
@@ -505,6 +501,9 @@ joinType | |
| mod=OUTER | ||
; | ||
|
||
joinSpec | ||
: ON expr; | ||
|
||
/** | ||
* | ||
* EXPRESSIONS & PRECEDENCE | ||
|
72 changes: 72 additions & 0 deletions
72
partiql-parser/src/main/kotlin/org/partiql/parser/V1PartiQLParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at: | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package org.partiql.parser | ||
|
||
import org.partiql.ast.v1.Query | ||
import org.partiql.ast.v1.Statement | ||
import org.partiql.ast.v1.expr.ExprLit | ||
import org.partiql.parser.internal.V1PartiQLParserDefault | ||
import org.partiql.spi.Context | ||
import org.partiql.spi.errors.PErrorListenerException | ||
import org.partiql.value.PartiQLValueExperimental | ||
import org.partiql.value.nullValue | ||
|
||
// TODO migrate public interfaces and classes to Java https://github.com/partiql/partiql-lang-kotlin/issues/1632 | ||
public interface V1PartiQLParser { | ||
alancai98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Parses the [source] into an AST. | ||
* @param source the user's input | ||
* @param ctx a configuration object for the parser | ||
* @throws PErrorListenerException when the [org.partiql.spi.errors.PErrorListener] defined in the [ctx] throws an | ||
* [PErrorListenerException], this method halts execution and propagates the exception. | ||
*/ | ||
@Throws(PErrorListenerException::class) | ||
public fun parse(source: String, ctx: Context): Result | ||
|
||
/** | ||
* Parses the [source] into an AST. | ||
* @param source the user's input | ||
* @throws PErrorListenerException when the [org.partiql.spi.errors.PErrorListener] defined in the context throws an | ||
* [PErrorListenerException], this method halts execution and propagates the exception. | ||
*/ | ||
@Throws(PErrorListenerException::class) | ||
public fun parse(source: String): Result { | ||
return parse(source, Context.standard()) | ||
} | ||
|
||
public data class Result( | ||
val source: String, | ||
val root: Statement, | ||
val locations: SourceLocations, | ||
) { | ||
public companion object { | ||
@OptIn(PartiQLValueExperimental::class) | ||
internal fun empty(source: String): Result { | ||
val locations = SourceLocations.Mutable().toMap() | ||
return Result(source, Query(ExprLit(nullValue())), locations) | ||
} | ||
} | ||
} | ||
|
||
public companion object { | ||
|
||
@JvmStatic | ||
public fun builder(): V1PartiQLParserBuilder = V1PartiQLParserBuilder() | ||
|
||
@JvmStatic | ||
public fun standard(): V1PartiQLParser = V1PartiQLParserDefault() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
partiql-parser/src/main/kotlin/org/partiql/parser/V1PartiQLParserBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at: | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package org.partiql.parser | ||
|
||
import org.partiql.parser.internal.V1PartiQLParserDefault | ||
|
||
/** | ||
* A builder class to instantiate a [V1PartiQLParser]. https://github.com/partiql/partiql-lang-kotlin/issues/1632 | ||
* | ||
* TODO replace with Lombok builder once [V1PartiQLParser] is migrated to Java. | ||
*/ | ||
public class V1PartiQLParserBuilder { | ||
|
||
public fun build(): V1PartiQLParser { | ||
return V1PartiQLParserDefault() | ||
} | ||
} | ||
alancai98 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was an error in the original PR adding the hand-written ASTs. The
lhs
andrhs
should have beenFromTableRef
s.