Skip to content
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] Add AST factory methods; some fixes to AST classes #1622

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 106 additions & 10 deletions partiql-ast/api/partiql-ast.api

Large diffs are not rendered by default.

481 changes: 481 additions & 0 deletions partiql-ast/src/main/java/org/partiql/ast/v1/Ast.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public interface AstVisitor<R, C> {

R visitSelectItem(SelectItem node, C ctx);

R visitSelectItemAll(SelectItem.Star node, C ctx);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(self-review) I forgot to change naming of this visitor function after the class was renamed.

R visitSelectItemStar(SelectItem.Star node, C ctx);

R visitSelectItemExpr(SelectItem.Expr node, C ctx);

Expand Down
10 changes: 5 additions & 5 deletions partiql-ast/src/main/java/org/partiql/ast/v1/QueryBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public static class SetOp extends QueryBody {
public Expr rhs;

public SetOp(@NotNull org.partiql.ast.v1.SetOp type, boolean isOuter, @NotNull Expr lhs, @NotNull Expr rhs) {
this.type = type;
this.isOuter = isOuter;
this.lhs = lhs;
this.rhs = rhs;
}
this.type = type;
this.isOuter = isOuter;
this.lhs = lhs;
this.rhs = rhs;
}

@NotNull
@Override
Expand Down
4 changes: 2 additions & 2 deletions partiql-ast/src/main/java/org/partiql/ast/v1/SelectItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class SelectItem extends AstNode {
@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
if (this instanceof Star) {
return visitor.visitSelectItemAll((Star) this, ctx);
return visitor.visitSelectItemStar((Star) this, ctx);
} else if (this instanceof Expr) {
return visitor.visitSelectItemExpr((Expr) this, ctx);
} else {
Expand Down Expand Up @@ -45,7 +45,7 @@ public Collection<AstNode> children() {

@Override
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
return visitor.visitSelectItemAll(this, ctx);
return visitor.visitSelectItemStar(this, ctx);
}
}

Expand Down
32 changes: 24 additions & 8 deletions partiql-ast/src/main/java/org/partiql/ast/v1/graph/GraphLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
*/
@Builder(builderClassName = "Builder")
public static class Wildcard extends GraphLabel {
public Wildcard() {}

@Override
@NotNull
public Collection<AstNode> children() {
Expand Down Expand Up @@ -103,16 +105,23 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
@Builder(builderClassName = "Builder")
public static class Conj extends GraphLabel {
@NotNull
public final List<GraphLabel> args;
public final GraphLabel lhs;

@NotNull
public final GraphLabel rhs;

public Conj(@NotNull List<GraphLabel> args) {
this.args = args;
public Conj(@NotNull GraphLabel lhs, @NotNull GraphLabel rhs) {
this.lhs = lhs;
this.rhs = rhs;
}

@Override
@NotNull
public Collection<AstNode> children() {
return new ArrayList<>(args);
List<AstNode> kids = new ArrayList<>();
kids.add(lhs);
kids.add(rhs);
return kids;
}

@Override
Expand All @@ -127,16 +136,23 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
@Builder(builderClassName = "Builder")
public static class Disj extends GraphLabel {
@NotNull
public final List<GraphLabel> args;
public final GraphLabel lhs;

public Disj(@NotNull List<GraphLabel> args) {
this.args = args;
@NotNull
public final GraphLabel rhs;

public Disj(@NotNull GraphLabel lhs, @NotNull GraphLabel rhs) {
this.lhs = lhs;
this.rhs = rhs;
}

@Override
@NotNull
public Collection<AstNode> children() {
return new ArrayList<>(args);
List<AstNode> kids = new ArrayList<>();
kids.add(lhs);
kids.add(rhs);
return kids;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
*/
@Builder(builderClassName = "Builder")
public class GraphQuantifier extends AstNode {
@NotNull
public final Long lower;
Comment on lines -17 to -18
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(self-review) type could just be primitive long.

public final long lower;

@Nullable
public final Long upper;

public GraphQuantifier(@NotNull Long lower, @Nullable Long upper) {
public GraphQuantifier(long lower, @Nullable Long upper) {
this.lower = lower;
this.upper = upper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
*/
@Builder(builderClassName = "Builder")
public static class AnyShortest extends GraphSelector {
public AnyShortest() {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(self-review) some missing constructors in the graph/ directory.


@Override
@NotNull
public Collection<AstNode> children() {
Expand All @@ -53,6 +55,8 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
*/
@Builder(builderClassName = "Builder")
public static class AllShortest extends GraphSelector {
public AllShortest() {}

@Override
@NotNull
public Collection<AstNode> children() {
Expand All @@ -70,6 +74,8 @@ public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
*/
@Builder(builderClassName = "Builder")
public static class Any extends GraphSelector {
public Any() {}

@Override
@NotNull
public Collection<AstNode> children() {
Expand Down
Loading