X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Ftib%2FTib.java;h=4805d1e8f543cbf16fcfef674552e391f72e3788;hb=ac3843911c47a601ffd679d2e075b519d3a18d6a;hp=f15bfbb324023a1deaa08ce2d900fa036923e222;hpb=aa467fd9d82ee4ab751a6ced1e4f48864f494e90;p=sbp.git diff --git a/src/edu/berkeley/sbp/tib/Tib.java b/src/edu/berkeley/sbp/tib/Tib.java index f15bfbb..4805d1e 100644 --- a/src/edu/berkeley/sbp/tib/Tib.java +++ b/src/edu/berkeley/sbp/tib/Tib.java @@ -42,7 +42,7 @@ public class Tib implements Input { int _row = 1; int _col = 0; - public Input.Location getLocation() { return new CartesianLocation(_row, _col); } + public Input.Location getLocation() { return new Input.Location.Cartesian(_col, _row); } private BufferedReader br; char left = CharRange.left; @@ -53,8 +53,8 @@ public class Tib implements Input { boolean indenting = true; int indentation = 0; private ArrayList istack = new ArrayList(); - public Character next(int numstates, int resets, int waits) throws IOException { - Character ret = nextc(numstates, resets); + public Character next() throws IOException { + Character ret = nextc(); if (ret==null) return null; else if (ret==left) System.out.print("\033[31m{\033[0m"); else if (ret==right) System.out.print("\033[31m}\033[0m"); @@ -63,7 +63,7 @@ public class Tib implements Input { } Character waitingBrace = null; - public Character nextc(int numstates, int resets) throws IOException { + public Character nextc() throws IOException { char c; if (waitingBrace != null) { Character ret = waitingBrace; @@ -83,12 +83,12 @@ public class Tib implements Input { return null; } c = (char)i; + if (c=='\n') { _row++; _col=0; } + else _col++; } - if (c=='\n') { _row++; _col=0; } - else _col++; if (indenting) { if (c==' ') { indentation++; return done(c); } - if (c=='\n') { indentation = 0; if (blank) return nextc(numstates, resets); blank = true; waiting = true; waitingChar='\n'; return '\n'; } + if (c=='\n') { indentation = 0; if (blank) return nextc(); blank = true; waiting = true; waitingChar='\n'; return '\n'; } int last = istack.size()==0 ? -1 : istack.get(istack.size()-1); if (indentation==last) { if (blank) { @@ -135,10 +135,10 @@ public class Tib implements Input { // Grammar ////////////////////////////////////////////////////////////////////////////// - public static class Grammar extends MetaGrammar { + public static class Grammar extends ReflectiveGrammar { private int anon = 0; - private final Element ws = Repeat.maximal0(getNonTerminal("w")); - public Grammar() { dropAll.add(ws); } + private final Element ws = Sequence.maximal0(getNonTerminal("w")); + public Grammar(Class c) { super(c); dropAll.add(ws); } public Object walk(Tree tree) { String head = tree.head(); if (tree.numChildren()==0) return super.walk(tree); @@ -146,14 +146,14 @@ public class Tib implements Input { Union u = new Union("???"); Union u2 = ((PreSequence)walk(tree, 0)).sparse(ws).buildUnion(); u2.add(Sequence.singleton(new Element[] { u }, 0)); - return anonymousNonTerminal(new PreSequence[][] { - new PreSequence[] { - new PreSequence(new Element[] { CharRange.leftBrace, - ws, - u2, - ws, - CharRange.rightBrace - }) + return anonymousNonTerminal(new Sequence[][] { + new Sequence[] { + Sequence.singleton(new Element[] { CharRange.leftBrace, + ws, + u2, + ws, + CharRange.rightBrace + }, 2) } }); }