Skip to content

Commit a961690

Browse files
authored
Merge pull request #45 from kcl-lang/fix-kcl-java-ast
fix: kcl java ast structures
2 parents e7c6457 + 1fb6dac commit a961690

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

java/src/main/java/com/kcl/ast/CheckExpr.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
* }
1313
* </pre>
1414
*/
15-
@JsonTypeName("Check")
16-
public class CheckExpr extends Expr {
15+
public class CheckExpr {
1716
@JsonProperty("test")
1817
private NodeRef<Expr> test;
1918

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.kcl.ast;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.util.List;
5+
6+
/**
7+
* Decorator, e.g.
8+
*
9+
* <pre>
10+
* {@code
11+
* deprecated(strict=True)
12+
* }
13+
* </pre>
14+
*/
15+
public class Decorator {
16+
@JsonProperty("func")
17+
private NodeRef<Expr> func;
18+
19+
@JsonProperty("args")
20+
private List<NodeRef<Expr>> args;
21+
22+
@JsonProperty("keywords")
23+
private List<NodeRef<Keyword>> keywords;
24+
25+
public NodeRef<Expr> getFunc() {
26+
return func;
27+
}
28+
29+
public void setFunc(NodeRef<Expr> func) {
30+
this.func = func;
31+
}
32+
33+
public List<NodeRef<Expr>> getArgs() {
34+
return args;
35+
}
36+
37+
public void setArgs(List<NodeRef<Expr>> args) {
38+
this.args = args;
39+
}
40+
41+
public List<NodeRef<Keyword>> getKeywords() {
42+
return keywords;
43+
}
44+
45+
public void setKeywords(List<NodeRef<Keyword>> keywords) {
46+
this.keywords = keywords;
47+
}
48+
}

java/src/main/java/com/kcl/ast/Expr.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
@JsonSubTypes.Type(value = CompClause.class, name = "CompClause"),
2323
@JsonSubTypes.Type(value = SchemaExpr.class, name = "Schema"),
2424
@JsonSubTypes.Type(value = ConfigExpr.class, name = "Config"),
25-
@JsonSubTypes.Type(value = CheckExpr.class, name = "Check"),
2625
@JsonSubTypes.Type(value = LambdaExpr.class, name = "Lambda"),
2726
@JsonSubTypes.Type(value = Subscript.class, name = "Subscript"),
2827
@JsonSubTypes.Type(value = Compare.class, name = "Compare"),

java/src/main/java/com/kcl/ast/SchemaAttr.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SchemaAttr extends Stmt {
3333
private boolean isOptional;
3434

3535
@JsonProperty("decorators")
36-
private List<NodeRef<CallExpr>> decorators;
36+
private List<NodeRef<Decorator>> decorators;
3737

3838
@JsonProperty("ty")
3939
private NodeRef<Type> ty;
@@ -78,11 +78,11 @@ public void setOptional(boolean isOptional) {
7878
this.isOptional = isOptional;
7979
}
8080

81-
public List<NodeRef<CallExpr>> getDecorators() {
81+
public List<NodeRef<Decorator>> getDecorators() {
8282
return decorators;
8383
}
8484

85-
public void setDecorators(List<NodeRef<CallExpr>> decorators) {
85+
public void setDecorators(List<NodeRef<Decorator>> decorators) {
8686
this.decorators = decorators;
8787
}
8888

java/src/main/java/com/kcl/ast/SchemaStmt.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class SchemaStmt extends Stmt {
5555
private List<NodeRef<Stmt>> body;
5656

5757
@JsonProperty("decorators")
58-
private List<NodeRef<CallExpr>> decorators;
58+
private List<NodeRef<Decorator>> decorators;
5959

6060
@JsonProperty("checks")
6161
private List<NodeRef<CheckExpr>> checks;
@@ -135,11 +135,11 @@ public void setBody(List<NodeRef<Stmt>> body) {
135135
this.body = body;
136136
}
137137

138-
public List<NodeRef<CallExpr>> getDecorators() {
138+
public List<NodeRef<Decorator>> getDecorators() {
139139
return decorators;
140140
}
141141

142-
public void setDecorators(List<NodeRef<CallExpr>> decorators) {
142+
public void setDecorators(List<NodeRef<Decorator>> decorators) {
143143
this.decorators = decorators;
144144
}
145145

java/src/main/java/com/kcl/ast/StringLit.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ public class StringLit extends Expr {
1818
private String rawValue;
1919
private String value;
2020

21+
public StringLit() {
22+
this.value = "";
23+
this.rawValue = "\"\"";
24+
this.isLongString = false;
25+
}
26+
2127
// Constructor that replicates the TryFrom implementation in Rust
22-
public StringLit(String value) {
28+
public StringLit(String value, String rawValue, boolean isLongString) {
2329
this.value = value;
24-
this.rawValue = String.format("%s", value); // Adding quotes, escaping, etc., if needed
25-
this.isLongString = false; // Determine based on actual logic (e.g., presence of line breaks)
30+
this.rawValue = rawValue;
31+
this.isLongString = isLongString;
2632
}
2733

2834
public boolean isLongString() {

0 commit comments

Comments
 (0)