Atom ret = null;
for(Seq[] ss : sequences)
for(Seq s : ss)
- ret = ret==null ? s.toAtom(cx) : infer(ret.union(s.toAtom(cx)));
+ ret = ret==null ? s.toAtom(cx) : (Atom)ret.union(s.toAtom(cx));
return ret;
}
public void build(Context cx, Union u, NonTerminalNode cnt) {
HashSet<Sequence> bad2 = new HashSet<Sequence>();
for(int i=0; i<sequences.length; i++) {
Seq[] group = sequences[i];
- Union u2 = new Union();
+ Union u2 = new Union(null, false);
if (sequences.length==1) u2 = u;
for(int j=0; j<group.length; j++) {
- group[j].build(cx, u2, false, cnt);
+ group[j].build(cx, u2, cnt);
}
if (sequences.length==1) break;
Sequence seq = Sequence.singleton(u2);
- for(Sequence s : bad2) {
- s.lame = true;
- seq = seq.not(s);
- }
+ for(Sequence s : bad2) seq = seq.not(s);
u.add(seq);
bad2.add(Sequence.singleton(u2));
}
if (!rep) { super.build(cx, u, this); return; }
HashSet<Sequence> bad2 = new HashSet<Sequence>();
- Union urep = new Union();
+ Union urep = new Union(null, false);
urep.add(Sequence.empty);
if (sep != null)
urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1));
for(int i=0; i<sequences.length; i++) {
Seq[] group = sequences[i];
- Union u2 = new Union();
+ Union u2 = new Union(null, false);
if (sequences.length==1) u2 = u;
for(int j=0; j<group.length; j++) {
- Union u3 = new Union();
- group[j].build(cx, u3, false, this);
+ Union u3 = new Union(null, false);
+ group[j].build(cx, u3, this);
Sequence s = Sequence.unwrap(new Element[] { u3, urep },
cx.rm.repeatTag(),
new boolean[] { false, false });
}
if (sequences.length==1) break;
Sequence seq = Sequence.singleton(u2);
- for(Sequence s : bad2) {
- s.lame = true;
- seq = seq.not(s);
- }
+ for(Sequence s : bad2) seq = seq.not(s);
u.add(seq);
bad2.add(Sequence.singleton(u2));
}
this.sequences = sequences;
}
public Element build(Context cx, NonTerminalNode cnt) {
- Union ret = new Union();
+ Union ret = new Union(null, false);
build(cx, ret, cnt);
return ret;
}
ElementNode[] elements;
ElementNode follow;
String tag = null;
- boolean lame;
public void append(ElementNode e) {
ElementNode[] elements = new ElementNode[this.elements.length+1];
System.arraycopy(this.elements, 0, elements, 0, this.elements.length);
ret.tag = prefix+tag;
return ret;
}
- public Seq and(Seq s) { and.add(s); s.lame = true; return this; }
- public Seq andnot(Seq s) { not.add(s); s.lame = true; return this; }
+ public Seq and(Seq s) { and.add(s); return this; }
+ public Seq andnot(Seq s) { not.add(s); return this; }
public Seq separate(ElementNode sep) {
ElementNode[] elements = new ElementNode[this.elements.length * 2 - 1];
for(int i=0; i<this.elements.length; i++) {
this.elements = elements;
return this;
}
- public Sequence build(Context cx, Union u, boolean lame, NonTerminalNode cnt) {
- Sequence ret = build0(cx, lame || this.lame, cnt);
- for(Seq s : and) { Sequence dork = s.build(cx, u, true, cnt); ret = ret.and(dork); }
- for(Seq s : not) { Sequence dork = s.build(cx, u, true, cnt); ret = ret.not(dork); }
+ public Sequence build(Context cx, Union u, NonTerminalNode cnt) {
+ Sequence ret = build0(cx, cnt);
+ for(Seq s : and) { Sequence dork = s.build(cx, u, cnt); ret = ret.and(dork); }
+ for(Seq s : not) { Sequence dork = s.build(cx, u, cnt); ret = ret.not(dork); }
u.add(ret);
- ret.lame = lame;
return ret;
}
- public Sequence build0(Context cx, boolean lame, NonTerminalNode cnt) {
- boolean dropAll = lame;
+ public Sequence build0(Context cx, NonTerminalNode cnt) {
+ boolean dropAll = false;
if (tag!=null && tag.endsWith("()")) dropAll = true;
boolean[] drops = new boolean[elements.length];
Element[] els = new Element[elements.length];
tag = elements[i].getOwnerTag();
}
Sequence ret = null;
- if (dropAll) ret = Sequence.drop(els, false);
+ if (dropAll) ret = Sequence.drop(els);
else {
Production prod = new Production(tag, (cnt==null?null:cnt.name), els, drops);
ret = cx.rm.createSequence(prod);
for(int i=0; i<els.length; i++)
if (!drops[i])
if (idx==-1) idx = i;
- else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(els, false));
+ else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(els));
if (idx != -1) ret = Sequence.singleton(els, idx);
- else ret = Sequence.drop(els, false);
+ else ret = Sequence.drop(els);
}
}
if (this.follow != null)
ret.follow = this.follow.toAtom(cx);
- ret.lame = this.lame;
return ret;
}
}
public static @bind.as("{") class XTree extends ElementNode {
public @bind.arg Seq body;
public Element build(Context cx, NonTerminalNode cnt) {
- Union u = new Union();
- Sequence s = body.build(cx, u, false, null);
- Union u2 = new Union();
+ Union u = new Union(null, false);
+ Sequence s = body.build(cx, u, null);
+ Union u2 = new Union(null, false);
u2.add(Sequence.singleton(new Element[] {
CharAtom.leftBrace,
cx.get("ws"),
public static @bind.as("\r") String lf() { return "\r"; }
//static Atom infer(Element e) { return infer((Topology<Character>)Atom.toAtom(e)); }
- static Atom infer(Topology<Character> t) { return new CharAtom(new CharTopology(t)); }
+ static Atom infer(Object t) { return (Atom)t; }
public static class Context {
public HashMap<String,Union> map = new HashMap<String,Union>();
public String getLabel() { return label; }
}
+ /*
static class Invert extends Atom {
private final Atom a;
public Invert(Atom a) { this.a = a; }
public Topology top() { return a.complement(); }
public String toString() { return "~"+a; }
}
+ */
}