From: adam Date: Wed, 14 Dec 2005 07:03:06 +0000 (-0500) Subject: checkpoint X-Git-Tag: tag_for_25-Mar~543 X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=fc28000b13f531d55e0509a596ce5ad96c63bbf2 checkpoint darcs-hash:20051214070306-5007d-1310612845226909a0e13346a978fafe52eee3f9.gz --- diff --git a/src/edu/berkeley/sbp/misc/MetaGrammar.java b/src/edu/berkeley/sbp/misc/MetaGrammar.java index d160680..900ee3f 100644 --- a/src/edu/berkeley/sbp/misc/MetaGrammar.java +++ b/src/edu/berkeley/sbp/misc/MetaGrammar.java @@ -25,9 +25,30 @@ public class MetaGrammar extends ReflectiveWalker { public static Union epsilon = new Union("()"); static { epsilon.add(Sequence.empty); } + //////////////////////////////////////////////////////////////////////////////// + + private Union g; + private HashMap nt; + private int anon = 0; + private Element dws; + private String startSymbol; + + public MetaGrammar() { this("s"); } + public MetaGrammar(String s) { done(s); } + public Union done() { return done("s"); } + public Union done(String str) { + Union ret = g; + g = new Union(str); + startSymbol = str; + nt = new HashMap(); + dropAll = new HashSet(); + nt.put(str, g); + this.dws = Repeat.maximal(Repeat.many0(nonTerminal("w"))); + return ret; + } // MetaGrammar ////////////////////////////////////////////////////////////////////////////// - public PreSequence _equals__greater_(Object[] o, String s) { return new PreSequence(o, s); } + public PreSequence _equals__greater_(Object[] o, String s) { return new PreSequence(o, s); } public Object _star_(Element r) { return Repeat.many0(r); } public Element epsilon(Object o, Object b) { return epsilon; } public Element _rightparen_(Object e) { return SELF; } @@ -104,40 +125,16 @@ public class MetaGrammar extends ReflectiveWalker { return CharToken.set(ret); } + public PreSequence wrap(Object[] o) { return new PreSequence(o, ""); } + public PreSequence rewrite(Object[] o) { return new PreSequence(o, null); } - //////////////////////////////////////////////////////////////////////////////// - - private Union g; - private HashMap nt; - private int anon = 0; - private Element dws; - private String startSymbol; - - public MetaGrammar() { this("s"); } - public MetaGrammar(String s) { done(s); } - public Union done() { return done("s"); } - public Union done(String str) { - Union ret = g; - g = new Union(str); - startSymbol = str; - nt = new HashMap(); - dropAll = new HashSet(); - nt.put(str, g); - this.dws = Repeat.maximal(Repeat.many0(nonTerminal("w"))); - return ret; + public static class MyLift { + public final String s; + public MyLift(String s) { this.s = s; } } - - public PreSequence sequence(Object[] o) { return new PreSequence(o, null); } - - - public PreSequence wrap(Object[] o) { return new PreSequence(o, ""); } - public PreSequence mwrap(Object[] o) { return new PreSequence(o, ""); } - public PreSequence rewrite(Object[] o) { return new PreSequence(o, null); } - public PreSequence rewrite(Object[] o, Object o2) { - Object[] o3 = new Object[o.length + 1]; - System.arraycopy(o, 0, o3, 0, o.length); - o3[o3.length-1] = o2; - return rewrite(o3); + public static class MyDrop { + public final Object o; + public MyDrop(Object o) { this.o = o; } } public static class PreSequence { @@ -235,15 +232,6 @@ public class MetaGrammar extends ReflectiveWalker { os.close(); } - public static class MyLift { - public final String s; - public MyLift(String s) { this.s = s; } - } - public static class MyDrop { - public final Object o; - public MyDrop(Object o) { this.o = o; } - } - public static final Tree meta = diff --git a/tests/meta.g b/tests/meta.g index d05ee8f..7afdbc4 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -20,7 +20,6 @@ conjuncts ::= rewrite rewrite ::= sequence /ws => "rewrite" | sequence ^"=>" word /ws | sequence ^"=>" quoted /ws - | sequence "=>" "()" /ws => "wrap" ec ::= [~\-\]\\\~] | escaped