// MetaGrammar //////////////////////////////////////////////////////////////////////////////
- public Union nonTerminal(String str) { return nonTerminal(str, null, false, false); }
- public Union nonTerminal(String str, PreSequence[][] s, boolean synthetic, boolean dropAll) {
+ public Union getNonTerminal(String str) { return nonTerminal(str, null, false, false); }
+ private Union nonTerminal(String str) { return nonTerminal(str, null, false, false); }
+ public Union anonymousNonTerminal(PreSequence[][] s) {
+ return nonTerminal("anon"+(anon++), s, false, false);
+ }
+ private 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));
if (dropAll) this.dropAll.add(n);
else if ("epsilon".equals(head)) return Union.epsilon;
else if ("()".equals(head)) return Union.epsilon;
else if (")".equals(head)) return SELF;
- else if ("nonTerminal".equals(head)) return nonTerminal(string(tree.child(0)), null, false, false);
+ else if ("nonTerminal".equals(head)) return getNonTerminal(string(tree.child(0)));
else if ("::=".equals(head)) return nonTerminal(string(tree.child(0)), (PreSequence[][])walk(tree, 1), false, false);
else if ("!::=".equals(head)) return nonTerminal(string(tree.child(0)), (PreSequence[][])walk(tree, 1), false, true);
- else if ("(".equals(head)) return nonTerminal("anon"+(anon++), (PreSequence[][])walk(tree, 0), false, false);
+ else if ("(".equals(head)) return buildUnion((PreSequence[][])walk(tree, 0));
else if ("literal".equals(head)) { Element ret = string(string(tree.child(0))); dropAll.add(ret); return ret; }
else if ("-".equals(head)) return new Range(walk(tree, 0).toString().charAt(0), walk(tree,1).toString().charAt(0));
else if ("range".equals(head)) return new Range(walk(tree, 0).toString().charAt(0), walk(tree,0).toString().charAt(0));
return super.walk(tag, argo);
}
+ public Union buildUnion(PreSequence[][] p) {
+ return anonymousNonTerminal(p);
+ }
+
//////////////////////////////////////////////////////////////////////////////
public class PreSequence {
this.drops = drops==null ? new boolean[o.length] : drops;
}
- public Union buildUnion() {
- Union u = new Union("???");
+ public Union buildUnion(String s) {
+ Union u = new Union(s);
u.add(buildSequence(u));
return u;
}
+ public Union buildUnion() { return buildUnion("???"); }
public boolean unwrap = false;
public Sequence buildSequence(Union u) { return buildSequence(u, false, false); }
public Sequence buildSequence(Union u, boolean lame, boolean dropAll) {
}
Element[] expansion = o2;
Sequence ret = null;
- if (dropAll || lame) ret = Sequence.drop(expansion, and, not, lame);
+ if (dropAll || lame) {
+ ret = Sequence.drop(expansion, lame);
+ for(Sequence s : and) ret = ret.and(s);
+ for(Sequence s : not) ret = ret.not(s);
+ }
else if (unwrap) ret = new Sequence.Unwrap(expansion, drops, and, not);
else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
else {
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));
+ else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,false));
if (idx != -1) ret = Sequence.singleton(expansion, idx, and, not);
- else ret = Sequence.drop(expansion, and, not, false);
+ else {
+ ret = Sequence.drop(expansion, false);
+ for(Sequence s : and) ret = ret.and(s);
+ for(Sequence s : not) ret = ret.not(s);
+ }
}
set.add(ret);
if (this.noFollow != null) ret.noFollow = new Atom.Invert(new Atom.Infer(this.noFollow));