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

20
LINES

< > BotCompany Repo | #1017567 // tok_findEndOfStatement (works, but might have trouble with for + block)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2563L/16K).

1  
// Return value is index of semicolon/curly brace+1
2  
static int tok_findEndOfStatement(L<S> tok, int i) {
3  
  // Is it a block?
4  
  if (eq(get(tok, i), "{"))
5  
    ret findEndOfBlock(tok, i);
6  
    
7  
  // It's a regular statement. Special handling of "for" and "if"
8  
  int j = i;
9  
  bool special;
10  
  while (j < l(tok) && neq(tok.get(j), ";")) {
11  
    S t = get(tok, j);
12  
    if (eqOneOf(t, "for", "if")) set special;
13  
    if (eqOneOf(t, "{", "(")) {
14  
      j = findEndOfBracketPart(tok, j)+1;
15  
      if (special && eq(t, "{")) ret j-1;
16  
    } else
17  
      j += 2;
18  
  }
19  
  ret j+1;
20  
}

Author comment

Began life as a copy of #1002453

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: #1017567
Snippet name: tok_findEndOfStatement (works, but might have trouble with for + block)
Eternal ID of this version: #1017567/10
Text MD5: 8778470445b3af424c4e072959740ede
Transpilation MD5: 40357101b47659031bccf11aa2aaa087
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-18 18:55:32
Source code size: 577 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 448 / 506
Version history: 9 change(s)
Referenced in: [show references]