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() {
24 public Sequence createSequence(Production p) {
25 Element[] els = p.elements;
27 return Sequence.create(p.tag, p.elements, p.drops, false);
29 for(int i=0; i<els.length; i++)
32 else return Sequence.create(p.nonTerminal, p.elements, p.drops, false);
33 if (idx != -1) return Sequence.create(els, idx);
34 else return Sequence.create(els, null);
40 CharInput input = new CharInput(new FileInputStream(targetFile), "", true);
41 //Input input = new Tib(new FileInputStream(targetFile));
42 Tree ret = new CharParser(meta).parse(input).expand1();
43 if (ret==null) throw new NullPointerException("CharParser returned null");
45 } catch (Throwable e) {
50 public static Tree help(String grammarFile, String targetFile) throws Throwable {
52 Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(grammarFile)).expand1();
53 Union meta = Grammar.create(res, "s",
54 new Grammar.Bindings() {
56 public Sequence createSequence(Production p) {
57 Element[] els = p.elements;
58 if (p.tag != null && !"".equals(p.tag))
59 return Sequence.create(p.tag, p.elements, p.drops, false);
61 for(int i=0; i<els.length; i++)
64 else return Sequence.create(p.nonTerminal, p.elements, p.drops, false);
65 if (idx != -1) return Sequence.create(els, idx);
66 else return Sequence.create(els, null);
72 //CharInput input = new CharInput(new FileInputStream(targetFile), "", true);
73 Input input = new Tib(new FileInputStream(targetFile));
74 Tree ret = new CharParser(meta).parse(input).expand1();
75 if (ret==null) throw new NullPointerException("CharParser returned null");
77 } catch (Throwable e) {