try {
Tree t = new CharParser(MetaGrammar.newInstance()).parse(new FileInputStream("tests/"+fileName)).expand1();
- Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
+ TreeFunctor<Object,Object> red = (TreeFunctor<Object,Object>)t.head();
String oldprefix = prefix;
prefix = as;
GrammarNode gn = (GrammarNode)red.invoke(t);
this.name = prefix + name;
this.sequences = sequences;
this.rep = rep;
- this.sep = prefix + sep;
+ this.sep = sep==null?null:(prefix + sep);
}
public Element build(Context cx, NonTerminalNode cnt) { return cx.get(name); }
public void build(Context cx, Union u, NonTerminalNode cnt) {
Union urep = new Union();
urep.add(Sequence.empty);
- urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1));
+ if (sep != null)
+ urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1));
+ else
+ urep.add(Sequence.singleton(new Element[] { u }, 0));
for(int i=0; i<sequences.length; i++) {
Seq[] group = sequences[i];
this.e = e; this.sep = sep; this.zero = zero; this.many = many; this.max = max;}
public Element build(Context cx, NonTerminalNode cnt) {
return (!max)
- ? Sequence.repeat(e.build(cx, null), zero, many, sep==null ? null : sep.build(cx, null), cx.rm.repeatTag())
+ ? Sequence.repeat(e.build(cx, null), zero, many, sep==null ? null : sep.build(cx, null), cx.rm.repeatTag())
: sep==null
- ? Sequence.repeatMaximal(infer(e.build(cx, null)), zero, many, cx.rm.repeatTag())
- : Sequence.repeatMaximal(e.build(cx, null), zero, many, infer(sep.build(cx, null)), cx.rm.repeatTag());
+ ? Sequence.repeatMaximal(infer(e.build(cx, null)), zero, many, cx.rm.repeatTag())
+ : Sequence.repeatMaximal(e.build(cx, null), zero, many, infer(sep.build(cx, null)), cx.rm.repeatTag());
}
}
}
public Context(Tree t, Grammar.Bindings rm) {
this.rm = rm;
- Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
+ TreeFunctor<Object,Object> red = (TreeFunctor<Object,Object>)t.head();
this.grammar = (GrammarNode)red.invoke(t);
}
public Union peek(String name) { return map.get(name); }
map.put(name, ret);
NonTerminalNode nt = grammar.get(name);
if (nt==null) {
- //System.err.println("*** warning could not find " + name);
throw new Error("warning could not find " + name);
} else {
String old = cnt;