X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FMetaGrammarBindings.java;h=23722739bff0d35bfa0e92c0b51515988c2b51fe;hb=bb5fe6d85085a3c3fb05072d789cc6edeb7992bc;hp=50fd0b33f7d6f1ba16a091dce0d8a922862cc6ea;hpb=8129e3bcdf7df528a636daf66e0b35b1dceb153f;p=sbp.git diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index 50fd0b3..2372273 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java @@ -47,13 +47,52 @@ public class MetaGrammarBindings { } public static class NonTerminal extends Un { + public boolean rep; public String name = null; - public @bind NonTerminal(@bind.arg String name, - @bind.arg Seq[][] sequences) { + public String sep = null; + public @bind NonTerminal(@bind.arg String name, @bind.arg Seq[][] sequences) { this(name, sequences, false); } + public NonTerminal(String name, Seq[][] sequences, boolean rep) { this(name, sequences, rep, null); } + public NonTerminal(String name, Seq[][] sequences, boolean rep, String sep) { this.name = name; this.sequences = sequences; + this.rep = rep; + this.sep = sep; } public Element build(MetaGrammar.Context cx) { return cx.get(name); } + public void build(MetaGrammar.Context cx, Union u) { + if (!rep) { super.build(cx, u); return; } + HashSet bad2 = new HashSet(); + + Union urep = new Union(); + urep.add(Sequence.empty); + urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1)); + + for(int i=0; i") Seq arrow(Seq s, El e) { return s.follow(e); } @@ -181,7 +223,7 @@ public class MetaGrammarBindings { public static @bind.as("/") Seq slash(Seq s, El e) { return s.separate(e); } public static Seq seq(El[] elements) { return new Seq(elements); } - public static @bind.as("PS") Seq seq2(El[] elements) { return new Seq(elements); } + public static @bind.as("Elements") Seq seq2(El[] elements) { return new Seq(elements); } public static @bind.as Seq psx(Seq s) { return s; } public static @bind.as(":") El colon(String s, El e) { return new Label(s, e); } public static @bind.as(")") void close(String foo) { throw new Error("not supported"); } @@ -211,7 +253,17 @@ public class MetaGrammarBindings { public static @bind.as("{") class XTree extends El { public @bind.arg Seq body; public Element build(MetaGrammar.Context cx) { - throw new Error(); + Union u = new Union(); + Sequence s = body.build(cx, u, false); + Union u2 = new Union(); + u2.add(Sequence.singleton(new Element[] { + CharRange.leftBrace, + cx.get("ws"), + u, + cx.get("ws"), + CharRange.rightBrace + }, 2)); + return u2; } } @@ -269,12 +321,12 @@ public class MetaGrammarBindings { //public static @bind.as("(") El subexpression(Seq[][] rhs) { return new NonTerminal(rhs); } - 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("\"\"") String emptystring() { return ""; } - public static @bind.as("\n") String retur() { return "\n"; } - public static @bind.as("\r") String lf() { return "\r"; } + 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("EmptyString") String emptystring() { return ""; } + public static @bind.as("\n") String retur() { return "\n"; } + public static @bind.as("\r") String lf() { return "\r"; } static Atom infer(Element e) { return infer((Topology)Atom.toAtom(e)); } static Atom infer(Topology t) { return new CharRange(new CharTopology(t)); }