-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v1] Migrate parser to new AST (#1626)
- Loading branch information
Showing
16 changed files
with
3,053 additions
and
584 deletions.
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
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 { | ||
|
||
/** | ||
* 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() | ||
} | ||
} |
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.