- public static class TestCaseBuilder extends MetaGrammar {
- public Object walk(Tree<String> tree) {
- try {
- if ("grammar".equals(tree.head())) { walkChildren(tree); return done("s"); }
- else if ("output".equals(tree.head())) return string(tree.children());
- else if ("input".equals(tree.head())) return string(tree.children());
- else if ("tibcase".equals(tree.head()) || "testcase".equals(tree.head())) {
- String input = string(tree.child(0));
- String[] output = tree.numChildren()>2 ? ((String[])walk(tree, 1)) : new String[0];
- boolean tib = "tibcase".equals(tree.head());
- MetaGrammar gram = tib ? new Tib.Grammar() : new MetaGrammar();
- Union grammar = (Union)((MetaGrammar)(gram.walk(tree, tree.numChildren()-1))).done("s");
- return new TestCase(input, output, grammar, tib);
- } else if ("ts".equals(tree.head())) return walk(tree, 0);
- else return super.walk(tree);
- } catch (Exception e) {
- throw new Error(e);
- }