* parsing with this Union should be provided to <tt>buildFromAST</tt>
*/
public static Union getMetaGrammar() {
- return MetaGrammar.newInstance();
+ return buildFromAST(MetaGrammar.meta, "s", new File[0]);
}
/**
if (head.equals("!")) return new DropNode(walkElement(t.child(0)));
if (head.equals("^")) return new LiteralNode(walkString(t.child(0)), true);
- if (head.equals("`")) return walkElement(t.child(0)).lifted();
+ if (head.equals("`")) return new BacktickNode(walkElement(t.child(0)));
if (head.equals("Quoted")) return stringifyChildren(t);
if (head.equals("Literal")) return new LiteralNode(walkString(t.child(0)));
if (head.equals("->")) return walkSeq(t.child(0)).follow(walkElement(t.child(1)));
try {
String newPrefix = t.size()<2 ? "" : (walkString(t.child(1))+".");
FileInputStream fis = new FileInputStream(file);
- Tree tr = new CharParser(MetaGrammar.newInstance()).parse(fis).expand1();
+ Tree tr = new CharParser(getMetaGrammar()).parse(fis).expand1();
return (GrammarNode)new GrammarAST(includes, newPrefix).walk(tr);
} catch (Exception e) {
throw new RuntimeException("while parsing " + file, e);
}
}
+ /** a node in the AST which is resolved into an Element */
private abstract class ElementNode {
- public boolean lifted = false;
- public Seq ownerSeq = null;
- public ElementNode lifted() { this.lifted = true; return this; }
+ public boolean isLifted() { return false; }
public boolean drop(Context cx) { return false; }
public Atom toAtom(Context cx) { throw new Error("can't convert a " + this.getClass().getName() + " to an atom: " + this); }
public abstract Element build(Context cx, NonTerminalNode cnt, boolean dropall);
for(int i=0; i<elements.length; i++) {
if (elements[i]==null)
throw new RuntimeException();
- elements[i].ownerSeq = this;
}
// FIXME: this whole mechanism is sketchy
if (check)
throw new RuntimeException("multiple non-dropped elements in sequence: " + Sequence.create("", els));
boolean[] lifts = new boolean[elements.length];
for(int i=0; i<elements.length; i++)
- lifts[i] = elements[i].lifted;
+ lifts[i] = elements[i].isLifted();
if (!multiNonDrop) {
if (idx == -1)
ret = tag==null
public Element build(Context cx, NonTerminalNode cnt, boolean dropall) { return _e.build(cx, cnt, dropall); }
}
+ private class BacktickNode extends ElementNodeWrapper {
+ public BacktickNode(ElementNode e) { super(e); }
+ public boolean isLifted() { return true; }
+ }
+
private class TildeNode extends ElementNodeWrapper {
public TildeNode(ElementNode e) { super(e); }
public Atom toAtom(Context cx) { return (Atom)((Topology<Character>)_e.toAtom(cx).complement()); }