Skip to content

Commit

Permalink
Change AST text property to function
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Nov 20, 2024
1 parent f6ea942 commit 5d25a5a
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 20 deletions.
14 changes: 12 additions & 2 deletions partiql-ast/api/partiql-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -2392,15 +2392,16 @@ public class org/partiql/ast/graph/GraphSelector$ShortestKGroup$Builder {
}

public abstract class org/partiql/ast/literal/Literal {
public final field text Ljava/lang/String;
protected fun <init> (Ljava/lang/String;)V
public fun <init> ()V
public abstract fun getText ()Ljava/lang/String;
}

public class org/partiql/ast/literal/LiteralBool : org/partiql/ast/literal/Literal {
public field value Z
public fun <init> (Z)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

Expand All @@ -2409,14 +2410,17 @@ public class org/partiql/ast/literal/LiteralDecimal : org/partiql/ast/literal/Li
public fun <init> (Ljava/math/BigDecimal;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralDouble : org/partiql/ast/literal/Literal {
public field text Ljava/lang/String;
public field value D
public fun <init> (Ljava/lang/String;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

Expand All @@ -2425,6 +2429,7 @@ public class org/partiql/ast/literal/LiteralInt : org/partiql/ast/literal/Litera
public fun <init> (I)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

Expand All @@ -2433,20 +2438,23 @@ public class org/partiql/ast/literal/LiteralLong : org/partiql/ast/literal/Liter
public fun <init> (J)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralMissing : org/partiql/ast/literal/Literal {
public fun <init> ()V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

public class org/partiql/ast/literal/LiteralNull : org/partiql/ast/literal/Literal {
public fun <init> ()V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

Expand All @@ -2455,6 +2463,7 @@ public class org/partiql/ast/literal/LiteralString : org/partiql/ast/literal/Lit
public fun <init> (Ljava/lang/String;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

Expand All @@ -2464,6 +2473,7 @@ public class org/partiql/ast/literal/LiteralTypedString : org/partiql/ast/litera
public fun <init> (Lorg/partiql/ast/DataType;Ljava/lang/String;)V
protected fun canEqual (Ljava/lang/Object;)Z
public fun equals (Ljava/lang/Object;)Z
public fun getText ()Ljava/lang/String;
public fun hashCode ()I
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@
*/
public abstract class Literal {
@NotNull
public final String text;

protected Literal(@NotNull String _text) {
this.text = _text;
}
public abstract String getText();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
Expand All @@ -10,7 +11,12 @@ public class LiteralBool extends Literal {
public boolean value;

public LiteralBool(boolean value) {
super(String.valueOf(value));
this.value = value;
}

@NotNull
@Override
public String getText() {
return Boolean.toString(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public class LiteralDecimal extends Literal {
public BigDecimal value;

public LiteralDecimal(@NotNull BigDecimal value) {
super(value.toString());
this.value = value;
}

@NotNull
@Override
public String getText() {
return value.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
public class LiteralDouble extends Literal {
public double value;

@NotNull
public String text;

public LiteralDouble(@NotNull String text) {
super(text);
this.text = text;
this.value = Double.parseDouble(text);
}

@NotNull
@Override
public String getText() {
return text;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
Expand All @@ -10,7 +11,12 @@ public class LiteralInt extends Literal {
public int value;

public LiteralInt(int value) {
super(String.format("%d", value));
this.value = value;
}

@NotNull
@Override
public String getText() {
return Integer.toString(value);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
Expand All @@ -10,7 +11,12 @@ public class LiteralLong extends Literal {
public long value;

public LiteralLong(long value) {
super(String.format("%d", value));
this.value = value;
}

@NotNull
@Override
public String getText() {
return Long.toString(value);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralMissing extends Literal {
public LiteralMissing() {
super("MISSING");
public LiteralMissing() {}

@NotNull
@Override
public String getText() {
return "MISSING";
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.partiql.ast.literal;

import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;

/**
* TODO docs
*/
@EqualsAndHashCode(callSuper = false)
public class LiteralNull extends Literal {
public LiteralNull() {
super("NULL");
public LiteralNull() {}

@NotNull
@Override
public String getText() {
return "NULL";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public class LiteralString extends Literal {
public String value;

public LiteralString(@NotNull String value) {
super(String.format("'%s'", value));
this.value = value;
}

@NotNull
@Override
public String getText() {
return String.format("'%s'", value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ public class LiteralTypedString extends Literal {
public String value;

public LiteralTypedString(@NotNull DataType type, @NotNull String value) {
super(String.format("%s '%s'", type.name(), value));
this.type = type;
this.value = value;
}

@NotNull
@Override
public String getText() {
return String.format("%s '%s'", type.name(), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import org.partiql.ast.Ast.literalInt
import org.partiql.ast.Ast.query
import org.partiql.ast.AstNode
import org.partiql.ast.expr.Expr
import org.partiql.value.PartiQLValueExperimental
import kotlin.test.assertEquals

@OptIn(PartiQLValueExperimental::class)
class PartiQLParserOperatorTests {

private val parser = PartiQLParserDefault()
Expand Down

0 comments on commit 5d25a5a

Please sign in to comment.