1 // Copyright 2008 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 import edu.berkeley.sbp.*;
6 import edu.berkeley.sbp.misc.*;
7 import edu.berkeley.sbp.util.*;
8 import edu.berkeley.sbp.meta.*;
9 import edu.berkeley.sbp.chr.*;
13 private static CharParser parser = null;
14 private static Object ret;
15 public static void putBack(String o) { ret = o; }
16 public static Object getResult() { return ret; }
18 synchronized(Helper.class) {
21 File grammarFile = new File("src/wix.g");
22 Tree<String> res = new CharParser(GrammarAST.getMetaGrammar())
23 .parse(new FileInputStream(grammarFile)).expand1();
24 Union grammar = GrammarAST.buildFromAST(res, "s", new GrammarAST.ImportResolver() {
25 public InputStream getImportStream(String filename) {
26 return this.getClass().getClassLoader().getResourceAsStream(filename);
29 parser = new CharParser(grammar);
30 } catch (Exception e) {
31 throw new RuntimeException(e);
37 public static boolean isNull(Object o) { return o==null; }
38 public static Tree help(String targetFile) throws Throwable {
41 Reader r = new InputStreamReader(new FileInputStream(targetFile));
42 Input input = new CharInput(new IndentingReader(r, CharAtom.left, CharAtom.right));
43 ret = parser.parse(input).expand1();
44 } catch (Throwable e) {
48 if (ret==null) throw new NullPointerException("CharParser returned null");