forked from senseidb/sensei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractCompiler.java
43 lines (32 loc) · 973 Bytes
/
AbstractCompiler.java
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
39
40
41
42
43
package com.senseidb.bql.parsers;
import org.antlr.v4.runtime.tree.ParseTree;
import org.json.JSONObject;
public abstract class AbstractCompiler {
public AbstractCompiler() {
super();
}
public abstract JSONObject compile(String expression);
public abstract String getErrorMessage(IllegalStateException ex);
protected void printTree(ParseTree ast) {
print(ast, 0);
}
private void print(ParseTree tree, int level) {
// Indent level
for (int i = 0; i < level; i++) {
System.out.print("--");
}
if (tree == null) {
System.out.println(" null tree.");
return;
}
// Print node description: type code followed by token text
// TODO: what "type" should print?
System.out.println(" " + "type?" + " " + tree.getText());
// Print all children
if (tree.getChildCount() != 0) {
for (int i = 0; i < tree.getChildCount(); i++) {
print(tree.getChild(i), level + 1);
}
}
}
}