X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Ftib%2FTib.java;h=29181a012e9c7acdc86f6cf7d2c240ee4332b0c1;hp=8ee70ca237ec5b9148f2ae3e29f82e0f2ba9bbc4;hb=9ded11559a1b6f817e99355b1c9e2c88042e91d4;hpb=f33c05adc5aa3dd324c5352cdbd6f4b55359acad diff --git a/src/edu/berkeley/sbp/tib/Tib.java b/src/edu/berkeley/sbp/tib/Tib.java index 8ee70ca..29181a0 100644 --- a/src/edu/berkeley/sbp/tib/Tib.java +++ b/src/edu/berkeley/sbp/tib/Tib.java @@ -54,6 +54,8 @@ public class Tib implements Token.Stream { } if (pos >= cur.size()) { pos = cur.iip+1; + _row = cur.endrow; + _col = cur.endcol; cur = cur.parent; if (cur==null) return null; return CharToken.right; @@ -85,7 +87,8 @@ public class Tib implements Token.Stream { boolean blankLine = false; Block top = new Block.Root(); for(String s = br.readLine(); s != null; s = br.readLine()) { - col = 0; + row++; + col=0; while (s.length() > 0 && s.charAt(0) == ' ' && (!(top instanceof Block.Literal) || col < top.col)) { col++; s = s.substring(1); } @@ -94,6 +97,8 @@ public class Tib implements Token.Stream { while (col < top.col) { if (s.startsWith("{}") && top instanceof Block.Literal && ((Block.Literal)top).braceCol == col) break; blankLine = false; + top.endrow = row; + top.endcol = col; top = top.closeIndent(); } if (s.startsWith("{}")) { @@ -107,16 +112,16 @@ public class Tib implements Token.Stream { } while (s.length() > 0 && s.charAt(s.length()-1)==' ') { s = s.substring(0, s.length()-1); } if (col > top.col) top = new Block.Indent(top, row, col); - else if (blankLine) { top = top.closeIndent(); top = new Block.Indent(top, row, col); } + else if (blankLine) { top.endrow=row; top.endcol=col; top = top.closeIndent(); top = new Block.Indent(top, row, col); } blankLine = false; for(int i=0; i { Block parent; public final int row; public final int col; + public int endrow; + public int endcol; public final int iip; private final Vector children = new Vector(); private String pending = ""; @@ -262,7 +269,8 @@ public class Tib implements Token.Stream { // Testing ////////////////////////////////////////////////////////////////////////////// - public static void main(String[] s) throws Exception { System.out.println(parse(new BufferedReader(new InputStreamReader(System.in))).toString(-1)); } + public static void main(String[] s) throws Exception { + System.out.println(parse(new BufferedReader(new InputStreamReader(System.in))).toString(-1)); } // Utilities //////////////////////////////////////////////////////////////////////////////