From dda22f5fe5cc0b84264c1a0d3369048c81a140f2 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 15 Jul 2006 01:32:04 -0400 Subject: [PATCH] checkpoint darcs-hash:20060715053204-5007d-7e165220811d26d9c4fd154cd5981450f77f578c.gz --- Makefile | 4 +- src/edu/berkeley/sbp/GSS.java | 4 +- src/edu/berkeley/sbp/bind/Bindable.java | 80 ++++++++------- src/edu/berkeley/sbp/meta/MetaGrammarBindings.java | 14 +-- src/edu/berkeley/sbp/tib/TibDoc.java | 106 ++++++++++---------- tests/tibdoc.g | 12 ++- 6 files changed, 117 insertions(+), 103 deletions(-) diff --git a/Makefile b/Makefile index 1154ad2..da56cde 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -java = java +java = java -Xmx900m tibdoc: edu.berkeley.sbp.jar $(java) -cp $< edu.berkeley.sbp.tib.TibDoc \ tests/tibdoc.g \ - tests/tib.in + tests/bitstream.tib demo: edu.berkeley.sbp.jar $(java) -cp $< edu.berkeley.sbp.misc.Demo \ diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index 9c4b62b..8412471 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -338,7 +338,9 @@ public class GSS { Forest[] holder = r.holder; Forest old = holder[pos]; - for(Forest result : results()) + HashSet rr = new HashSet(); + for(Forest result : results()) rr.add(result); + for(Forest result : rr) for(Node child : ((Forest.Ref)result).parents) { if (only != null && child!=only) continue; holder[pos] = result; diff --git a/src/edu/berkeley/sbp/bind/Bindable.java b/src/edu/berkeley/sbp/bind/Bindable.java index ccaa51d..8f5cc86 100644 --- a/src/edu/berkeley/sbp/bind/Bindable.java +++ b/src/edu/berkeley/sbp/bind/Bindable.java @@ -22,49 +22,19 @@ public abstract class Bindable implements ToJava { public abstract String[] getArgNames(); public abstract Class[] getArgTypes(); - public static Bindable create(Object o) { - if (o instanceof Class) return new BindableClass((Class)o); - if (o instanceof Method) return new BindableMethod((Method)o); - if (o instanceof Constructor) return new BindableConstructor((Constructor)o); - return null; - } - public Binding createBinding() { return new SimpleBinding(); } public Binding createBinding(final int[] map) { return new SimpleBinding(map); } public Binding createBinding(final int[] map, Object prepend) { return new SimpleBinding(map, prepend); } - public class SimpleBinding implements Binding, ToJava { - private int[] map = null; - private Object prepend = null; - public SimpleBinding() { } - public SimpleBinding(int[] map) { this.map = map; } - public SimpleBinding(int[] map, Object prepend) { this.map = map; this.prepend = prepend; } - - public Object invoke(Object[] o) { - if (map==null) return impose(o); - int max = 0; - for(int i=0; i= 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", @@ -678,12 +692,17 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix 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 { + try { Tree res = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream(s[0])).expand1(); AnnotationGrammarBindings resolver = new AnnotationGrammarBindings(TD.class); @@ -706,27 +725,6 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix p.println(sb); p.flush(); p.close(); - - - - /* - System.out.println("parsing " + s[0]); - Tree 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)); diff --git a/tests/tibdoc.g b/tests/tibdoc.g index 072c625..8a0928a 100644 --- a/tests/tibdoc.g +++ b/tests/tibdoc.g @@ -63,7 +63,7 @@ Body = { Section } */ws Section = SectionHeader ws! Paragraph* SectionHeader = "==" SectionHeaderBody "==" SectionHeaderBody = "=" SectionHeaderBody "=" - > ws! alphanum++ ws! + > ws! text ws! sp = " "** blank = sp! "\n" sp! "\n" ws! @@ -74,6 +74,8 @@ num = [0-9]++ Paragraph = { Blockquote:: "\"\" " text } > HR:: { "---" "-"* } + > P:: { UL:: uli+/ws } + > P:: { OL:: oli+/ws } > P:: { text } onums = nums (". "|") ")! @@ -95,7 +97,7 @@ Item*/ws = > structured > styled > (Chars:: alphanum++) - > "\"" text "\"" + > Quotes:: "\"" text "\"" > (Symbol:: sym++) > { Block:: text } @@ -123,7 +125,8 @@ styled = Underline:: "__" text "__" block = { text } -link = text:({ text }|word) "->" href:(url|email) +link = text:({ text }|word) "->" ws! href:href +href = url | email | {href} structured = command & "\\" ([a-zA-Z0-9]++)! block? > glyph @@ -161,7 +164,8 @@ url = Mailto:: "mailto" ":" email -> ~urlv host:host port:(":" nums)? path:("/" urlpath)? - -> ~urlv + ref:("#" urlpath)? + -> ~(urlv|[\#]) url_login = Login:: username:username password:(":" password) "@" method = [+\-.a-z0-9]+ domain = (part +/ ".") -> ~"." -- 1.7.10.4