// FIXME ugly ugly ugly scary dangerous
public static String prefix = "";
-
+
/** A grammar (a set of nonterminals) */
public static class GrammarNode extends HashMap<String,NonTerminalNode> implements NonTerminalSource {
public NonTerminalNode[] getNonTerminals() {
public static @bind.as("#import") GrammarNode poundimport(String fileName, String as) {
if (as==null) as = "";
+ else if ("".equals(as)) { }
+ else as = as +".";
+
System.err.println("#import " + fileName + " as " + as);
try {
- Tree t = new CharParser(MetaGrammar.make()).parse(new FileInputStream(fileName)).expand1();
+ Tree t = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream("tests/"+fileName)).expand1();
Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
String oldprefix = prefix;
prefix = as;
}
public Seq(ElementNode e) { this(new ElementNode[] { e }); }
public Seq(ElementNode[] elements) { this.elements = elements; }
- public Seq tag(String tag) { this.tag = tag; return this; }
+ public Seq tag(String tag) { this.tag = prefix+tag; return this; }
public Seq follow(ElementNode 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;
+ ret.tag = prefix+tag;
return ret;
}
public Seq and(Seq s) { and.add(s); s.lame = true; return this; }
}
public Sequence build0(Context cx, boolean lame, NonTerminalNode cnt) {
boolean dropAll = lame;
- if (tag!=null && "()".equals(tag)) dropAll = true;
+ if (tag!=null && tag.endsWith("()")) dropAll = true;
boolean[] drops = new boolean[elements.length];
Element[] els = new Element[elements.length];
for(int i=0; i<elements.length; i++) {
Sequence ret = null;
if (dropAll) ret = Sequence.drop(els, false);
else {
- ret = cx.rm.tryResolveTag(tag, cnt==null?null:cnt.name, els, drops);
+ Production prod = new Production(tag, (cnt==null?null:cnt.name), els, drops);
+ ret = cx.rm.tryResolveTag(prod);
if (ret == null) {
int idx = -1;
for(int i=0; i<els.length; i++)
{ return new Drop(e); }
public static @bind.as("^") ElementNode caret(final String s) {
+ final String thePrefix = prefix;
return new Drop(new Constant(CharRange.string(s)) {
- public String getOwnerTag() { return s; }
+ public String getOwnerTag() { return thePrefix+s; }
});
}