// 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. while (j < l(tok) && neq(tok.get(j), ";")) if (eq(get(tok, j), "{")) j = findEndOfBlock(tok, j)+1; else j += 2; ret j+1; }