return ret.toString();
}
- private static HashSet<Element> dropAll = new HashSet<Element>();
+ public /*private*/ static HashSet<Element> dropAll = new HashSet<Element>();
// Statics //////////////////////////////////////////////////////////////////////////////
startSymbol = str;
nt = new HashMap<String,Union>();
dropAll = new HashSet<Element>();
+ dropAll.add(leftBrace());
+ dropAll.add(rightBrace());
nt.put(str, g);
return ret;
}
// MetaGrammar //////////////////////////////////////////////////////////////////////////////
+ public Union nonTerminal(String str) { return nonTerminal(str, null, false, false); }
public Union nonTerminal(String str, PreSequence[][] s, boolean synthetic, boolean dropAll) {
Union n = str.equals(startSymbol) ? g : nt.get(str);
if (n == null) nt.put(str, n = new Union(str, synthetic));
PreSequence ret = new PreSequence(o3, s);
ret.drops[o1.length] = o3.length>1;
return ret;
- } else if ("{".equals(head))
- return nonTerminal("braced"+(anon++),
- new PreSequence[][] {
- new PreSequence[] {
- new PreSequence(new Element[] { leftBrace(),
- ((PreSequence)walk(tree, 0)).buildUnion(),
- rightBrace()
- })
- }
- },
- false,
- false);
- else if ("[".equals(head) || "[~".equals(head)) {
+ } else if ("[".equals(head) || "[~".equals(head)) {
boolean positive = "[".equals(head);
Range[] rr = (Range[])walk(tree, 0);
Range.Set ret = positive ? new Range.Set() : new Range.Set(new Range(true, true));
else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
else {
int idx = -1;
- for(int i=0; i<expansion.length; i++) {
- if (!drops[i]) idx = i;
- else expansion[i] = expansion[i];
- }
- ret = idx==-1 ? Sequence.drop(expansion, and, not, false) : Sequence.singleton(expansion, idx, and, not);
+ for(int i=0; i<expansion.length; i++)
+ if (!drops[i])
+ if (idx==-1) idx = i;
+ else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,null,null,false));
+ if (idx != -1) return Sequence.singleton(expansion, idx, and, not);
+ return Sequence.drop(expansion, and, not, false);
}
set.add(ret);
return ret;