+
+ public static abstract class MetaClause {
+ public String label = null;
+ public boolean drop = false;
+ public boolean lift = false;
+ public abstract Element build(BuildContext bc);
+ public static MetaClause make(Tree<String> t, MetaConjunct c) {
+ //System.err.println("MetaClause.make("+t+")");
+ if (t.head().equals("{")) throw new Error("metatree: " + t);
+ if (t.head().equals("*")) return new MetaRepeat(make(t.child(0), c), false, null, true, true);
+ if (t.head().equals("+")) return new MetaRepeat(make(t.child(0), c), false, null, false, true);
+ if (t.head().equals("?")) return new MetaRepeat(make(t.child(0), c), false, null, true, false);
+ if (t.head().equals("**")) return new MetaRepeat(make(t.child(0), c), true, null, true, true);
+ if (t.head().equals("++")) return new MetaRepeat(make(t.child(0), c), true, null, false, true);
+ if (t.head().equals("*/")) return new MetaRepeat(make(t.child(0), c), false, make(t.child(1), c), true, true);
+ if (t.head().equals("+/")) return new MetaRepeat(make(t.child(0), c), false, make(t.child(1), c), false, true);
+ if (t.head().equals("**/")) return new MetaRepeat(make(t.child(0), c), true, make(t.child(1), c), true, true);
+ if (t.head().equals("++/")) return new MetaRepeat(make(t.child(0), c), true, make(t.child(1), c), false, true);
+ if (t.head().equals("()")) return new MetaEpsilon();
+ if (t.head().equals("[")) return new MetaRange(t.child(0));
+ if (t.head().equals("literal")) return new MetaStringLiteral(t.child(0));
+ if (t.head().equals("nonTerminal")) return new MetaNonterminalReference(t.child(0));
+ if (t.head().equals(")")) return new MetaSelfReference();
+ if (t.head().equals("(")) return new MetaParens(t.child(0));
+ if (t.head().equals("~")) return new MetaInvert(t.child(0), c);
+ if (t.head().equals("!")) { MetaClause mc = make(t.child(0), c); mc.drop = true; return mc; }
+ if (t.head().equals("^")) { c.tag = string(t.child(0)); return new MetaStringLiteral(t.child(0)); }
+ if (t.head().equals("^^")) throw new Error("carets: " + t);
+ throw new Error("unknown: " + t);
+ }
+ public static class MetaRepeat extends MetaClause {
+ public MetaClause element, separator;
+ public boolean maximal, zero, many;
+ public Element build(BuildContext bc) {
+ return new Repeat(element.build(bc), zero, many, separator==null?null:separator.build(bc), maximal);
+ }
+ public MetaRepeat(MetaClause element, boolean maximal, MetaClause separator, boolean zero, boolean many) {
+ this.separator = separator;
+ this.element = element;
+ this.maximal = maximal;
+ this.zero = zero;
+ this.many = many;
+ }
+ public String toString() {
+ return element+
+ ((zero&&!many)?"?":zero?"*":"+")+
+ (!maximal?"":zero?"*":"+")+
+ (separator==null?"":(" /"+separator));
+ }
+ }
+ public static class MetaParens extends MetaClause {
+ public MetaUnion body;
+ public MetaParens(Tree<String> t) { this.body = rhs(t); }
+ public String toString() { return "( " + body + " )"; }
+ public Element build(BuildContext bc) { return body.buildAnon(bc); }
+ }
+ /*
+ public static class MetaTree extends MetaClause {
+ public MetaConjunct body;
+ public MetaTree(Tree<String> t) { this.body = MetaConjunct.make(t); }
+ public String toString() { return "{ " + body + " }"; }
+ public Element build(BuildContext bc) {
+ return new Union("{}");// body.buildSequence();
+ }
+ }
+ */
+ public static class MetaEpsilon extends MetaClause {
+ public String toString() { return "()"; }
+ public Element build(BuildContext bc) { return Union.epsilon; }