X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Ftib%2FTib.java;h=39f6071d01a576fa6539f62240125d40b822f052;hp=200544aa5e4a53140c40a216e04195bee24d51ed;hb=0516ea34996c86664928ef948013b749876b87ec;hpb=f7dc68eeb40878c12463fc1ed2b4351b2a9fe261;ds=sidebyside diff --git a/src/edu/berkeley/sbp/tib/Tib.java b/src/edu/berkeley/sbp/tib/Tib.java index 200544a..39f6071 100644 --- a/src/edu/berkeley/sbp/tib/Tib.java +++ b/src/edu/berkeley/sbp/tib/Tib.java @@ -289,21 +289,30 @@ public class Tib implements Token.Stream { public static class Grammar extends MetaGrammar { private int anon = 0; + private final Element ws = Repeat.maximal0(nonTerminal("w")); + public Grammar() { dropAll.add(ws); } public Object walk(Tree tree) { String head = tree.head(); if (tree.numChildren()==0) return super.walk(tree); - if ("{".equals(head)) - return nonTerminal("braced"+(anon++), + if ("{".equals(head)) { + String s = "braced"+(anon++); + Union u = nonTerminal(s); + Union u2 = ((PreSequence)walk(tree, 0)).sparse(ws).buildUnion(); + u2.add(Sequence.singleton(new Element[] { u }, 0, null, null)); + return nonTerminal(s, new PreSequence[][] { new PreSequence[] { new PreSequence(new Element[] { CharToken.leftBrace, - ((PreSequence)walk(tree, 0)).buildUnion(), + ws, + u2, + ws, CharToken.rightBrace }) } }, false, false); + } return super.walk(tree); } }