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];
public static @bind.as Seq psx(Seq s) { return s; }
public static @bind.as(":") ElementNode colon(String s, ElementNode e) { return new Label(s, e); }
public static @bind.as(")") void close(String foo) { throw new Error("not supported"); }
- public static @bind.as("()") ElementNode epsilon() { return new Constant(Union.epsilon); }
+ public static @bind.as("()") ElementNode epsilon() { return new Constant(epsilon); }
+
+ private static Union epsilon = new Union("()");
+ static { epsilon.add(Sequence.empty); }
public static class NonTerminalReferenceNode extends ElementNode {
public String nonTerminal;
}
public static class Literal extends Constant {
- public @bind Literal(@bind.arg String string) { super(CharRange.string(string)); }
+ public @bind Literal(@bind.arg String string) { super(CharAtom.string(string)); }
public boolean drop() { return true; }
}
edu.berkeley.sbp.util.Range.Set set = new edu.berkeley.sbp.util.Range.Set();
for(Range r : ranges)
set.add(r.first, r.last);
- return CharRange.set(set);
+ return CharAtom.set(set);
}
}
Sequence s = body.build(cx, u, false, null);
Union u2 = new Union();
u2.add(Sequence.singleton(new Element[] {
- CharRange.leftBrace,
+ CharAtom.leftBrace,
cx.get("ws"),
u,
cx.get("ws"),
- CharRange.rightBrace
+ CharAtom.rightBrace
}, 2));
return u2;
}
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 static @bind.as("^") ElementNode caret(final String s) {
final String thePrefix = prefix;
- return new Constant(CharRange.string(s)) {
+ return new Constant(CharAtom.string(s)) {
public String getOwnerTag() { return thePrefix+s; }
public boolean drop() { return true; }
};
public static @bind.as("~") ElementNode tilde(final ElementNode e) {
return new PostProcess(e) {
public Element postProcess(Element e) {
- return infer((Topology<Character>)Atom.toAtom(e).complement().minus(CharRange.braces));
+ return infer((Topology<Character>)Atom.toAtom(e).complement().minus(CharAtom.braces));
} }; }
public static @bind.as("Word") String word(String s) { return s; }
public static @bind.as("\r") String lf() { return "\r"; }
static Atom infer(Element e) { return infer((Topology<Character>)Atom.toAtom(e)); }
- static Atom infer(Topology<Character> t) { return new CharRange(new CharTopology(t)); }
+ static Atom infer(Topology<Character> t) { return new CharAtom(new CharTopology(t)); }
public static class Context {
public HashMap<String,Union> map = new HashMap<String,Union>();
}
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;