1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp.misc;
5 import edu.berkeley.sbp.*;
6 import edu.berkeley.sbp.misc.*;
7 import edu.berkeley.sbp.meta.*;
8 import edu.berkeley.sbp.chr.*;
9 import edu.berkeley.sbp.tib.*;
12 public class HaskellHelper {
14 public static void main(String[] argv) throws Throwable {
15 help(argv[0], argv[1]);
17 public static boolean isNull(Object o) { return o==null; }
18 public static Tree help0(String grammarFile, String targetFile) throws Throwable {
20 Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(grammarFile)).expand1();
21 Union meta = Grammar.create(res, "s" /*,
22 new Grammar.Bindings() {
23 public Sequence createSequence(Production p) {
24 Element[] els = p.elements;
26 return Sequence.create(p.tag, p.elements, p.drops, false);
28 for(int i=0; i<els.length; i++)
31 else return Sequence.create(p.nonTerminal, p.elements, p.drops, false);
32 if (idx != -1) return Sequence.create(els, idx);
33 else return Sequence.create(els, "");
39 CharInput input = new CharInput(new FileInputStream(targetFile), "", true);
40 //Input input = new Tib(new FileInputStream(targetFile));
41 Tree ret = new CharParser(meta).parse(input).expand1();
42 if (ret==null) throw new NullPointerException("CharParser returned null");
44 } catch (Throwable e) {
49 public static Tree help(String grammarFile, String targetFile) throws Throwable {
51 Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(grammarFile)).expand1();
52 Union meta = Grammar.create(res, "s" /*,
53 new Grammar.Bindings() {
54 public Sequence createSequence(Production p) {
55 Element[] els = p.elements;
56 if (p.tag != null && !"".equals(p.tag))
57 return Sequence.create(p.tag, p.elements, p.drops, false);
59 for(int i=0; i<els.length; i++)
62 else return Sequence.create(p.nonTerminal, p.elements, p.drops, false);
63 if (idx != -1) return Sequence.create(els, idx);
64 else return Sequence.create(els, "");
70 //CharInput input = new CharInput(new FileInputStream(targetFile), "", true);
71 Input input = new Tib(new FileInputStream(targetFile));
72 Tree ret = new CharParser(meta).parse(input).expand1();
73 if (ret==null) throw new NullPointerException("CharParser returned null");
75 } catch (Throwable e) {