Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1002453 // findEndOfStatement (broken version, use tok_findEndOfStatement instead)

JavaX fragment (include)

// 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<S> 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;
}

Author comment

Began life as a copy of #1001046

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002453
Snippet name: findEndOfStatement (broken version, use tok_findEndOfStatement instead)
Eternal ID of this version: #1002453/6
Text MD5: 9465e7f4a2388a547dcb275e8d24ea5b
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-04 00:50:17
Source code size: 553 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 763 / 1721
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1013213 - tok_findEndOfForExpression
#1017567 - tok_findEndOfStatement (works, but might have trouble with for + block)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)