added stuff to TibDoc
authoradam <adam@megacz.com>
Sun, 25 Dec 2005 10:28:20 +0000 (05:28 -0500)
committeradam <adam@megacz.com>
Sun, 25 Dec 2005 10:28:20 +0000 (05:28 -0500)
darcs-hash:20051225102820-5007d-8dbe1e51b5de193b44425ab7ec3bddf65e770296.gz

src/edu/berkeley/sbp/tib/TibDoc.java

index 504e3a4..b44678f 100644 (file)
@@ -5,10 +5,26 @@
 package edu.berkeley.sbp.tib;
 //import org.ibex.util.*;
 //import org.ibex.io.*;
 package edu.berkeley.sbp.tib;
 //import org.ibex.util.*;
 //import org.ibex.io.*;
+import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.misc.*;
 import java.util.*;
 import java.io.*;
 
 public class TibDoc {
 import java.util.*;
 import java.io.*;
 
 public class TibDoc {
+    
+    public static void main(String[] s) throws Exception {
+        System.out.println("parsing " + s[0]);
+        Tree<String> res = new Parser(MetaGrammar.make(), CharToken.top()).parse1(new CharToken.Stream(new FileInputStream(s[0])));
+        MetaGrammar gram = (MetaGrammar)new Tib.Grammar().walk(res);
+        //System.out.println(gram);
+        Union mg = gram.done();
+        
+        System.out.println("\nparsing " + s[1]);
+        res = new Parser(mg, CharToken.top()).parse1(new Tib(new FileInputStream(s[1])));
+        System.out.println(res);
+    }
+
+
     /*
     public static enum Style { H, UL, TT, SO, IT, Q, B, PRE, LIST, EMDASH; }
 
     /*
     public static enum Style { H, UL, TT, SO, IT, Q, B, PRE, LIST, EMDASH; }
 
@@ -105,6 +121,111 @@ public class TibDoc {
         }
         static String[] packages = new String[] { "supp-fun", "bib", "href" };
     }
         }
         static String[] packages = new String[] { "supp-fun", "bib", "href" };
     }
+
+    // ConTex
+
+module Contex where
+import Data.Array.IArray
+import Data.Char
+import Util
+import Lexer
+import IR
+import Data.List
+import Beautify
+
+toContex ll = prefix ++ (concatMap tl ll) ++ suffix
+ where
+  packages                         = [ "[supp-fun]",
+                                       "[bib]",
+                                       "[href]" ]
+  prefix                           = (concatMap (\x -> "\\usemodule"++x++"\n") packages) ++
+                                     "\\setuppapersize[letter]\n" ++
+                                     "\\setuppagenumbering[location=]\n" ++
+                                     "\\setupcolors[state=start]\n" ++
+                                     --"\\setupinteraction[title={Title},author={Me},"++
+                                     --"subtitle={Deez Nutz},keywords={blargh},color=blue]\n" ++
+                                     --"\\setuppublications[database={me},numbering=yes,sort=author]\n" ++
+                                     "\\setuphead[section][style={\\ss\\bfa},\n" ++
+                                     "                     number=no,\n" ++
+                                     "                     before=\\blank\\hairline\\nowhitespace,\n" ++
+                                     "                     ]\n" ++
+                                     "\\definelayout[mypage][\n" ++
+                                     " backspace=1.75in, % the space for margin notes\n" ++
+                                     " cutspace=1.75in, % the space for right margin notes\n" ++
+                                     " width=5in" ++
+                                     "]\n" ++
+                                     "\\setuplayout[mypage]\n" ++
+                                     "\\definetypeface[myface][rm][Xserif][Warnock Pro]\n" ++
+                                     "\\definetypeface[myface][tt][Xmono][CMU Typewriter Text Regular][default]\n" ++
+                                     "\\definetypeface[myface][ss][Xsans][Myriad Pro][default]\n" ++
+                                     "\\usesymbols[uni]\n" ++
+                                     "\\definesymbol[1][{\\USymbCharZapf{39}{164}}]\n" ++
+                                     "\\setupbodyfont[myface, 11pt]\n" ++
+                                     "\\setupwhitespace[7pt]\n" ++
+                                     "\\def\\MyDroppedCaps%\n" ++
+                                     "    {\\DroppedCaps\n" ++
+                                     "        {} {Serif} {2\\baselineskip} {2pt} {1\\baselineskip} {2}}\n" ++
+                                     "\\starttext\n" ++
+                                     "\\switchtobodyfont[16pt]\\midaligned{\\ss\\bfa{Hi5 Replicated Server Infrastructure}}\\switchtobodyfont[10pt]\n"++ 
+                                     "\\midaligned{Adam Megacz}\n\n\\nowhitespace\\midaligned{\\tt{adam@megacz.com}}\n\n"++
+                                     "\\blank[1cm,force]\n" ++
+                                     "\\defineparagraphs[mypar][n=2,before={\\blank},after={\\blank}]\n"++
+                                     "\\setupparagraphs[mypar][1][width=.45\\textwidth]\n"++
+                                     "\\setupparagraphs[mypar][2][width=.55\\textwidth]\n"++
+                                     "\\startmypar"++
+                                     "\\switchtobodyfont[small]\n"
+  suffix                           = "\n\\stoptext\n"
+  addItem i                        = "\\item " ++ (striptrail $ boost 8 $ wrap $ striplead $ tl i)
+  escapify []                      = []
+  escapify ('%':t)                 = '\\':'%':(escapify t)
+  escapify ('$':t)                 = '\\':'$':(escapify t)
+  escapify (h:t)                   = h:(escapify t)
+  escapeMath s                     = s
+  tl (Special _ BulletList l)      = "\\startitemize[symbol]\n" ++ (concatMap addItem l) ++ "\\stopitemize\n"
+  tl (Special _ NumberList l)      = "\\startitemize[symbol]\n" ++ (concatMap addItem l) ++ "\\stopitemize\n"
+  tl (Special _ Section (h:t))     = "\\section{"++(tl h)++"}\n"++(concatMap tl t)
+  tl (Special _ NumberedSection (h:t)) = "\\section{"++(tl h)++"}\n"++(concatMap tl t)
+  tl (Special _ (Glyph EmDash) []) = "{\\emdash}"
+--tl (Special _ Superscript l)     = 
+--tl (Special _ Subscript l)       = 
+--tl (Special _ (Image u) l)       = 
+--tl (Special _ (Cite u) l)        = 
+  tl (Special _ BlockQuote l)      = "\n\n\\startquote\n     "++
+                                     (striptrail $ boost 4 $ wrap $ striplead $ concatMap tl l)++"\n\\stopquote\n\n"
+  tl (Special _ HorizontalRule []) = "\\\\\\rule{4in}{0.5pt}\\\\"
+  tl (Special _ Italic l)          = "{\\it{"++(concatMap tl l)++"}}"
+  tl (Special _ Bold l)            = "{\\bf{"++(concatMap tl l)++"}}"
+  tl (Special _ DropCap (h:t))     = "\\MyDroppedCaps{"++(tl h)++"}{\\sc "++(concatMap tl t)++"}"
+  tl (Special _ Typewriter l)      = "{\\tt{"++(concatMap tl l)++"}}"
+  tl (Special _ StrikeThrough l)   = "" --"\\sout{"++(concatMap tl l)++"}"
+  tl (Special _ Quotes l)          = "``"++(concatMap tl l)++"''"
+  tl (Special _ Underline l)       = "" --"\\uline{"++(concatMap tl l)++"}"
+  tl (Special _ Underline2 l)      = "" --"\\uuline{"++(concatMap tl l)++"}"
+  tl (Special _ (Math s) [])       = "\\placeformula\n$$\n" ++ (escapeMath s) ++ "\n$$\n"
+  tl (Special _ Footnote l)        = "\\footnote{"++(concatMap tl l)++"}"
+  tl (Special _ Float l)           = "" --"\n\n\\begin{wrapfigure}{r}{0.4\\textwidth} \\framebox[0.4\\textwidth]{"++
+                                     --(concatMap tl l)++"} \\label{x}\\end{wrapfigure}\n\n"
+--tl (Special _ Figure l)          = "\\placefigure[][fig:church]{}{"++(concatMap tl l)++"}"
+  tl (Special _ Figure l)          = "\\startnarrower\n"++(concatMap tl l)++"\n\\stopnarrower\n"
+  tl (Special _ (Link u) l)        = "\\href{"++(escapify u)++"}{"++(concatMap tl l)++"}"
+  tl (Special _ (Verbatim s) [])   = "\\starttyping\n"++s++"\n\\stoptyping\n"
+--  tl (Special _ TwoColumn l)       = "\\startcolumns[n=2]\n"++(concatMap tl l)++"\\stopcolumns"
+--  tl (Special _ Title l)           = ""--"\\title{"++(concatMap tl l)++"}\n\\maketitle\n\n\n"
+  tl (Special _ Abstract l) =
+      "\\midaligned{\\ss\\bfa Abstract}\\par\n " ++
+      "\n\n"++(concatMap tl l)++"\\mypar" ++
+      "\\switchtobodyfont[8pt]{\\ss{\\placecontent}}\\switchtobodyfont[normal]\\stopmypar\n\n\\blank[1cm,force]"
+  tl (Special _ (Command c) l)     = "\\"++c++"["++(concatMap tl l)++"]"
+  tl (Special _ t l)               = error $ "formatting code "++(show t)++" not supported on {"++(concatMap show l)++"})"
+  tl (WS _)                        = " "
+  tl (BlankLine _)                 = "\n\n"
+  tl (Block _ l)                   = concatMap tl l
+  tl (Letter _ c)                  = escapify [c]
+  tl z                             = (show z)
+
+
+
+
     */
 }
 
     */
 }