-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMapExpr.java
More file actions
38 lines (31 loc) · 933 Bytes
/
Copy pathMapExpr.java
File metadata and controls
38 lines (31 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cwp.ast;
import cwp.lexer.Token;
import java.util.ArrayList;
public class MapExpr extends Expr {
public ArrayList<Expr> args;
public MapExpr(Token initTok, ArrayList<Expr> a, boolean callable) {
super(initTok, callable);
this.args = a;
}
@Override
public String toString() {
return "MapExpr: " + initTok.toString();
}
@Override
public String gen() {
StringBuilder sb = new StringBuilder(initTok.str);
for (int i = 0; i < args.size() - 2; i += 2) {
sb.append(args.get(i).gen());
sb.append(" ");
sb.append(args.get(i + 1).gen());
sb.append(", ");
}
if (!args.isEmpty()) {
sb.append(args.get(args.size() - 2).gen());
sb.append(" ");
sb.append(args.get(args.size() - 1).gen());
}
sb.append("}");
return sb.toString();
}
}