_____________________________________________________________________________
Immediately
+ - The repeat API's in Sequence are ugly
+ - segregate the sequence static-constructors?
+
- Sequence shouldn't be an Element -> make Union.add(Element)
- Should Tree<T> really be type-parameterized?
-
- - More topology untangling
- - needs/hates/follow API ugliness
-
- do Forest/Tree still need a Region?
+
- reconsider the degree of genericization
- - GraphViz stuff pollutes the API...
+
+ - grammar highlighting?
+ - comment indentation vs block indentation?
+ - { and } in <pre>
+ - recursive { { foo } }
+
+ - More topology untangling
- Forest needs a "manual access" API
- the unwrap bit in Forest makes it really hard to expose an API for forests
- copyright notices
- documentation
- - grammar highlighting?
- - comment indentation vs block indentation?
- - { and } in <pre>
- - recursive { { foo } }
______________________________________________________________________________
v1.1
+++ /dev/null
-package edu.berkeley.sbp;
-import edu.berkeley.sbp.util.*;
-import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.*;
-import java.io.*;
-import java.util.*;
-import java.lang.reflect.*;
-import java.lang.ref.*;
-
-/** currently this class exports only static methods to create repetitions; there are no public instance methods or constructors */
-class Repeat extends Union {
-
- public Repeat(final Element e, boolean zeroOkay, boolean manyOkay, Object tag) {
- this(e, zeroOkay, manyOkay, null, false, tag); }
- public Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, Object tag) {
- this(e, zeroOkay, manyOkay, separator, false, tag); }
- protected Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, boolean maximal, Object tag) {
- super(e+(!manyOkay ? "?" : (zeroOkay ? (maximal ? "**" : "*") : (maximal ? "++" : "+")))+(separator==null?"":("/"+separator)), true);
- if (zeroOkay && !manyOkay) {
- add(new Sequence.Constant.Empty());
- add(new Sequence.Singleton(e));
- return;
- }
- if (zeroOkay) {
- add(new Sequence.RewritingSequence(tag, new Element[] { }, null));
- //add(new Sequence.Constant.Empty());
- // FUGLY
- add(new Sequence.Singleton(Sequence.many1(e, separator, tag)));
- } else {
- add(new Sequence.RewritingSequence(tag, new Element[] { e }, null));
- if (separator==null)
- add(new Sequence.Unwrap(new Element[] { e, Repeat.this }, tag));
- else
- add(new Sequence.Unwrap(new Element[] { e, separator, Repeat.this }, tag, new boolean[] { false, true, false }));
- }
- }
-
- public static class Maximal extends Repeat {
- public Maximal(final Element e, boolean zeroOkay, boolean manyOkay, final Atom separator, Object tag) {
- super(e, zeroOkay, manyOkay, separator, true, tag);
- if (zeroOkay && separator != null)
- throw new RuntimeException("cannot create a maximal repetition of zero or more items with a separator (yet): " + this);
- for(Sequence s : this)
- s.follow = (Atom)separator.complement();
- }
- public Maximal(final Atom e, boolean zeroOkay, boolean manyOkay, Object tag) {
- super(e, zeroOkay, manyOkay, null, true, tag);
- for(Sequence s : this)
- s.follow = (Atom)e.complement();
- }
- }
-
-}
}
/** the empty sequence (matches the empty string) */
- public static final Sequence empty = new Sequence.Constant.Empty();
+ static final Sequence empty = new Sequence.Constant.Empty();
+ public static Sequence empty() { return empty; }
/** after matching the sequence, do not add anything to the output tree */
public static Sequence drop(Element[] e) { return new Constant.Drop(e); }
public Sequence not(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); return ret; }
public Sequence followedBy(Atom a) { Sequence ret = dup(); ret.follow = a; return ret; }
- public Iterable<Sequence> needs() { return needs; }
- public Iterable<Sequence> hates() { return hates; }
+ Iterable<Sequence> needs() { return needs; }
+ Iterable<Sequence> hates() { return hates; }
Position firstp() { return firstp; }
Sequence _clone() { return new Singleton(elements,idx); }
}
- public static Unwrap unwrap(Element[] e, Object tag, boolean[] drops) { return new Unwrap(e, tag, drops); }
+ public static Sequence unwrap(Element[] e, Object tag, boolean[] drops) { return new Unwrap(e, tag, drops); }
static class Unwrap extends Sequence {
private boolean[] drops;
private final Object tag;
public Unwrap(Element[] e, Object tag) { super(e); this.drops = null; this.tag = tag; }
public Unwrap(Element[] e, Object tag, boolean[] drops) { super(e); this.drops = drops; this.tag = tag; }
- Sequence _clone() { return new Unwrap(elements, drops); }
+ Sequence _clone() { return new Unwrap(elements, tag, drops); }
public <T> Forest<T> postReduce(Input.Region loc, Forest<T>[] args, Position p) {
for(int i=0; i<args.length; i++) if (args[i]==null) throw new Error();
if (drops==null) return Forest.create(loc, (T)tag, args, true);
}
}
- // Repeat //////////////////////////////////////////////////////////////////////////////
-
- /** repeat zero or one times */
- public static Element maybe(Element e) { return new Repeat(e, true, false, null, null); }
- public static Element maybe(Element e, Object tag) { return new Repeat(e, true, false, null, tag); }
- /** repeat zero or more times */
- public static Element many0(Element e) { return new Repeat(e, true, true, null, null); }
- public static Element many0(Element e, Object tag) { return new Repeat(e, true, true, null, tag); }
- /** repeat zero or more times, separated by <tt>sep</tt> */
- public static Element many0(Element e, Element sep) { return new Repeat(e, true, true, sep, null); }
- public static Element many0(Element e, Element sep, Object tag) { return new Repeat(e, true, true, sep, tag); }
- /** repeat one or more times */
- public static Element many1(Element e) { return new Repeat(e, false, true, null, null); }
- public static Element many1(Element e, Object tag) { return new Repeat(e, false, true, null, tag); }
- /** repeat one or more times, separated by <tt>sep</tt> */
- public static Element many1(Element e, Element sep) { return new Repeat(e, false, true, sep, null); }
- public static Element many1(Element e, Element sep, Object tag) { return new Repeat(e, false, true, sep, tag); }
-
- /** repeat zero or more times, matching a maximal sequence of atoms */
- public static Element maximal0(Atom e) { return new Repeat.Maximal(e, true, true, null); }
- public static Element maximal0(Atom e, Object tag) { return new Repeat.Maximal(e, true, true, tag); }
- /** repeat one or more times, matching a maximal sequence of atoms */
- public static Element maximal1(Atom e) { return new Repeat.Maximal(e, false, true, null); }
- public static Element maximal1(Atom e, Object tag) { return new Repeat.Maximal(e, false, true, tag); }
- /** repeat one or more times, separated by an atom <tt>sep</tt>, matching a maximal sequence */
- public static Element maximal1(Element e, Atom sep) { return new Repeat.Maximal(e, false, true, sep, null); }
- public static Element maximal1(Element e, Atom sep, Object tag) { return new Repeat.Maximal(e, false, true, sep, tag); }
-
- public static Element repeatMaximal(Atom e, boolean zero, boolean many, Object tag) {
- return new Repeat.Maximal(e, zero, many, tag); }
- public static Element repeatMaximal(Element e, boolean zero, boolean many, Atom sep, Object tag) {
- return new Repeat.Maximal(e, zero, many, sep, tag); }
- public static Element repeat(Element e, boolean zero, boolean many, Object tag) {
- return new Repeat(e, zero, many, tag); }
- public static Element repeat(Element e, boolean zero, boolean many, Element sep, Object tag) {
- return new Repeat(e, zero, many, sep, tag); }
}
}
private static Union epsilon = new Union("()");
- static { epsilon.add(Sequence.empty); }
+ static { epsilon.add(Sequence.empty()); }
public Topology<Atom<Character>> unwrap() { return this; }
public Topology<Atom<Character>> empty() { return new CharAtom(); }
HashSet<Sequence> bad2 = new HashSet<Sequence>();
Union urep = new Union(null, false);
- urep.add(Sequence.empty);
+ urep.add(Sequence.empty());
if (sep != null)
urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1));
else
public static @bind.as("()") ElementNode epsilon() { return new Constant(epsilon); }
private static Union epsilon = new Union("()");
- static { epsilon.add(Sequence.empty); }
+ static { epsilon.add(Sequence.empty()); }
public static class NonTerminalReferenceNode extends ElementNode {
public String nonTerminal;
}
public Element build(Context cx, NonTerminalNode cnt) {
return (!max)
- ? Sequence.repeat(e.build(cx, null), zero, many, sep==null ? null : sep.build(cx, null), cx.rm.repeatTag())
+ ? Repeat.repeat(e.build(cx, null), zero, many, sep==null ? null : sep.build(cx, null), cx.rm.repeatTag())
: sep==null
- ? Sequence.repeatMaximal(e.toAtom(cx), zero, many, cx.rm.repeatTag())
- : Sequence.repeatMaximal(e.build(cx, null), zero, many, sep.toAtom(cx), cx.rm.repeatTag());
+ ? Repeat.repeatMaximal(e.toAtom(cx), zero, many, cx.rm.repeatTag())
+ : Repeat.repeatMaximal(e.build(cx, null), zero, many, sep.toAtom(cx), cx.rm.repeatTag());
}
}
--- /dev/null
+package edu.berkeley.sbp.meta;
+import edu.berkeley.sbp.util.*;
+import edu.berkeley.sbp.*;
+import java.io.*;
+import java.util.*;
+import java.lang.reflect.*;
+import java.lang.ref.*;
+
+/** currently this class exports only static methods to create repetitions; there are no public instance methods or constructors */
+public class Repeat extends Union {
+
+ public Repeat(final Element e, boolean zeroOkay, boolean manyOkay, Object tag) {
+ this(e, zeroOkay, manyOkay, null, false, tag); }
+ public Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, Object tag) {
+ this(e, zeroOkay, manyOkay, separator, false, tag); }
+ protected Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, boolean maximal, Object tag) {
+ this(e, zeroOkay, manyOkay, separator, maximal, tag, null); }
+ protected Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, boolean maximal, Object tag, Atom follow) {
+ super(e+(!manyOkay ? "?" : (zeroOkay ? (maximal ? "**" : "*") : (maximal ? "++" : "+")))+(separator==null?"":("/"+separator)), true);
+ if (zeroOkay && !manyOkay) {
+ add(Sequence.empty().followedBy(follow));
+ add(Sequence.singleton(e).followedBy(follow));
+ return;
+ }
+ if (zeroOkay) {
+ add(Sequence.rewritingSequence(tag, new Element[] { }, null).followedBy(follow));
+ //add(new Sequence.Constant.Empty());
+ // FUGLY
+ add(Sequence.singleton(many1(e, separator, tag)).followedBy(follow));
+ } else {
+ add(Sequence.rewritingSequence(tag, new Element[] { e }, null).followedBy(follow));
+ if (separator==null)
+ add(Sequence.unwrap(new Element[] { e, Repeat.this }, tag, new boolean[] { false, false }).followedBy(follow));
+ else
+ add(Sequence.unwrap(new Element[] { e, separator, Repeat.this }, tag, new boolean[] { false, true, false }).followedBy(follow));
+ }
+ }
+
+ public static class Maximal extends Repeat {
+ public Maximal(final Element e, boolean zeroOkay, boolean manyOkay, final Atom separator, Object tag) {
+ super(e, zeroOkay, manyOkay, separator, true, tag, (Atom)separator.complement());
+ if (zeroOkay && separator != null)
+ throw new RuntimeException("cannot create a maximal repetition of zero or more items with a separator (yet): " + this);
+ }
+ public Maximal(final Atom e, boolean zeroOkay, boolean manyOkay, Object tag) {
+ super(e, zeroOkay, manyOkay, null, true, tag, (Atom)e.complement());
+ }
+ }
+
+ /** repeat zero or one times */
+ public static Element maybe(Element e) { return new Repeat(e, true, false, null, null); }
+ public static Element maybe(Element e, Object tag) { return new Repeat(e, true, false, null, tag); }
+ /** repeat zero or more times */
+ public static Element many0(Element e) { return new Repeat(e, true, true, null, null); }
+ public static Element many0(Element e, Object tag) { return new Repeat(e, true, true, null, tag); }
+ /** repeat zero or more times, separated by <tt>sep</tt> */
+ public static Element many0(Element e, Element sep) { return new Repeat(e, true, true, sep, null); }
+ public static Element many0(Element e, Element sep, Object tag) { return new Repeat(e, true, true, sep, tag); }
+ /** repeat one or more times */
+ public static Element many1(Element e) { return new Repeat(e, false, true, null, null); }
+ public static Element many1(Element e, Object tag) { return new Repeat(e, false, true, null, tag); }
+ /** repeat one or more times, separated by <tt>sep</tt> */
+ public static Element many1(Element e, Element sep) { return new Repeat(e, false, true, sep, null); }
+ public static Element many1(Element e, Element sep, Object tag) { return new Repeat(e, false, true, sep, tag); }
+
+ /** repeat zero or more times, matching a maximal sequence of atoms */
+ public static Element maximal0(Atom e) { return new Repeat.Maximal(e, true, true, null); }
+ public static Element maximal0(Atom e, Object tag) { return new Repeat.Maximal(e, true, true, tag); }
+ /** repeat one or more times, matching a maximal sequence of atoms */
+ public static Element maximal1(Atom e) { return new Repeat.Maximal(e, false, true, null); }
+ public static Element maximal1(Atom e, Object tag) { return new Repeat.Maximal(e, false, true, tag); }
+ /** repeat one or more times, separated by an atom <tt>sep</tt>, matching a maximal sequence */
+ public static Element maximal1(Element e, Atom sep) { return new Repeat.Maximal(e, false, true, sep, null); }
+ public static Element maximal1(Element e, Atom sep, Object tag) { return new Repeat.Maximal(e, false, true, sep, tag); }
+
+ public static Element repeatMaximal(Atom e, boolean zero, boolean many, Object tag) {
+ return new Repeat.Maximal(e, zero, many, tag); }
+ public static Element repeatMaximal(Element e, boolean zero, boolean many, Atom sep, Object tag) {
+ return new Repeat.Maximal(e, zero, many, sep, tag); }
+ public static Element repeat(Element e, boolean zero, boolean many, Object tag) {
+ return new Repeat(e, zero, many, tag); }
+ public static Element repeat(Element e, boolean zero, boolean many, Element sep, Object tag) {
+ return new Repeat(e, zero, many, sep, tag); }
+}