From: adam Date: Wed, 14 Dec 2005 06:56:46 +0000 (-0500) Subject: checkpoint X-Git-Tag: tag_for_25-Mar~546 X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=656fdc1bf64b681ff0df822cf37867f2c3dbcbe7 checkpoint darcs-hash:20051214065646-5007d-40cb387951d4c3d3e3586ca962933ccedf28317a.gz --- diff --git a/src/edu/berkeley/sbp/misc/MetaGrammar.java b/src/edu/berkeley/sbp/misc/MetaGrammar.java index f210673..d6e8a88 100644 --- a/src/edu/berkeley/sbp/misc/MetaGrammar.java +++ b/src/edu/berkeley/sbp/misc/MetaGrammar.java @@ -27,7 +27,7 @@ public class MetaGrammar extends ReflectiveWalker { // MetaGrammar ////////////////////////////////////////////////////////////////////////////// - public Object _star_(Element r) { return new Rep(r, null, false, true).build(); } + public Object _star_(Element r) { return rep(r, null, false, true); } public Element epsilon(Object o, Object b) { return epsilon; } public Element _rightparen_(Object e) { return SELF; } @@ -67,7 +67,7 @@ public class MetaGrammar extends ReflectiveWalker { public Object _backslash__leftbrace_(String s) { return SELF; } public Object _leftbrace_(String s) { return SELF; } - public Object _plus_(final Element r) { return new Rep(r, null, false, false).build(); } + public Object _plus_(final Element r) { return rep(r, null, false, false); } public Object[] _slash_(Object[] o, Object sep) { if (o.length <= 1) return o; Object[] ret = new Object[o.length * 2 - 1]; @@ -78,10 +78,10 @@ public class MetaGrammar extends ReflectiveWalker { } return ret; } - public Object _plus__slash_(final Element r, Object s) { return new Rep(r, (Element)s, false, false).build(); } - public Object _star__slash_(final Element r, Object s) { return new Rep(r, (Element)s, false, true).build(); } - public Object _star__star_(final Element r) { return new Rep(r, null, true, true).build(); } - public Object _plus__plus_(final Element r) { return new Rep(r, null, true, false).build(); } + public Object _plus__slash_(final Element r, Object s) { return rep(r, (Element)s, false, false); } + public Object _star__slash_(final Element r, Object s) { return rep(r, (Element)s, false, true); } + public Object _star__star_(final Element r) { return rep(r, null, true, true); } + public Object _plus__plus_(final Element r) { return rep(r, null, true, false); } public Element _question_(final Element r) { return Repeat.maybe(r); } public MetaGrammar gram(Object o, MetaGrammar g, Object o2) { return g; } public MetaGrammar grammar(Object[] o) { return this; } @@ -146,17 +146,9 @@ public class MetaGrammar extends ReflectiveWalker { public PreBrace(Object[] o) { this.o = o; } } - public static class Rep { - private final Element e; - private final Element s; - private final boolean maximal; - private final boolean zero; - public Rep(Element e, Element s, boolean maximal, boolean zero) { this.e = e; this.s = s; this.zero = zero; this.maximal = maximal;} - public Element build() { - Element sep = s; - Element ret = zero ? Repeat.many0(e, sep) : Repeat.many1(e, sep); - return maximal ? Repeat.maximal(ret) : ret; - } + public Element rep(Element e, Element sep, boolean maximal, boolean zero) { + Element ret = zero ? Repeat.many0(e, sep) : Repeat.many1(e, sep); + return maximal ? Repeat.maximal(ret) : ret; } public static class PreSequence {