checkpoint
authoradam <adam@megacz.com>
Wed, 14 Dec 2005 07:24:43 +0000 (02:24 -0500)
committeradam <adam@megacz.com>
Wed, 14 Dec 2005 07:24:43 +0000 (02:24 -0500)
darcs-hash:20051214072443-5007d-825d2fe0896e97a8f1749ba12b77e1cca413c144.gz

src/edu/berkeley/sbp/misc/MetaGrammar.java
tests/meta.g

index 53aeff0..ff0ef4b 100644 (file)
@@ -30,7 +30,6 @@ public class MetaGrammar extends ReflectiveWalker {
     private Union g;
     private HashMap<String,Union> nt;
     private int anon = 0;
-    private Element dws;
     private String startSymbol;
 
     public MetaGrammar() { this("s"); }
@@ -43,12 +42,12 @@ public class MetaGrammar extends ReflectiveWalker {
         nt = new HashMap<String,Union>();
         dropAll = new HashSet<Element>();
         nt.put(str, g);
-        this.dws = Repeat.maximal(Repeat.many0(nonTerminal("w")));
         return ret;
     }
-    // MetaGrammar //////////////////////////////////////////////////////////////////////////////
 
 
+    // MetaGrammar //////////////////////////////////////////////////////////////////////////////
+
     public PreSequence _amp_(PreSequence p, Object[] o)        { return p.and(new PreSequence(o, null, true).buildSequence(null, true, false)); }
     public PreSequence _amp__tilde_(PreSequence p, Object[] o) { return p.not(new PreSequence(o, null, true).buildSequence(null, true, false)); }
     public PreSequence rewrite(Object[] o)                                            { return new PreSequence(o, null); }
@@ -84,10 +83,11 @@ public class MetaGrammar extends ReflectiveWalker {
         return n;
     }
 
-
     public Object   _backslash__leftbrace_(String s)      { return SELF; }
     public Object   _leftbrace_(String s)                 { return SELF; }
     public Object   _plus_(final Element r) { return Repeat.many1(r); }
+
+    public Object[] seq(Object[] o) { return o; }
     public Object[] _slash_(Object[] o, Object sep) {
         if (o.length <= 1) return o;
         Object[] ret = new Object[o.length * 2 - 1];
@@ -111,15 +111,15 @@ public class MetaGrammar extends ReflectiveWalker {
     public char    _backslash_r() { return '\r'; }
     public Object    literal(String s) { return new MyDrop(CharToken.string(s)); }
     public Range     _minus_(char a, char b) { return new Range(a, b); }
-    public Element   _leftbracket_       (Range[] rr) { return ranges(null, rr); }
-    public Element   _leftbracket__tilde_(Range[] rr) { return ranges("~",  rr); }
     public Range     range(char a)         { return new Range(a, a); }
-    public Element   ranges(Object o, Range[] rr) {
-        Range.Set ret = !"~".equals(o+"") ? new Range.Set() : new Range.Set(new Range(true, true));
+    public Element   _leftbracket_       (Range[] rr) { return ranges(true, rr); }
+    public Element   _leftbracket__tilde_(Range[] rr) { return ranges(false,  rr); }
+    public Element   ranges(boolean positive, Range[] rr) {
+        Range.Set ret = positive ? new Range.Set() : new Range.Set(new Range(true, true));
         if (rr != null)
             for(Range r : rr)
-                if (!"~".equals(o+"")) ret.add(r);
-                else                   ret.remove(r);
+                if (positive) ret.add(r);
+                else          ret.remove(r);
         return CharToken.set(ret);
     }
 
@@ -161,9 +161,11 @@ public class MetaGrammar extends ReflectiveWalker {
                 for(int i=0; i<o.length; i++) {
                     Object oi = o[i];
                     if (oi instanceof MyDrop)      { oi = ((MyDrop)oi).o; drops[j] = true; }
+
                     if (oi==SELF)                    o2[j] = u.new Subset("(("+u+"))", set);
                     else if (oi instanceof MyLift) { o2[j] = CharToken.string(tag = ((MyLift)oi).s); drops[j] = true; }
                     else                             o2[j] = (Element)oi;
+
                     if (MetaGrammar.dropAll.contains(o2[j])) drops[j] = true;
                     o2[j] = o2[j];
                     j++;
@@ -172,10 +174,7 @@ public class MetaGrammar extends ReflectiveWalker {
             Element[] expansion = o2;
             boolean keeper = this.keeper;
             Sequence ret = dropAll || lame || keeper ? Sequence.drop(expansion, and, not, lame) : null;
-            if (ret==null && tag!=null) {
-                for(int i=0; i<expansion.length; i++) expansion[i] = expansion[i];
-                ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
-            }
+            if (ret==null && tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
             if (ret==null) {
                 int idx = -1;
                 for(int i=0; i<expansion.length; i++) {
index e2713f9..85e9e25 100644 (file)
@@ -11,7 +11,7 @@ sequence    ::= es
               > es ws ^"/" e
 es          ::= e */ (w**)
 
-ss ::= es | es ^"/" e /ws
+ss ::= es => "seq" | es ^"/" e /ws
 
 conjuncts   ::=  rewrite
               |  rewrite ^"&"  e*/ws   /ws