System.err.println("usage: java " + MetaGrammar.class.getName() + " grammarfile.g com.yourdomain.package.ClassName");
System.exit(-1);
}
- //StringBuffer sbs = new StringBuffer();
- //((MetaGrammar)new MetaGrammar().walk(meta)).nt.get("e").toString(sbs);
- //System.err.println(sbs);
String className = args[1].substring(args[1].lastIndexOf('.')+1);
String packageName = args[1].substring(0, args[1].lastIndexOf('.'));
String fileName = packageName.replace('.', '/') + "/" + className + ".java";
out.append("\n // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED\n");
- /*
- GrammarCompiler m = new GrammarCompiler();
- Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(args[0])).expand1();
- MetaGrammar.Meta.MetaGrammarFile mgf = m.new MetaGrammarFile(res);
- MetaGrammar.BuildContext bc = new MetaGrammar.BuildContext(mgf);
-
- Union meta = mgf.get("s").build(bc);
- Tree t = new CharParser(meta).parse(new FileInputStream(args[0])).expand1();
- */
Tree t = MetaGrammarTree.meta;
Union u = MetaGrammar.make(t, "s");
System.err.println("== parsing with parsed grammar =================================================================================");
t = new CharParser((Union)u).parse(new FileInputStream(args[0])).expand1();
System.out.println(t.toPrettyString());
- //Forest<String> fs = new CharParser(make()).parse(new FileInputStream(args[0]));
- //System.out.println(fs.expand1());
-
- //GraphViz gv = new GraphViz();
- //fs.toGraphViz(gv);
- //FileOutputStream fox = new FileOutputStream("out.dot");
- //gv.dump(fox);
- //fox.close();
t.toJava(out);
out.append("\n // DO NOT EDIT STUFF ABOVE: IT IS AUTOMATICALLY GENERATED\n");
public static Union cached = null;
- public static Union make() {
- /*
- if (cached != null) return cached;
- try {
- GrammarBindingResolver m = new GrammarBindingResolver();
- Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream("tests/meta.g")).expand1();
- MetaGrammar.Meta.MetaGrammarFile mgf = m.new MetaGrammarFile(res);
- MetaGrammar.BuildContext bc = new MetaGrammar.BuildContext(mgf);
- Union meta = mgf.get("s").build(bc);
- Tree t = new CharParser(meta).parse(new FileInputStream("tests/meta.g")).expand1();
- return cached = make(t, "s");
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- */
- return make(MetaGrammarTree.meta, "s");
- }
+ public static Union make() { return make(MetaGrammarTree.meta, "s"); }
public static Union make(Tree t, String s) { return make(t, s, new AnnotationGrammarBindingResolver()); }
public static Union make(Tree t, String s, GrammarBindingResolver rm) {
Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
}
public @bind.as("Euro") Object euro() { return null; }
- public @bind.as("Citation") Object cite(Object o) { return null; }
+ public @bind.as("Citation") Object cite(Object o) { return new Chars("*cite*"); }
public @bind.as("Symbol") Object sym(Object o) { return null; }
public static abstract class List extends Text {
public void toHTML(HTML h) { for(Text t : text) t.toHTML(h); }
}
public static class TextWrap extends Text {
- public Text text;
+ public @bind.arg Text[] text;
public void toHTML(HTML h) {
- if (htmlTag()!=null)
- h.tag(htmlTag(), htmlTagParams(), text);
- else
- text.toHTML(h);
+ if (htmlTag()!=null) {
+ h.openTag(htmlTag(), htmlTagParams());
+ }
+ for(Text t : text) t.toHTML(h);
+ if (htmlTag()!=null) {
+ h.closeTag(htmlTag());
+ }
}
public String htmlTag() { return null; }
public Object[] htmlTagParams() { return null; }
public static @bind class Footnote extends TextWrap { public String htmlTag() { return "small"; } }
public static @bind class TT extends TextWrap { public String htmlTag() { return "tt"; } }
//public @bind class Citation extends Text { "[" word "]" }
- public static @bind class Strikethrough extends TextWrap { public String htmlTag() { return "strikethrough"; } }
+ public static @bind class Strikethrough extends TextWrap { public String htmlTag() { return "strike"; } }
public static @bind class Superscript extends TextWrap { public String htmlTag() { return "sup"; } }
public static @bind class Subscript extends TextWrap { public String htmlTag() { return "sub"; } }
public static @bind class Smallcap extends TextWrap { public String htmlTag() { return "sc"; } }
public static @bind class LineBreak extends Command { public void toHTML(HTML h) { h.tag("br"); } }
public abstract static class Glyph extends Text { }
- public static @bind.as("emdash") class Emdash extends Glyph { public void toHTML(HTML h) { h.append("&emdash;"); } }
+ public static @bind.as("emdash") class Emdash extends Glyph { public void toHTML(HTML h) { h.appendLiterally("—"); } }
public static class Link extends Text {
public Text[] t;
private final StringBuffer sb;
public HTML(StringBuffer sb) { this.sb = sb; }
+ public void appendLiterally(String s) {
+ sb.append(s);
+ }
public void append(String s) {
/* FIXME */
sb.append(s);
append(s);
sb.append("/>");
}
- public void tag(String s, Object o) { tag(s, null, o); }
- public void tag(String s, Object[] attrs, Object o) {
- if (s != null) {
+ public void openTag(String s, Object[] attrs) {
sb.append("<");
append(s);
if (attrs != null)
sb.append("\'");
}
sb.append(">");
- }
+ }
+ public void closeTag(String s) {
+ sb.append("<");
+ append(s);
+ sb.append(">");
+ }
+ public void tag(String s, Object o) { tag(s, null, o); }
+ public void tag(String s, Object[] attrs, Object o) {
+ if (s != null) openTag(s, attrs);
append(o);
if (s != null) {
sb.append("</");
Doc = head:Header body:Body /ws
Header = H:: { "header" { KeyVal */ ws } /ws }
Body = B:: {Section}*/ws
-Section = SectionHeader Paragraph* /ws
+Section = SectionHeader ws! (Paragraph Paragraph)
SectionHeader = "==" SectionHeaderBody "=="
SectionHeaderBody = "=" SectionHeaderBody "="
> ws! alphanum++ ws!
oli = ("# "|onums)! (ws! text &~ any (oli|uli)!)
text = Item
-Itemx = ws! Item
- | ()
Item*/ws =
blockquote
> (Chars:: alphanum++)
> "\"" text "\""
> (Symbol:: sym++)
- > { Block:: text }
+// > { Block:: text }
blockquote = "adsfafewag"
//blockquote = Blockquote:: "\"\"" (block | text "\"\"")