bd9cb7e5b1a90e251607bff17e973ea903059647
[sbp.git] / src / edu / berkeley / sbp / tib / TibDoc.java
1 // Copyright 2005 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.
4
5 package edu.berkeley.sbp.tib;
6 import edu.berkeley.sbp.*;
7 import edu.berkeley.sbp.misc.*;
8 import edu.berkeley.sbp.util.*;
9 import edu.berkeley.sbp.chr.*;
10 import edu.berkeley.sbp.bind.*;
11 import java.util.*;
12 import java.io.*;
13 import static edu.berkeley.sbp.misc.Demo.*;
14
15 public class TibDoc {
16     /*
17     public static Text lf()     { Chars ret = new Chars(); ret.text = "\n"; return ret; }
18     public static Text cr()     { Chars ret = new Chars(); ret.text = "\r"; return ret; }
19     public static Text emdash() { return new Entity("mdash"); }
20     public static char urlescape(int a, int b) { return (char)(10*a+b); }
21
22
23     // Template Classes //////////////////////////////////////////////////////////////////////////////
24
25     public static abstract class Text implements ToHTML {
26         public static final Class[] subclasses = new Class[] { Chars.class, URL.class, Email.class };
27         public void toHTML(ToHTML.HTML sb) { }
28         public static class TextString extends Text {
29             public String text;
30             public String tag() { return null; }
31             public void toHTML(ToHTML.HTML sb) { sb.tag(tag(), text); }
32         }
33         public static class TextArray extends Text {
34             public Text[] t;
35             public String tag() { return null; }
36             public void toHTML(ToHTML.HTML sb) { sb.tag(tag(), t); }
37         }
38     }
39
40
41     // Structural //////////////////////////////////////////////////////////////////////////////
42
43     public static class Doc implements ToHTML {
44         public Header head;
45         public Body   body;
46         public void toHTML(ToHTML.HTML sb) { sb.tag("html", body); }
47         public static class Header extends HashMap<String, Text[]> {
48             public static class KeyVal { public String key; public Text[] val; }
49             public void attrs(KeyVal[] KeyVals) { for(int i=0; i<KeyVals.length; i++) this.put(KeyVals[i].key, KeyVals[i].val); }
50         }
51         public static class Body implements ToHTML {
52             public Section[] sections;
53             public void toHTML(ToHTML.HTML sb) { sb.append(sections); }
54             public static class Section implements ToHTML {
55                 public Text header;
56                 public Paragraph[] paragraphs;
57                 public void toHTML(ToHTML.HTML sb) {
58                     sb.tag("h3", header);
59                     sb.append(paragraphs);
60                 }
61             }
62         }
63     }
64
65
66     // Paragraph //////////////////////////////////////////////////////////////////////////////
67
68     public static interface Paragraph extends ToHTML {
69         public static final Class[] subclasses = new Class[] { Blockquote.class, P.class, HR.class };
70         public static class HR                                implements Paragraph { public void toHTML(ToHTML.HTML sb) { sb.append("\n<hr>\n"); } }
71         public static class P          extends Text.TextArray implements Paragraph { public String tag() { return "p"; } }
72         public static class Blockquote extends Text.TextArray implements Paragraph { public String tag() { return "blockquote"; } }
73     }
74
75     public static abstract class List extends Text {
76         public Text[][] points;
77         public abstract String tag();
78         public void toHTML(ToHTML.HTML sb) {
79             sb.append("<"+tag()+">\n");
80             for(Text[] t : points) sb.tag("li", t);
81             sb.append("</"+tag()+">\n");
82         }
83     }
84     public static class OL extends List { public String tag() { return "ol"; } }
85     public static class UL extends List { public String tag() { return "ul"; } }
86
87
88
89     // Tags //////////////////////////////////////////////////////////////////////////////
90
91     public static class Chars         extends Text.TextString { }
92     public static class Symbol        extends Text.TextString { }
93     public static class Keyword       extends Text.TextString { public String tag() { return "tt"; } }
94     public static class Subscript     extends Text.TextString { public String tag() { return "sub"; } }
95     public static class Superscript   extends Text.TextString { public String tag() { return "super"; } }
96     public static class Bold          extends Text.TextArray  { public String tag() { return "b"; } }
97     public static class Smallcap      extends Text.TextArray  { public String tag() { return "sc"; } }
98     public static class Strikethrough extends Text.TextArray  { public String tag() { return "strike"; } }
99     public static class TT            extends Text.TextArray  { public String tag() { return "tt"; } }
100     public static class Underline     extends Text.TextArray  { public String tag() { return "u"; } }
101     public static class Italic        extends Text.TextArray  { public String tag() { return "i"; } }
102     public static class Citation      extends Text.TextArray  { } // FIXME
103     public static class Footnote      extends Text.TextArray  { } // FIXME
104     public static class LineBreak     extends Text            { public void toHTML(ToHTML.HTML sb) { sb.tag("br"); } }
105     public static class Today         extends Text            { }
106     public static class Euro          extends Text            { public void toHTML(ToHTML.HTML sb) { sb.entity(8364); } }
107     public static class Link          extends Text {
108         public Text[] text;
109         public URI href;
110         public void toHTML(ToHTML.HTML sb) { sb.tag("a", new Object[] { "href", href }, text); }
111     }
112     public static class Entity        extends Text {
113         public final String entity;
114         public Entity(String entity) { this.entity = entity; }
115         public void toHTML(ToHTML.HTML sb) { sb.entity(entity); }
116     }
117
118
119     // Network //////////////////////////////////////////////////////////////////////////////
120
121     public static interface Host extends ToHTML {
122         public static class DNS implements Host {
123             public String[] part;
124             public void toHTML(ToHTML.HTML sb) {
125                 for(int i=0; i<part.length; i++)
126                     sb.append((i==0 ? "" : ".")+part[i]);
127             }
128         }
129         public static class IP  implements Host {
130             public int a, b, c, d;
131             public void toHTML(ToHTML.HTML sb) { sb.append(a+"."+b+"."+c+"."+d); }
132         }
133     }
134
135     public static interface URI extends ToHTML {
136         public static final Class[] subclasses = new Class[] { URL.class, Email.class };
137     }
138     public static class URL extends Text    implements URI {
139         public String method;
140         public Login login;
141         public Host host;
142         public int port;
143         public String path;
144         public void toHTML(ToHTML.HTML sb) {
145             sb.append(method);
146             sb.append("://");
147             // login.toHTML(sb);   FIXME
148             host.toHTML(sb);
149             // sb.append(":");     FIXME
150             // sb.append(port);
151             sb.append("/");
152             sb.append(path);
153         }
154     }
155     public static class Email extends Text  implements URI {
156         public String user;
157         public Host host;
158         public void toHTML(ToHTML.HTML sb) {
159             sb.append(user);
160             sb.append('@');
161             host.toHTML(sb);
162         }
163     }
164
165     public static class Login {
166         public String username;
167         public String password;
168         public void toHTML(ToHTML.HTML sb) {
169             sb.append(username);
170             sb.append(':');
171             sb.append(password);
172             sb.append('@');
173         }        
174     }
175
176
177
178
179     */
180     /*
181         public static void prefix(PrintWriter p) {
182             p.println("% generated by TIBDOC");
183             for(int i=0; i<packages.length; i++) p.println("\\usemodule["+packages[i]+"]");
184             p.println("\\setuppapersize[letter]");
185             p.println("\\setuppagenumbering[location=]");
186             p.println("\\setupcolors[state=start]");
187             //"\\setupinteraction[title={Title},author={Me},"++
188             //"subtitle={Deez Nutz},keywords={blargh},color=blue]\n" ++
189             //"\\setuppublications[database={me},numbering=yes,sort=author]\n" ++
190             p.println("\\setuphead[section][style={\\ss\\bfa},number=no,before=\\blank\\hairline\\nowhitespace]");
191             p.println("\\definelayout[mypage][backspace=1.75in,cutspace=1.75in,width=5in]");
192             p.println("\\setuplayout[mypage]");
193             p.println("\\definetypeface[myface][rm][Xserif][Warnock Pro]");
194             p.println("\\definetypeface[myface][tt][Xmono][CMU Typewriter Text Regular][default]");
195             p.println("\\definetypeface[myface][ss][Xsans][Myriad Pro][default]");
196             p.println("\\usesymbols[uni]");
197             p.println("\\definesymbol[1][{\\USymbCharZapf{39}{164}}]");
198             p.println("\\setupbodyfont[myface, 11pt]");
199             p.println("\\setupwhitespace[7pt]");
200             p.println("\\def\\MyDroppedCaps%");
201             p.println("    {\\DroppedCaps");
202             p.println("        {} {Serif} {2\\baselineskip} {2pt} {1\\baselineskip} {2}}");
203             p.println("\\starttext");
204             p.println("\\switchtobodyfont[16pt]\\midaligned{\\ss\\bfa{Title}}\\switchtobodyfont[10pt]");
205             p.println("\\midaligned{Adam Megacz}\n\n\\nowhitespace\\midaligned{\\tt{adam@megacz.com}}");
206             p.println("\\blank[1cm,force]");
207             //p.println("\\defineparagraphs[mypar][n=2,before={\\blank},after={\\blank}");
208             //p.println("\\setupparagraphs[mypar][1][width=.45\\textwidth");
209             //p.println("\\setupparagraphs[mypar][2][width=.55\\textwidth");
210             //p.println("\\startmypa");
211             //p.println("\\switchtobodyfont[sma");
212         }
213
214         public static void suffix(PrintWriter p) {
215             p.println("\\stoptext");
216         }
217         static String[] packages = new String[] { "supp-fun", "bib", "href" };
218     }
219
220     // ConTex
221
222 module Contex where
223 import Data.Array.IArray
224 import Data.Char
225 import Util
226 import Lexer
227 import IR
228 import Data.List
229 import Beautify
230
231 toContex ll = prefix ++ (concatMap tl ll) ++ suffix
232  where
233   packages                         = [ "[supp-fun]",
234                                        "[bib]",
235                                        "[href]" ]
236   prefix                           = (concatMap (\x -> "\\usemodule"++x++"\n") packages) ++
237                                      "\\setuppapersize[letter]\n" ++
238                                      "\\setuppagenumbering[location=]\n" ++
239                                      "\\setupcolors[state=start]\n" ++
240                                      --"\\setupinteraction[title={Title},author={Me},"++
241                                      --"subtitle={Deez Nutz},keywords={blargh},color=blue]\n" ++
242                                      --"\\setuppublications[database={me},numbering=yes,sort=author]\n" ++
243                                      "\\setuphead[section][style={\\ss\\bfa},\n" ++
244                                      "                     number=no,\n" ++
245                                      "                     before=\\blank\\hairline\\nowhitespace,\n" ++
246                                      "                     ]\n" ++
247                                      "\\definelayout[mypage][\n" ++
248                                      " backspace=1.75in, % the space for margin notes\n" ++
249                                      " cutspace=1.75in, % the space for right margin notes\n" ++
250                                      " width=5in" ++
251                                      "]\n" ++
252                                      "\\setuplayout[mypage]\n" ++
253                                      "\\definetypeface[myface][rm][Xserif][Warnock Pro]\n" ++
254                                      "\\definetypeface[myface][tt][Xmono][CMU Typewriter Text Regular][default]\n" ++
255                                      "\\definetypeface[myface][ss][Xsans][Myriad Pro][default]\n" ++
256                                      "\\usesymbols[uni]\n" ++
257                                      "\\definesymbol[1][{\\USymbCharZapf{39}{164}}]\n" ++
258                                      "\\setupbodyfont[myface, 11pt]\n" ++
259                                      "\\setupwhitespace[7pt]\n" ++
260                                      "\\def\\MyDroppedCaps%\n" ++
261                                      "    {\\DroppedCaps\n" ++
262                                      "        {} {Serif} {2\\baselineskip} {2pt} {1\\baselineskip} {2}}\n" ++
263                                      "\\starttext\n" ++
264                                      "\\switchtobodyfont[16pt]\\midaligned{\\ss\\bfa{Hi5 Replicated Server Infrastructure}}\\switchtobodyfont[10pt]\n"++ 
265                                      "\\midaligned{Adam Megacz}\n\n\\nowhitespace\\midaligned{\\tt{adam@megacz.com}}\n\n"++
266                                      "\\blank[1cm,force]\n" ++
267                                      "\\defineparagraphs[mypar][n=2,before={\\blank},after={\\blank}]\n"++
268                                      "\\setupparagraphs[mypar][1][width=.45\\textwidth]\n"++
269                                      "\\setupparagraphs[mypar][2][width=.55\\textwidth]\n"++
270                                      "\\startmypar"++
271                                      "\\switchtobodyfont[small]\n"
272   suffix                           = "\n\\stoptext\n"
273   addItem i                        = "\\item " ++ (striptrail $ boost 8 $ wrap $ striplead $ tl i)
274   escapify []                      = []
275   escapify ('%':t)                 = '\\':'%':(escapify t)
276   escapify ('$':t)                 = '\\':'$':(escapify t)
277   escapify (h:t)                   = h:(escapify t)
278   escapeMath s                     = s
279   tl (Special _ BulletList l)      = "\\startitemize[symbol]\n" ++ (concatMap addItem l) ++ "\\stopitemize\n"
280   tl (Special _ NumberList l)      = "\\startitemize[symbol]\n" ++ (concatMap addItem l) ++ "\\stopitemize\n"
281   tl (Special _ Section (h:t))     = "\\section{"++(tl h)++"}\n"++(concatMap tl t)
282   tl (Special _ NumberedSection (h:t)) = "\\section{"++(tl h)++"}\n"++(concatMap tl t)
283   tl (Special _ (Glyph EmDash) []) = "{\\emdash}"
284 --tl (Special _ Superscript l)     = 
285 --tl (Special _ Subscript l)       = 
286 --tl (Special _ (Image u) l)       = 
287 --tl (Special _ (Cite u) l)        = 
288   tl (Special _ BlockQuote l)      = "\n\n\\startquote\n     "++
289                                      (striptrail $ boost 4 $ wrap $ striplead $ concatMap tl l)++"\n\\stopquote\n\n"
290   tl (Special _ HorizontalRule []) = "\\\\\\rule{4in}{0.5pt}\\\\"
291   tl (Special _ Italic l)          = "{\\it{"++(concatMap tl l)++"}}"
292   tl (Special _ Bold l)            = "{\\bf{"++(concatMap tl l)++"}}"
293   tl (Special _ DropCap (h:t))     = "\\MyDroppedCaps{"++(tl h)++"}{\\sc "++(concatMap tl t)++"}"
294   tl (Special _ Typewriter l)      = "{\\tt{"++(concatMap tl l)++"}}"
295   tl (Special _ StrikeThrough l)   = "" --"\\sout{"++(concatMap tl l)++"}"
296   tl (Special _ Quotes l)          = "``"++(concatMap tl l)++"''"
297   tl (Special _ Underline l)       = "" --"\\uline{"++(concatMap tl l)++"}"
298   tl (Special _ Underline2 l)      = "" --"\\uuline{"++(concatMap tl l)++"}"
299   tl (Special _ (Math s) [])       = "\\placeformula\n$$\n" ++ (escapeMath s) ++ "\n$$\n"
300   tl (Special _ Footnote l)        = "\\footnote{"++(concatMap tl l)++"}"
301   tl (Special _ Float l)           = "" --"\n\n\\begin{wrapfigure}{r}{0.4\\textwidth} \\framebox[0.4\\textwidth]{"++
302                                      --(concatMap tl l)++"} \\label{x}\\end{wrapfigure}\n\n"
303 --tl (Special _ Figure l)          = "\\placefigure[][fig:church]{}{"++(concatMap tl l)++"}"
304   tl (Special _ Figure l)          = "\\startnarrower\n"++(concatMap tl l)++"\n\\stopnarrower\n"
305   tl (Special _ (Link u) l)        = "\\href{"++(escapify u)++"}{"++(concatMap tl l)++"}"
306   tl (Special _ (Verbatim s) [])   = "\\starttyping\n"++s++"\n\\stoptyping\n"
307 --  tl (Special _ TwoColumn l)       = "\\startcolumns[n=2]\n"++(concatMap tl l)++"\\stopcolumns"
308 --  tl (Special _ Title l)           = ""--"\\title{"++(concatMap tl l)++"}\n\\maketitle\n\n\n"
309   tl (Special _ Abstract l) =
310       "\\midaligned{\\ss\\bfa Abstract}\\par\n " ++
311       "\n\n"++(concatMap tl l)++"\\mypar" ++
312       "\\switchtobodyfont[8pt]{\\ss{\\placecontent}}\\switchtobodyfont[normal]\\stopmypar\n\n\\blank[1cm,force]"
313   tl (Special _ (Command c) l)     = "\\"++c++"["++(concatMap tl l)++"]"
314   tl (Special _ t l)               = error $ "formatting code "++(show t)++" not supported on {"++(concatMap show l)++"})"
315   tl (WS _)                        = " "
316   tl (BlankLine _)                 = "\n\n"
317   tl (Block _ l)                   = concatMap tl l
318   tl (Letter _ c)                  = escapify [c]
319   tl z                             = (show z)
320
321
322
323
324     */
325
326     // Main //////////////////////////////////////////////////////////////////////////////
327
328     public static class Dump implements Reflection.Show {
329         public String toString() { return Reflection.show((Reflection.Show)this); }
330     }
331
332     public static class TD {
333
334         public @bind.as static class Doc extends Dump {
335             public @bind.arg Header head;
336             public @bind.arg Body body;
337         }
338
339         public @bind.as static class Header extends Dump {
340             public @bind.arg KeyVal[] attrs;
341             // FIXME: it would be nice to be able to
342             // void KeyVal(String, String) { ... } imperatively
343         }
344         
345         public @bind.as static class Body extends Dump {
346             public Section[] sections;
347         }
348         
349         public @bind.as("Section") static class Section extends Dump {
350             public String      header;
351             public Paragraph[] paragraphs;
352         }
353         
354         public @bind.as static class KeyVal extends Dump {
355             public @bind.arg String key;
356             public @bind.arg Object val;
357         }
358
359         public abstract static class Paragraph extends Dump implements ToHTML { }
360
361         public @bind.as("P") static class P extends Paragraph {
362             public Text[] text;
363             public P() { }
364             public P(Text[] text) { this.text = text; }
365             public void toHTML(HTML h) { if (text != null) for (Text t : text) if (t != null) t.toHTML(h); }
366             public String toString() {
367                 StringBuffer sb = new StringBuffer();
368                 ToHTML.HTML h = new ToHTML.HTML(sb);
369                 toHTML(h);
370                 return sb.toString();
371             }
372         }
373
374         public @bind.as("HR") static class HR extends Paragraph {
375             public void toHTML(HTML h) { h.tag("hr"); }
376         }
377
378         public @bind.as("Blockquote") static class Blockquote extends Paragraph {
379             Text[] text;
380             public void toHTML(HTML h) { h.tag("blockquote", new P(text)); }
381         }
382
383         public abstract static class Text extends Dump implements ToHTML { }
384         public @bind.as static class Chars extends Text {
385             public String text;
386             public Chars() { }
387             public Chars(String text) { this.text = text; }
388             public void toHTML(HTML h) { h.appendText(" " + text + " "); }
389             public String toString() { return text; }
390         }
391         public @bind.as static class Block extends Text {
392             public Text[] text;
393             public void toHTML(HTML h) { for(Text t : text) t.toHTML(h); }
394         }
395         public static class TextWrap extends Text {
396             public Text text;
397             public void toHTML(HTML h) {
398                 if (htmlTag()!=null)
399                     h.tag(htmlTag(), htmlTagParams(), text);
400                 else
401                     text.toHTML(h);
402             }
403             public String   htmlTag() { return null; }
404             public Object[] htmlTagParams() { return null; }
405         }
406         public static @bind.as class Verbatim   extends Text { public char[] c; public void toHTML(HTML h) { } }
407         //public @bind.as class Blockquote extends TextWrap { }
408         public static @bind.as class Underline extends TextWrap { public String htmlTag() { return "u"; } }
409         public static @bind.as class Footnote extends TextWrap { public String htmlTag() { return "small"; } }
410         public static @bind.as class TT extends TextWrap { public String htmlTag() { return "tt"; } }
411         //public @bind.as class Citation extends Text {       "[" word "]" }
412         public static @bind.as class Strikethrough extends TextWrap { public String htmlTag() { return "strikethrough"; } }
413         public static @bind.as class Superscript extends TextWrap { public String htmlTag() { return "sup"; } }
414         public static @bind.as class Subscript extends TextWrap { public String htmlTag() { return "sub"; } }
415         public static @bind.as class Smallcap extends TextWrap { public String htmlTag() { return "sc"; } }
416         public static @bind.as class Keyword extends TextWrap { public String htmlTag() { return "sc"; } }
417         public static @bind.as class Bold extends TextWrap { public String htmlTag() { return "b"; } }
418         public static @bind.as class Italic extends TextWrap { public String htmlTag() { return "i"; } }
419
420         public abstract static class Command extends Text { }
421         public static @bind.as class Today extends Command { public void toHTML(HTML h) { } }
422         public static @bind.as class LineBreak extends Command { public void toHTML(HTML h) { h.tag("br"); } }
423
424         public abstract static class Glyph extends Text { }
425         public static @bind.as("emdash") class Emdash extends Glyph { public void toHTML(HTML h) { h.append("&emdash;"); } }
426
427         public static class Link extends Text {
428             public Text[] t;
429             public Url u;
430             public @bind.as("LinkText") Link(Text[] t, Url u)  { this.t = t; this.u = u; }
431             public @bind.as("LinkChars") Link(String s, Url u) { this(new Text[] { new Chars(s) }, u); }
432             public void toHTML(HTML h) {
433                 h.tag("a",
434                       new Object[] { "href", u==null ? "" : u.toString() },
435                       new P(t));
436             }
437         }
438
439         public static class Host {
440             public String name;
441             public String toString() { return name; }
442             public @bind.as("DNS") Host(String[][] parts) {
443                 name = "";
444                 for(String[] s : parts) {
445                     for(String ss : s)
446                         name += ss;
447                     name += ".";
448                 }
449             }
450             public @bind.as("IP")  Host(int a, int b, int c, int d) { name = a+"."+b+"."+c+"."+d; }
451         }
452
453         public static class Url extends Text {
454             public String   method;
455             public Host     host;
456             public String   user;
457             public String   pass;
458             public String   port;
459             public String   path;
460             public @bind.as("URL") Url(String method, String[] login, Host host, String port, String path) {
461                 this.method = method;
462                 this.user = login==null ? null : login.length >= 1 ? login[0] : null;
463                 this.pass = login==null ? null : login.length >= 2 ? login[1] : null;
464                 this.host = host;
465                 this.port = port;
466                 this.path = path;
467             }
468             public @bind.as("Mailto") Url(String email) { this("mailto", null, null, "25", email); }
469             public void toHTML(HTML h) { new Link(toString(), this).toHTML(h); }
470             public String toString() {
471                 return method + "://" + host + "/" + path;
472             }
473         }
474         public static @bind.as("lf")        String lf() { return "\r"; }
475         public static @bind.as("cr")        String cr() { return "\n"; }
476         public static @bind.as("\"\"")      String empty() { return ""; }
477         public static @bind.as("urlescape") String urlescape(char a, char b) { return ((char)((a-'0') * 16 + (b-'0')))+""; }
478     }
479
480     public static void main(String[] s) throws Exception {
481             /*
482         try {
483
484                FIXME FIXME
485
486             Demo.ReflectiveMeta m =
487                 new Demo.ReflectiveMeta(TibDoc.TD.class);
488             Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
489             MetaGrammar.Meta.MetaGrammarFile mgf = m.new MetaGrammarFile(res);
490             MetaGrammar.BuildContext bc = new MetaGrammar.BuildContext(mgf);
491             
492             Union tibgram = mgf.get("s").build(bc);
493
494             System.err.println("parsing " + s[1]);
495             Tree t = new CharParser(tibgram).parse(new Tib(new FileInputStream(s[1]))).expand1();
496             System.out.println("tree:\n" + t.toPrettyString());
497             
498             Object result = ((Functor)t.head()).invoke(t);
499             System.out.println((TD.Doc)result);
500             */
501
502
503             /*
504             System.out.println("parsing " + s[0]);
505             Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
506             MetaGrammar gram = new Tib.Grammar(TibDoc.class);
507             gram = (MetaGrammar)gram.walk(res);
508             System.out.println("\nparsing " + s[1]);
509             Forest f = new CharParser(gram.done()).parse(new Tib(new FileInputStream(s[1])));
510             System.out.println();
511             System.out.println(f.expand1().toPrettyString());
512             System.out.println();
513
514
515             FileOutputStream fos = new FileOutputStream("out.html");
516             PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));
517             p.println(sb);
518             p.flush();
519             p.close();
520
521         } catch (Ambiguous a) {
522             FileOutputStream fos = new FileOutputStream("/Users/megacz/Desktop/out.dot");
523             PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));
524             GraphViz gv = new GraphViz();
525             a.ambiguity.toGraphViz(gv);
526             gv.dump(p);
527             p.flush();
528             p.close();
529             a.printStackTrace();
530             
531         } catch (Exception e) {
532             e.printStackTrace();
533         }
534             */
535     }
536
537 }
538