- 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==null) return new MetaEpsilon();
- if (t.head()==null) return new MetaEpsilon();
- 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 @bind.as void range(char c) { }
+ public static class Range {
+ public @bind.as("range") Range(char only) { first = only; last = only; }
+ public @bind.as("-") Range(char first, char last) { this.first = first; this.last = last; }
+ public char first;
+ public char last;
+ }
+ public static abstract class El {
+ public String getLabel() { return null; }
+ public String getOwnerTag() { return null; }
+ public boolean drop() { return false; }
+ public abstract Element build(Context cx);
+ }
+ public static class Drop extends El {
+ public El e;
+ public Drop(El e) { this.e = e; }
+ public String getLabel() { return null; }
+ public boolean drop() { return true; }
+ public String getOwnerTag() { return e.getOwnerTag(); }
+ public Element build(Context cx) { return e.build(cx); }
+ }
+ public static class Label extends El {
+ public String label;
+ public El e;
+ public Label(String label, El e) { this.e = e; this.label = label; }
+ public String getLabel() { return label; }
+ public String getOwnerTag() { return e.getOwnerTag(); }
+ public Element build(Context cx) { return e.build(cx); }
+ }
+ public static /*abstract*/ class Seq {
+ HashSet<Seq> and = new HashSet<Seq>();
+ HashSet<Seq> not = new HashSet<Seq>();
+ El[] elements;
+ El follow;
+ String tag = null;
+ boolean lame;
+ public Seq(El e) { this(new El[] { e }); }
+ public Seq(El[] elements) { this.elements = elements; }
+ public Seq tag(String tag) { this.tag = tag; return this; }
+ public Seq follow(El follow) { this.follow = follow; return this; }
+ public Seq dup() {
+ Seq ret = new Seq(elements);
+ ret.and.addAll(and);
+ ret.not.addAll(not);
+ ret.follow = follow;
+ ret.tag = tag;
+ return ret;