public class TibDoc {
+ public static class Doc {
+ public Header head;
+ public Body body;
+ }
+ public static class kv { public String key; public Text[] val; }
+ public static class Header {
+ public void attrs(kv[] kvs) {
+ for(int i=0; i<kvs.length; i++)
+ System.out.println("key="+kvs[i].key+" val="+kvs[i].val);
+ }
+ }
+ public static class Body {
+ Section[] sections;
+ }
+ public static class Section { }
+ public static abstract class Text {
+ public static final Class[] subclasses = new Class[] { Chars.class, URL.class, Email.class };
+ }
+ public static class Chars extends Text { String chars; }
+ public static class Symbol extends Text { String chars; }
+ public static class Email extends Text { String user; Host host; }
+ public static interface Host { }
+ public static class DNS implements Host { String[] part; }
+ public static class IP implements Host { int a, b, c, d; }
+ public static class URL extends Text { String method; Host host; int port; String path; }
+ public static class Italic extends Text { Text body; }
+
public static void main(String[] s) throws Exception {
try {
System.out.println("parsing " + s[0]);
Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
- MetaGrammar gram = (MetaGrammar)new Tib.Grammar().walk(res);
+ MetaGrammar gram = new Tib.Grammar(TibDoc.class);
+ gram = (MetaGrammar)gram.walk(res);
//System.out.println(gram);
Union mg = gram.done();
System.out.println("\nparsing " + s[1]);
Forest f = new CharParser(mg).parse(new Tib(new FileInputStream(s[1])));
-
+ //((Tree)new StringifyWalker().walk(f.expand1())).toPrettyString()
System.out.println();
- System.out.println(f);
- System.out.println();
- System.out.println(((Tree)new StringifyWalker().walk(f.expand1())).toPrettyString());
-
+ Doc doc = (Doc)new ReflectiveGrammar(TibDoc.class).build(f.expand1());
+ System.out.println(doc);
+ /*
String st = new HTMLWalker().walk(f.expand1()).toString();
System.out.println(st);
FileOutputStream fos = new FileOutputStream("out.html");
p.println(st);
p.flush();
p.close();
+ */
} catch (Ambiguous a) {
FileOutputStream fos = new FileOutputStream("/Users/megacz/Desktop/out.dot");
PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));
gv.dump(p);
p.flush();
p.close();
+ a.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
public String ul(String[] li) { return "<ul>"+join(li,"")+"</ul>"; }
public String ol(String[] li) { return "<ol>"+join(li,"")+"</ol>"; }
public String hr() { return "\n<hr/>\n"; }
+ public String br() { return "\n<br/>\n"; }
public String it(Object o) { return "<i>"+o+"</i>"; }
public String tt(Object o) { return "<tt>"+o+"</tt>"; }
public String underline(Object o) { return "<ul>"+o+"</ul>"; }