X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FMetaGrammarBindings.java;h=927cd6248b6aba71085ae5a27ccb9a0a57ed9ebf;hp=37902272e20832be0ab4e47d9b6470f7cdf079d5;hb=9d727bd14c659cdc6c34153b988e8d3fdb8067f5;hpb=6af13e9dda011e2416e4f0ee3cc347e8e7fcafd7 diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index 3790227..927cd62 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java @@ -1,3 +1,5 @@ +// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp.meta; import edu.berkeley.sbp.util.*; import edu.berkeley.sbp.*; @@ -68,7 +70,7 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { Atom ret = null; for(Seq[] ss : sequences) for(Seq s : ss) - ret = ret==null ? s.toAtom(cx) : infer(ret.union(s.toAtom(cx))); + ret = ret==null ? s.toAtom(cx) : (Atom)ret.union(s.toAtom(cx)); return ret; } public void build(Context cx, Union u, NonTerminalNode cnt) { @@ -77,14 +79,13 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { Seq[] group = sequences[i]; Union u2 = new Union(null, false); if (sequences.length==1) u2 = u; - for(int j=0; j bad2 = new HashSet(); Union urep = new Union(null, false); - urep.add(Sequence.empty); + urep.add(Sequence.create()); if (sep != null) - urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1)); + urep.add(Sequence.create(new Element[] { cx.get(sep), u }, 1)); else - urep.add(Sequence.singleton(new Element[] { u }, 0)); + urep.add(Sequence.create(new Element[] { u }, 0)); for(int i=0; i, **, ++, 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; } @@ -223,14 +225,12 @@ 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.not(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) { - boolean dropAll = false; - if (tag!=null && tag.endsWith("()")) dropAll = true; boolean[] drops = new boolean[elements.length]; Element[] els = new Element[elements.length]; for(int i=0; i)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"; } //static Atom infer(Element e) { return infer((Topology)Atom.toAtom(e)); } - static Atom infer(Topology t) { return new CharAtom(new CharTopology(t)); } + static Atom infer(Object t) { return (Atom)t; } public static class Context { public HashMap map = new HashMap(); @@ -497,10 +503,12 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { public String getLabel() { return label; } } + /* static class Invert extends Atom { private final Atom a; public Invert(Atom a) { this.a = a; } public Topology top() { return a.complement(); } public String toString() { return "~"+a; } } + */ }