X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FMetaGrammarBindings.java;h=927cd6248b6aba71085ae5a27ccb9a0a57ed9ebf;hp=196394a9de1a07ec89a30af67328cb228c82a06b;hb=9d727bd14c659cdc6c34153b988e8d3fdb8067f5;hpb=24112db237318c030b4d4f457d90c34fd69d652b diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index 196394a..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,17 +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; } @@ -216,8 +211,8 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { ret.tag = prefix+tag; return ret; } - public Seq and(Seq s) { and.add(s); s.lame = true; return this; } - public Seq andnot(Seq s) { not.add(s); s.lame = true; return this; } + public Seq and(Seq s) { and.add(s); return this; } + public Seq andnot(Seq s) { not.add(s); return this; } public Seq separate(ElementNode sep) { ElementNode[] elements = new ElementNode[this.elements.length * 2 - 1]; 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(); @@ -506,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; } } + */ }