public P() { }
public P(Text[] text) { this.text = text; }
public P(String string) { this.text = new Text[] { new Chars(string) }; }
- public void toHTML(HTML h) { if (text != null) for (Text t : text) if (t != null) t.toHTML(h); }
+ public void toHTML(HTML h) { if (text != null) h.append(text); }
public String toString() {
StringBuffer sb = new StringBuffer();
ToHTML.HTML h = new ToHTML.HTML(sb);
public @bind.arg String password;
}
- public static @bind.as("Euro") Object euro() { return null; }
public static @bind.as("Citation") Object cite(Object o) { return new Chars("*cite*"); }
public static @bind.as("Symbol") Object sym(Object o) { return null; }
}
public abstract static class Text extends Dump implements ToHTML { }
+
+ public @bind static class Space extends Chars {
+ public Space() { super(" "); }
+ }
public @bind static class Chars extends Text {
public String text;
public Chars() { }
public Chars(String text) { this.text = text; }
- public void toHTML(HTML h) { h.appendText(" " + text + " "); }
+ public void toHTML(HTML h) { h.appendText(text); }
public String toString() { return text; }
}
public @bind static class Block extends Text {
public Text[] text;
- public void toHTML(HTML h) {
- for(Text t : text)
- if (t != null)
- t.toHTML(h);
- }
+ public void toHTML(HTML h) { h.append(text); }
}
public static class TextWrap extends Text {
public @bind.arg Text[] text;
if (htmlTag()!=null) {
h.openTag(htmlTag(), htmlTagParams());
}
- for(Text t : text) t.toHTML(h);
+ h.append(text);
if (htmlTag()!=null) {
h.closeTag(htmlTag());
}
public String htmlTag() { return null; }
public Object[] htmlTagParams() { return null; }
}
- public static @bind class Verbatim extends Text {
+
+ public static @bind class Verbatim extends Text {
public @bind.arg String s;
public void toHTML(HTML h) {
h.openTag("div", new Object[] { "class", "terminal" });
h.closeTag("div");
}
}
+
//public @bind class Blockquote extends TextWrap { }
public static @bind class Underline extends TextWrap { public String htmlTag() { return "u"; } }
public static @bind class Footnote extends TextWrap { public String htmlTag() { return "small"; } }
public static @bind class Today extends Command { public void toHTML(HTML h) { } }
public static @bind class LineBreak extends Command { public void toHTML(HTML h) { h.tag("br"); } }
- public static abstract class Glyph extends Text implements ToHTML { }
- public static @bind.as("emdash") class Emdash extends Glyph { public void toHTML(HTML h) { h.appendLiterally("—"); } }
- public static @bind.as("ellipses") class Ellipses extends Glyph { public void toHTML(HTML h) { h.appendLiterally("…"); } }
- public static @bind.as("r") class RegTm extends Glyph { public void toHTML(HTML h) { h.appendLiterally("®"); } }
- public static @bind.as("c") class Copyright extends Glyph { public void toHTML(HTML h) { h.appendLiterally("©"); } }
- public static @bind.as("tm") class Tm extends Glyph { public void toHTML(HTML h) { h.appendLiterally("&;"); } }
- public static @bind.as("euro") class Euro extends Glyph { public void toHTML(HTML h) { h.appendLiterally("€"); } }
+ public static @bind.as("emdash") Entity emdash() { return new Entity("mdash"); }
+ public static @bind.as("ellipses") Entity ellipses() { return new Entity("#8230"); }
+ public static @bind.as("r") Entity r() { return new Entity("#xAE"); }
+ public static @bind.as("c") Entity c() { return new Entity("#xA9"); }
+ public static @bind.as("tm") Entity tm() { return new Entity(""); }
+ public static @bind.as("euro") Entity euro() { return new Entity("euro"); }
- public static @bind.as("#") Text comment() { return new Chars(""); }
public static class Entity extends Text implements ToHTML {
- public int code;
public String name;
- public Entity(String name, int code) { this.name = name; this.code = code; }
+ public String code;
+ public Entity(String code) { this.name = ""; this.code = code; }
+ public Entity(String name, int code) { this.code = "#"+code; this.name = name; }
public Entity(String name, String abbrev, int code) { this(name, code); }
- public void toHTML(HTML h) {
- h.appendLiterally("&#x"+Integer.toString(code, 16)+";");
- }
+ public void toHTML(HTML h) { h.appendLiterally("&"+code+";"); }
}
public static Entity[] entities = new Entity[] {
return null;
}
+ public static @bind class Quotes extends Text {
+ public Text[] text;
+ public void toHTML(HTML h) {
+ h.append("\"");
+ h.append(text);
+ h.append("\"");
+ }
+ }
+
public static class Link extends Text {
public Text[] t;
public Url u;
- public Input.Region region;
- public @bind.as("link") Link(Input.Region region, @bind.arg Text[] t, @bind.arg Url u) { this.region = region; this.t = t; this.u = u; }
- public Link(String s, Url u) { this(null,new Text[] { new Chars(s) }, u); }
+ public @bind.as("link") Link(@bind.arg Text[] t, @bind.arg Url u) { this.t = t; this.u = u; }
+ public Link(String s, Url u) { this(new Text[] { new Chars(s) }, u); }
public void toHTML(HTML h) {
h.tag("a",
new Object[] { "href", u==null ? "" : u.toString() },
- new P(/*t*/region+""));
+ new P(t));
}
}
public String pass;
public String port;
public String path;
- public @bind.as("URL") Url(String method, String[] login, Host host, String port, String path) {
+ public String ref;
+ public @bind.as("URL") Url(String method, String[] login, Host host, String port, String path, String ref) {
this.method = method;
this.user = login==null ? null : login.length >= 1 ? login[0] : null;
this.pass = login==null ? null : login.length >= 2 ? login[1] : null;
this.host = host;
this.port = port;
this.path = path;
+ this.ref = ref;
}
public void toHTML(HTML h) { new Link(toString(), this).toHTML(h); }
public String toString() {
- return method + "://" + host + "/" + path;
+ return method + "://" + host + "/" + path + (ref==null ? "" : ("#"+ref));
}
}
public static class Email extends Url {
public @bind.as("Mailto") Email(String email) {
- super("mailto", null, new Host(email.substring(email.indexOf('@'))), "25", email.substring(email.indexOf('@')));
+ super("mailto",
+ null,
+ new Host(email.substring(email.indexOf('@'))),
+ "25",
+ email.substring(email.indexOf('@')),
+ null
+ );
}
public @bind.as("email") Email(String user, Host host) {
- super("mailto", null, host, "25", user);
+ super("mailto", null, host, "25", user, null);
}
public void toHTML(HTML h) {
h.tag("a",
public static @bind.as("lf") String lf() { return "\r"; }
public static @bind.as("cr") String cr() { return "\n"; }
public static @bind.as("\"\"") String empty() { return ""; }
- public static @bind.as("urlescape") char urlescape(char a, char b) { return ((char)((a-'0') * 16 + (b-'0'))); }
+ public static @bind.as("urlescape") char urlescape(char a, char b) { return ((char)((a-'0') * 16 + (b-'0'))); }
+ public static @bind String urlpath(String[] s) {
+ StringBuffer sb = new StringBuffer();
+ for(String st : s) sb.append(st);
+ return sb.toString();
+ }
}
public static void main(String[] s) throws Exception {
- try {
- Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
+ try {
+ Tree<String> res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(s[0])).expand1();
- AnnotationGrammarBindingResolver resolver = new AnnotationGrammarBindingResolver(TD.class);
+ AnnotationGrammarBindings resolver = new AnnotationGrammarBindings(TD.class);
resolver.add(MetaGrammarBindings.class, "meta");
- Union tibgram = MetaGrammar.make(res, "s", resolver);
+ Union tibgram = Grammar.create(res, "s", resolver);
System.err.println("parsing " + s[1]);
Tree t = new CharParser(tibgram).parse(new Tib(new FileInputStream(s[1]))).expand1();
p.println(sb);
p.flush();
p.close();
-
-
-
- /*
- System.out.println("parsing " + s[0]);
- Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
- MetaGrammar gram = new Tib.Grammar(TibDoc.class);
- gram = (MetaGrammar)gram.walk(res);
- System.out.println("\nparsing " + s[1]);
- Forest f = new CharParser(gram.done()).parse(new Tib(new FileInputStream(s[1])));
- System.out.println();
- System.out.println(f.expand1().toPrettyString());
- System.out.println();
-
-
- FileOutputStream fos = new FileOutputStream("out.html");
- PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));
- p.println(sb);
- p.flush();
- p.close();
- */
} catch (Ambiguous a) {
FileOutputStream fos = new FileOutputStream("/Users/megacz/Desktop/out.dot");
PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));