public static Object repeatTag = null;
- /** an atom which tracks the possible tokenset of some element, provided that element can only match single-token sequences */
- public static class Infer<T extends Input> extends Atom<T> {
- private final Element e;
- public Infer(Element e) { this.e = e; }
- public Topology<T> top() { return (Topology<T>)toAtom(e); }
- public String toString() { return e.toString(); }
- }
-
- /** an atom which tracks the inverse of some other atom */
- public static class Invert<T extends Input> extends Atom<T> {
- private final Atom<T> a;
- public Invert(Atom<T> a) { this.a = a; }
- public Topology<T> top() { return a.complement(); }
- public String toString() { return "~"+a; }
- }
-
- public static class Hack<T extends Input> extends Atom<T> {
- private final Atom<T> a;
- static final Topology leftright = CharRange.rightBrace.union(CharRange.leftBrace);
- public Hack(Atom<T> a) { this.a = a; }
- public Topology<T> top() { return a.minus(leftright); }
- public String toString() { return a.toString(); }
- }
-
public static Union make() throws Exception { return make(MetaGrammarTree.meta, "s"); }
public static Union make(Tree<String> tree, String nt) throws Exception {
Meta.MetaGrammarFile mgf = new MetaGrammar.Meta.MetaGrammarFile(tree);
////////////////////////////////////////////////////////////////////////////////
- private static boolean strings;
- private static Element set(Range.Set r) { if (strings) throw new Error(); return CharRange.set(r); }
- private static Element string(String s) { return strings ? StringInput.string(s) : CharRange.string(s); }
+ private static Element set(Range.Set r) { return CharRange.set(r); }
+ private static Element string(String s) { return CharRange.string(s); }
+ private static Atom infer(Element e) { return infer((Topology<Character>)Atom.toAtom(e)); }
+ private static Atom infer(Topology<Character> t) { return new CharRange(new CharTopology(t)); }
private MetaGrammar() { }
if (idx != -1) ret = Sequence.singleton(els, idx);
else ret = Sequence.drop(els, false);
}
- if (this.followedBy != null) ret.follow = new Hack(new Infer(this.followedBy.build(bc)));
+ if (this.followedBy != null)
+ ret.follow = infer(this.followedBy.build(bc));
return ret;
}
private MetaConjunct(Tree<String> t) {
public boolean maximal, zero, many;
public Element build(BuildContext bc) {
return !maximal
- ? new Repeat(element.build(bc), zero, many, separator==null?null:separator.build(bc), null)
- : separator==null
- ? new Repeat.Maximal(element.build(bc), zero, many, null)
- : new Repeat.Maximal(element.build(bc), zero, many, separator.build(bc), null);
+ ? (separator==null
+ ? Sequence.repeat(element.build(bc), zero, many, null, null)
+ : Sequence.repeat(element.build(bc), zero, many, separator.build(bc), null))
+ : (separator==null
+ ? Sequence.repeatMaximal(infer(element.build(bc)), zero, many, null)
+ : Sequence.repeatMaximal(element.build(bc), zero, many, infer(separator.build(bc)), null));
}
public MetaRepeat(MetaClause element, boolean maximal, MetaClause separator, boolean zero, boolean many) {
this.separator = separator;
public MetaClause element;
public MetaInvert(Tree<String> t, MetaConjunct c) { this.element = make(t, c); }
public String toString() { return "~"+element; }
- public Element build(BuildContext bc) { return new Hack(new Invert(new Infer(element.build(bc)))); }
+ public Element build(BuildContext bc) { return infer((Topology<Character>)Atom.toAtom(element.build(bc)).complement()); }
}
}
p.flush();
os.close();
}
+
}