Skip to content

Commit

Permalink
[v1][WIP] Replicate partiqlparser default with v1 AST
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Oct 22, 2024
1 parent 4fa3853 commit 6759a9c
Show file tree
Hide file tree
Showing 7 changed files with 2,405 additions and 4 deletions.
10 changes: 8 additions & 2 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -5737,7 +5737,7 @@ public abstract interface class org/partiql/ast/v1/AstVisitor {
public abstract fun visitTableRef (Lorg/partiql/ast/v1/FromTableRef;Ljava/lang/Object;)Ljava/lang/Object;
}

public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/Enum {
public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/AstNode, org/partiql/ast/v1/Enum {
public static final field BAG I
public static final field BIGINT I
public static final field BINARY_LARGE_OBJECT I
Expand Down Expand Up @@ -5814,6 +5814,8 @@ public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/Enum {
public static fun CLOB (I)Lorg/partiql/ast/v1/DataType;
public static fun DATE ()Lorg/partiql/ast/v1/DataType;
public static fun DEC ()Lorg/partiql/ast/v1/DataType;
public static fun DEC (I)Lorg/partiql/ast/v1/DataType;
public static fun DEC (II)Lorg/partiql/ast/v1/DataType;
public static fun DECIMAL ()Lorg/partiql/ast/v1/DataType;
public static fun DECIMAL (I)Lorg/partiql/ast/v1/DataType;
public static fun DECIMAL (II)Lorg/partiql/ast/v1/DataType;
Expand Down Expand Up @@ -5856,14 +5858,16 @@ public class org/partiql/ast/v1/DataType : org/partiql/ast/v1/Enum {
public static fun USER_DEFINED (Lorg/partiql/ast/v1/IdentifierChain;)Lorg/partiql/ast/v1/DataType;
public static fun VARCHAR ()Lorg/partiql/ast/v1/DataType;
public static fun VARCHAR (I)Lorg/partiql/ast/v1/DataType;
public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public fun children ()Ljava/util/Collection;
public fun code ()I
public fun getLength ()Ljava/lang/Integer;
public fun getName ()Lorg/partiql/ast/v1/IdentifierChain;
public fun getPrecision ()Ljava/lang/Integer;
public fun getScale ()Ljava/lang/Integer;
}

public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/Enum {
public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/AstNode, org/partiql/ast/v1/Enum {
public static final field DAY I
public static final field HOUR I
public static final field MINUTE I
Expand All @@ -5882,6 +5886,8 @@ public class org/partiql/ast/v1/DatetimeField : org/partiql/ast/v1/Enum {
public static fun TIMEZONE_MINUTE ()Lorg/partiql/ast/v1/DatetimeField;
public static fun UNKNOWN ()Lorg/partiql/ast/v1/DatetimeField;
public static fun YEAR ()Lorg/partiql/ast/v1/DatetimeField;
public fun accept (Lorg/partiql/ast/v1/AstVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public fun children ()Ljava/util/Collection;
public fun code ()I
}

Expand Down
27 changes: 26 additions & 1 deletion partiql-ast/src/main/java/org/partiql/ast/v1/DataType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.partiql.ast.v1;

public class DataType implements Enum {
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;

public class DataType extends AstNode implements Enum {
public static final int UNKNOWN = 0;
// <absent types>
public static final int NULL = 1;
Expand Down Expand Up @@ -158,6 +163,14 @@ public static DataType DEC() {
return new DataType(DEC);
}

public static DataType DEC(int precision) {
return new DataType(DEC, precision, null, null);
}

public static DataType DEC(int precision, int scale) {
return new DataType(DEC, precision, scale, null);
}

public static DataType NUMERIC() {
return new DataType(NUMERIC);
}
Expand Down Expand Up @@ -411,4 +424,16 @@ public Integer getLength() {
public IdentifierChain getName() {
return name;
}

// TODO ALAN -- decide if DataType should extend AstNode; if so, what will be `children` and `accept` definitions
@NotNull
@Override
public Collection<AstNode> children() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
18 changes: 17 additions & 1 deletion partiql-ast/src/main/java/org/partiql/ast/v1/DatetimeField.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package org.partiql.ast.v1;

import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;

/**
* TODO docs, equals, hashcode
*/
public class DatetimeField implements Enum {
public class DatetimeField extends AstNode implements Enum {
public static final int UNKNOWN = 0;
public static final int YEAR = 1;
public static final int MONTH = 2;
Expand Down Expand Up @@ -60,4 +65,15 @@ private DatetimeField(int code) {
public int code() {
return code;
}

@NotNull
@Override
public Collection<AstNode> children() {
return Collections.emptyList();
}

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return null;
}
}
32 changes: 32 additions & 0 deletions partiql-parser/api/partiql-parser.api
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,35 @@ public final class org/partiql/parser/SourceLocations : java/util/Map, kotlin/jv
public final fun values ()Ljava/util/Collection;
}

public abstract interface class org/partiql/parser/V1PartiQLParser {
public static final field Companion Lorg/partiql/parser/V1PartiQLParser$Companion;
public static fun builder ()Lorg/partiql/parser/V1PartiQLParserBuilder;
public abstract fun parse (Ljava/lang/String;)Lorg/partiql/parser/V1PartiQLParser$Result;
public static fun standard ()Lorg/partiql/parser/V1PartiQLParser;
}

public final class org/partiql/parser/V1PartiQLParser$Companion {
public final fun builder ()Lorg/partiql/parser/V1PartiQLParserBuilder;
public final fun standard ()Lorg/partiql/parser/V1PartiQLParser;
}

public final class org/partiql/parser/V1PartiQLParser$Result {
public fun <init> (Ljava/lang/String;Lorg/partiql/ast/v1/Statement;Lorg/partiql/parser/SourceLocations;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lorg/partiql/ast/v1/Statement;
public final fun component3 ()Lorg/partiql/parser/SourceLocations;
public final fun copy (Ljava/lang/String;Lorg/partiql/ast/v1/Statement;Lorg/partiql/parser/SourceLocations;)Lorg/partiql/parser/V1PartiQLParser$Result;
public static synthetic fun copy$default (Lorg/partiql/parser/V1PartiQLParser$Result;Ljava/lang/String;Lorg/partiql/ast/v1/Statement;Lorg/partiql/parser/SourceLocations;ILjava/lang/Object;)Lorg/partiql/parser/V1PartiQLParser$Result;
public fun equals (Ljava/lang/Object;)Z
public final fun getLocations ()Lorg/partiql/parser/SourceLocations;
public final fun getRoot ()Lorg/partiql/ast/v1/Statement;
public final fun getSource ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/parser/V1PartiQLParserBuilder {
public fun <init> ()V
public final fun build ()Lorg/partiql/parser/V1PartiQLParser;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.Statement
import org.partiql.parser.internal.V1PartiQLParserDefault

public interface V1PartiQLParser {

@Throws(PartiQLSyntaxException::class, InterruptedException::class)
public fun parse(source: String): Result

public data class Result(
val source: String,
val root: Statement,
val locations: SourceLocations,
)

public companion object {

@JvmStatic
public fun builder(): V1PartiQLParserBuilder = V1PartiQLParserBuilder()

@JvmStatic
public fun standard(): V1PartiQLParser = V1PartiQLParserDefault()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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].
*/
public class V1PartiQLParserBuilder {

public fun build(): V1PartiQLParser {
return V1PartiQLParserDefault()
}
}
Loading

0 comments on commit 6759a9c

Please sign in to comment.