// It's rough but should work if you don't make anonymous classes inside the statement or something... // Also won't work with "for" // Return value is index of semicolon/curly brace+1 static int findEndOfStatement(L tok, int i) { int j = i; // Is it a block? if (eq(get(tok, i), "{")) ret findEndOfBlock(tok, i)+1; // It's a regular statement. int n = l(tok); S t; while (j < n && !";".equals(t = tok.get(j))) if ("{".equals(t)) j = findEndOfBlock(tok, j)+1; else j += 2; ret j+1; }