carets.put(ret, s);
dropAll.add(ret);
return ret;
+ /*
} else if ("^^".equals(head)) {
return new Keep(walk(tree,0));
+ */
} else if ("psx".equals(head)) return ((PreSequence)walk(tree, 0)).buildSequence();
else if ("nonTerminal".equals(head)) return getNonTerminal(string(tree.child(0)));
else if ("::=".equals(head)) return nonTerminal(string(tree.child(0)), (Sequence[][])Reflection.lub(walk(tree, 1)), false, false);
else if ("ps".equals(head)) return new PreSequence((Object[])walk(tree,0), null);
else if (":".equals(head)) {
String s = string(tree.child(0));
- return new Keep("_".equals(s)?walk(tree,1):new PreSequence(new Object[] { walk(tree, 1) }, convertLabel(s)).buildUnion());
+ return new Keep(s,walk(tree,1));
} else if ("::".equals(head)) {
PreSequence p = (PreSequence)walk(tree, 1);
- p.tag = convertLabel(string(tree.child(0)));
+ String s = string(tree.child(0));
+ if (s.equals("[]")) p.unwrap = true;
+ else p.tag = convertLabel(s);
return p;
}
else if ("=>".equals(head)) {
}
static class Keep {
- final Object o;
- public Keep(Object o) { this.o = o; }
+ public final String label;
+ public final Object o;
+ public Keep(String label, Object o) { this.label = label; this.o = o; }
}
- public String convertLabel(String label) { return label; }
+ public Object convertLabel(String label) { return label; }
public Object walk(String tag, Object[] argo) {
if (argo.length==0) return super.walk(tag, argo);
public Element noFollow = null;
public final HashSet<Sequence> and = new HashSet<Sequence>();
public final HashSet<Sequence> not = new HashSet<Sequence>();
- public /*final*/ String tag;
+ public /*final*/ Object tag;
public final Object[] o;
public PreSequence sparse(Object e) {
boolean[] drops = null;
public PreSequence(Object o) { this(new Object[] { o }, null); }
public PreSequence(Object[] o) { this(o, null); }
- public PreSequence(Object[] o, String tag) { this(o, tag, null); }
- public PreSequence(Object[] o, String tag, boolean[] drops) {
+ public PreSequence(Object[] o, Object tag) { this(o, tag, null); }
+ public PreSequence(Object[] o, Object tag, boolean[] drops) {
this.o = o;
this.tag = tag;
this.drops = drops==null ? new boolean[o.length] : drops;
public boolean unwrap = false;
public Sequence buildSequence() { return buildSequence(null, false, false); }
public Sequence buildSequence(Union u) { return buildSequence(u, false, false); }
- public Sequence buildSequence(Union u, boolean lame, String tag) {
+ public Sequence buildSequence(Union u, boolean lame, Object tag) {
this.tag = tag;
return buildSequence(u, lame, false);
}
}
HashSet<Sequence> set = new HashSet<Sequence>();
Element[] o2 = o==null ? new Element[0] : new Element[o.length];
+ Object[] labels = new Object[drops.length];
int nonDrop = 0;
boolean keeping = false;
if (o != null) {
if (!keeping) { for(int k=0; k<i; k++) drops[k]=true; }
drops[i] = false;
keeping = true;
+ labels[i] = ((Keep)oi).label;
oi = ((Keep)oi).o;
} else {
if (keeping) drops[i] = true;
Sequence ret = null;
if (dropAll || lame) ret = Sequence.drop(expansion, lame);
else if (unwrap) ret = new Sequence.Unwrap(expansion, drops);
- else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, null, drops);
+ else if (keeping || tag!=null) ret = Sequence.rewritingSequence(tag, expansion, labels, drops);
else {
int idx = -1;
for(int i=0; i<expansion.length; i++)
+
+
+
// DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED
new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "=", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "s", new edu.berkeley.sbp.Tree[] { })}),
new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "psx", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "ps", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "!", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "nonTerminal", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "w", new edu.berkeley.sbp.Tree[] { }),
+
+
+