Permalink
Browse files

more stuff

  • Loading branch information...
1 parent 3e6377e commit dc213827c064e729d2647e6da0b766c93bdab820 @michelegonella committed Oct 15, 2012
@@ -42,8 +42,8 @@ throw e;
program
: value
- | LvalTkn '@' value
- -> ^(TYPEDEF LvalTkn value)
+ | (LvalTkn '@' value)+
+ -> ^(TYPEDEF LvalTkn value)+
;
value
@@ -17,6 +17,7 @@
import java.io.StringReader;
import java.nio.channels.IllegalSelectorException;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -61,6 +62,31 @@ public JclValidatorFactory(String jclExpr) throws Exception {
public JsonTransformer getObject() {
Tree cur = root;
+ if(cur.getText() != null) {
+ return makeValueTransformer(cur);
+ } else {
+ int len = cur.getChildCount();
+ for(int i = 0; i < len; i++) {
+ Tree t = cur.getChild(i);
+ Check.illegalstate.assertEquals(TYPEDEF, t.getType());
+ String tname = t.getChild(0).getText();
+ JsonTransformer tx = makeValueTransformer(t.getChild(1));
+ addTypeToLibrary(tname, t, tx);
+ }
+ return getDefaultTypeTransfomer();
+ }
+ }
+
+ private JsonTransformer getDefaultTypeTransfomer() {
+ return tMap.entrySet().iterator().next().getValue();
+ }
+
+ private LinkedHashMap<String, JsonTransformer> tMap = new LinkedHashMap<String, JsonTransformer>();
+ private void addTypeToLibrary(String tname, Tree t, JsonTransformer tx) {
+ tMap.put(tname, tx);
+ }
+
+ private JsonTransformer makeValueTransformer(Tree cur) {
final Stack<EventConsumer> stack = new Stack<EventConsumer>();
stack.push(makeConsumer(cur, stack));
return new BaseJsonTransformer() {
@@ -37,25 +37,27 @@
@Test
public void testValid() throws Exception {
- valid("{}", "{}");
- invalid("{}", "{a:null}");
- valid("{a}", "{a:1}");
- valid("{a?}", "{}");
- invalid("{a}", "{}");
- valid("{c,a?,b}", "{b:1,c:2}");
- valid("{a!}", "{a:1}");
- invalid("{a!}", "{a:null}");
- valid("{a?:{}}", "{a:null}");
- invalid("{a!:{}}", "{a:null}");
- valid("{a!:{}}", "{a:{}}");
- invalid("{a!:{}}", "{a:2}");
- valid("{a,*}", "{b:{},a:1}");
- valid("{a,b:{*}}", "{b:{c:{d:1}},a:1}");
- valid("[]", "[]");
- valid("[b]", "[true]");
- invalid("[]", "[true]");
- invalid("[b,b]", "[true]");
- invalid("[b,b]", "[true,null,null]");
+// valid("{}", "{}");
+// invalid("{}", "{a:null}");
+// valid("{a}", "{a:1}");
+// valid("{a?}", "{}");
+// invalid("{a}", "{}");
+// valid("{c,a?,b}", "{b:1,c:2}");
+// valid("{a!}", "{a:1}");
+// invalid("{a!}", "{a:null}");
+// valid("{a?:{}}", "{a:null}");
+// invalid("{a!:{}}", "{a:null}");
+// valid("{a!:{}}", "{a:{}}");
+// invalid("{a!:{}}", "{a:2}");
+// valid("{a,*}", "{b:{},a:1}");
+// valid("{a,b:{*}}", "{b:{c:{d:1}},a:1}");
+// valid("[]", "[]");
+// valid("[b]", "[true]");
+// invalid("[]", "[true]");
+// invalid("[b,b]", "[true]");
+// invalid("[b,b]", "[true,null,null]");
+// valid("[b,b,*]", "[true,true,true,1]");
+ valid("MyType@[b] MyType2@[b]", "[true]");
}
private void invalid(String schema, String instance) throws Exception {

0 comments on commit dc21382

Please sign in to comment.