removed TibDoc/Haskell stuff
[sbp.git] / src / edu / berkeley / sbp / misc / HaskellHelper.java
1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
2
3 package edu.berkeley.sbp.misc;
4
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.*;
10 import java.io.*;
11
12 public class HaskellHelper {
13
14     public static void main(String[] argv) throws Throwable {
15         help(argv[0], argv[1]);
16     }
17     public static boolean isNull(Object o) { return o==null; }
18     public static Tree help0(String grammarFile, String targetFile) throws Throwable {
19         try {
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                                             
24                                             public Sequence createSequence(Production p) {
25                                                 Element[] els = p.elements;
26                                                 if (p.tag != null)
27                                                     return Sequence.create(p.tag, p.elements, p.drops, false);
28                                                 int idx = -1;
29                                                 for(int i=0; i<els.length; i++)
30                                                     if (!p.drops[i])
31                                                         if (idx==-1) idx = 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);
35                                             }
36                                             
37                                         });
38             System.out.println();
39             System.out.println();
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");
44             return ret;
45         } catch (Throwable e) {
46             e.printStackTrace();
47             throw e;
48         }
49     }
50     public static Tree help(String grammarFile, String targetFile) throws Throwable {
51         try {
52             Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(grammarFile)).expand1();
53             Union meta = Grammar.create(res, "s",
54                                         new Grammar.Bindings() {
55                                             
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);
60                                                 int idx = -1;
61                                                 for(int i=0; i<els.length; i++)
62                                                     if (!p.drops[i])
63                                                         if (idx==-1) idx = 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);
67                                             }
68                                             
69                                         });
70             System.out.println();
71             System.out.println();
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");
76             return ret;
77         } catch (Throwable e) {
78             e.printStackTrace();
79             throw e;
80         }
81     }
82
83
84 }