X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FMetaGrammarBindings.java;h=927cd6248b6aba71085ae5a27ccb9a0a57ed9ebf;hp=cae45c0c75485ab94ba5e3fbf8bc634330200933;hb=9d727bd14c659cdc6c34153b988e8d3fdb8067f5;hpb=62be1c1ae2ac13086b508e34eeffdb7e536d5b61 diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index cae45c0..927cd62 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java @@ -195,7 +195,7 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { public Seq(ElementNode e) { this(new ElementNode[] { e }); } public Seq(ElementNode[] elements) { this.elements = elements; } public Atom toAtom(Context cx) { - if (elements.length != 1) throw new Error("FIXME"); + if (elements.length != 1) throw new Error("you attempted to use ->, **, ++, or a similar character-class operator on a [potentially] multicharacter production"); return elements[0].toAtom(cx); } public Seq tag(String tag) { this.tag = prefix+tag; return this; } @@ -225,9 +225,9 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { } public Sequence build(Context cx, Union u, NonTerminalNode cnt) { Sequence ret = build0(cx, cnt); - for(Seq s : and) { Sequence dork = s.build(cx, u, cnt); ret = ret.and(dork); } - for(Seq s : not) { Sequence dork = s.build(cx, u, cnt); ret = ret.andnot(dork); } - u.add(ret); + for(Seq s : and) { Sequence dork = s.build(cx, null, cnt); ret = ret.and(dork); } + for(Seq s : not) { Sequence dork = s.build(cx, null, cnt); ret = ret.andnot(dork); } + if (u!=null) u.add(ret); return ret; } public Sequence build0(Context cx, NonTerminalNode cnt) { @@ -321,6 +321,11 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { } } + public static @bind.as("\\{") ElementNode leftBrace() { + return new Drop(new CharClass(new Range[] { new Range(CharAtom.left, CharAtom.left) })); } + public static @bind.as("\\}") ElementNode rightBrace() { + return new Drop(new CharClass(new Range[] { new Range(CharAtom.right, CharAtom.right) })); } + public static @bind.as("{") class XTree extends ElementNode { public @bind.arg Seq body; public Element build(Context cx, NonTerminalNode cnt) { @@ -389,15 +394,19 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { public static @bind.as("~") ElementNode tilde(final ElementNode e) { return new ElementNodeWrapper(e) { public Atom toAtom(Context cx) { - return infer((Topology)e.toAtom(cx).complement().minus(CharAtom.braces)); + return infer((Topology)e.toAtom(cx).complement()/*.minus(CharAtom.braces)*/); } public Element build(Context cx, NonTerminalNode cnt) { - return infer((Topology)e.toAtom(cx).complement().minus(CharAtom.braces)); + return infer((Topology)e.toAtom(cx).complement()/*.minus(CharAtom.braces)*/); } }; } public static @bind.as("Word") String word(String s) { return s; } public static @bind.as("Quoted") String quoted(String s) { return s; } - public static @bind.as("escaped") String c(char c) { return c+""; } + public static @bind.as("escaped") String c(char c) { + if (c=='{') return CharAtom.left+""; + if (c=='}') return CharAtom.right+""; + return c+""; + } public static @bind.as("EmptyString") String emptystring() { return ""; } public static @bind.as("\n") String retur() { return "\n"; } public static @bind.as("\r") String lf() { return "\r"; }