+// Copyright 2008 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.misc.*;
+import edu.berkeley.sbp.util.*;
+import edu.berkeley.sbp.meta.*;
+import edu.berkeley.sbp.chr.*;
+import java.io.*;
+
+public class Helper {
+ private static CharParser parser = null;
+ private static Object ret;
+ public static void putBack(String o) { ret = o; }
+ public static Object getResult() { return ret; }
+ static {
+ synchronized(Helper.class) {
+ if (parser == null) {
+ try {
+ File grammarFile = new File("src/wix.g");
+ Tree<String> res = new CharParser(GrammarAST.getMetaGrammar())
+ .parse(new FileInputStream(grammarFile)).expand1();
+ Union grammar = GrammarAST.buildFromAST(res, "s", new GrammarAST.ImportResolver() {
+ public InputStream getImportStream(String filename) {
+ return this.getClass().getClassLoader().getResourceAsStream(filename);
+ }
+ });
+ parser = new CharParser(grammar);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+
+ public static boolean isNull(Object o) { return o==null; }
+ public static Tree help(String targetFile) throws Throwable {
+ Tree ret = null;
+ try {
+ Reader r = new InputStreamReader(new FileInputStream(targetFile));
+ Input input = new CharInput(new IndentingReader(r, CharAtom.left, CharAtom.right));
+ ret = parser.parse(input).expand1();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ throw e;
+ }
+ if (ret==null) throw new NullPointerException("CharParser returned null");
+ return ret;
+ }
+}
\ No newline at end of file