return ret.toString();
}
- // FIXME
private static HashSet<Element> dropAll = new HashSet<Element>();
// Statics //////////////////////////////////////////////////////////////////////////////
// MetaGrammar //////////////////////////////////////////////////////////////////////////////
- public PreSequence _amp_(PreSequence p, Object[] o) { return p.and(new PreSequence(o, null).buildSequence(null, true, false, true)); }
- public PreSequence _amp__tilde_(PreSequence p, Object[] o) { return p.not(new PreSequence(o, null).buildSequence(null, true, false, true)); }
+ public PreSequence _amp_(PreSequence p, Object[] o) { return p.and(new PreSequence(o, null).buildSequence(null, true, false)); }
+ public PreSequence _amp__tilde_(PreSequence p, Object[] o) { return p.not(new PreSequence(o, null).buildSequence(null, true, false)); }
public Element epsilon(Object o, Object b) { return Union.epsilon; }
public Object _leftparen__rightparen_(Object o) { return Union.epsilon; }
public Element _rightparen_(Object e) { return SELF; }
public Union nonTerminal(String s) { return nonTerminal(s, null, false, false); }
public Union _colon__colon__equals_(String s, PreSequence[][] p) { return nonTerminal(s, p, false, false); }
public Union _bang__colon__colon__equals_(String s, PreSequence[][] p) { return nonTerminal(s, p, false, true); }
- public Union _colon__colon__equals_(boolean q, String s, PreSequence[][] p) { return nonTerminal(s, p, false, q); }
public Object _leftparen_(PreSequence[][] p) { return nonTerminal("anon"+(anon++), p, false, false); }
public Union nonTerminal(String str, PreSequence[][] s, boolean synthetic, boolean dropAll) {
Union n = str.equals(startSymbol) ? g : nt.get(str);
HashSet<Sequence> temp = new HashSet<Sequence>();
for(PreSequence pre : s[i]) {
pre.not.addAll(seqs);
- Sequence seq = pre.buildSequence(n, false, dropAll, false);
+ Sequence seq = pre.buildSequence(n, false, dropAll);
temp.add(seq);
n.add(seq);
}
new PreSequence[] {
new PreSequence(new Element[] { leftBrace(),
p.buildUnion(),
- rightBrace() })
+ rightBrace()
+ })
}
},
false,
false);
}
- public PreSequence rewrite(Object[] o) { return new PreSequence(o, null); }
-
- public PreSequence seqx(PreSequence p, String tag) { return _equals__greater_(p, tag); }
- public PreSequence _equals__greater_(PreSequence p, String tag) {
- p.tag = tag;
- return p;
- }
+ public PreSequence _equals__greater_(PreSequence p, String tag) { p.tag = tag; return p; }
public PreSequence ps(Object[] o) { return new PreSequence(o); }
public PreSequence ps2(Object[] o1, String s, Object[] o2) {
if (o2==null) o2 = new Object[0];
Object[] o3 = new Object[o1.length + o2.length + 1];
System.arraycopy(o1, 0, o3, 0, o1.length);
- Element es = string(s);
- //dropAll.add(es);
- o3[o1.length] = es;
+ o3[o1.length] = string(s);
System.arraycopy(o2, 0, o3, o1.length+1, o2.length);
PreSequence ret = new PreSequence(o3, s);
ret.drops[o1.length] = o3.length>1;
public Object _plus__plus_(final Element r) { return Repeat.maximal(Repeat.many1(r)); }
public Element _question_(final Element r) { return Repeat.maybe(r); }
- public MetaGrammar gram(Object o, MetaGrammar g, Object o2) { return g; }
- public MetaGrammar grammar(Object[] o) { return this; }
+ public Object walk(Tree<String> tree) {
+ String head = tree.head();
+ if (tree.numChildren()==0) return super.walk(tree);
+ if ("\\n".equals(head)) return new Character('\n');
+ else if ("\\r".equals(head)) return new Character('\r');
+ else return super.walk(tree);
+ }
+
public MetaGrammar grammar(Object o, Union[] u, Object x) { return this; }
- public char _backslash_n() { return '\n'; }
- public char _backslash_r() { return '\r'; }
+ public Object gram(Object o, Object g, Object o2) { return g; }
+ public MetaGrammar grammar(Object[] o) { return this; }
public Element literal(String s) { Element ret = string(s); dropAll.add(ret); return ret; }
public Range _minus_(char a, char b) { return new Range(a, b); }
public Range range(char a) { return new Range(a, a); }
return set(ret);
}
+ //////////////////////////////////////////////////////////////////////////////
+
public class PreSequence {
public final HashSet<Sequence> and = new HashSet<Sequence>();
public final HashSet<Sequence> not = new HashSet<Sequence>();
u.add(buildSequence(u));
return u;
}
- public Sequence buildSequence(Union u) { return buildSequence(u, false, false, false); }
- public Sequence buildSequence(Union u, boolean lame, boolean dropAll, boolean keeper) {
+ public Sequence buildSequence(Union u) { return buildSequence(u, false, false); }
+ public Sequence buildSequence(Union u, boolean lame, boolean dropAll) {
for(Sequence s : and) u.add(s);
for(Sequence s : not) u.add(s);
HashSet<Sequence> set = new HashSet<Sequence>();
}
}
Element[] expansion = o2;
- Sequence ret = dropAll || lame || keeper ? Sequence.drop(expansion, and, not, lame) : null;
- if (ret==null && tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
- if (ret==null) {
+ Sequence ret = null;
+ if (dropAll || lame) ret = Sequence.drop(expansion, and, not, lame);
+ 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;