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

16
LINES

< > BotCompany Repo | #1025037 - tok_findBeginningOfStatement (probably doesn't always work)

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

Libraryless. Click here for Pure Java version (2089L/14K).

// Return value is C token
static int tok_findBeginningOfStatement(L<S> tok, int i) {
  i |= 1;
  int level = 0;
  
  while (i > 1) {
    S t = get(tok, i);
    if (eqOneOf(t, "{", "(")) { if (level-- < 0) break; }
    else if (eqOneOf(t, "}", ")")) level++;
    else if (level == 0 && eqGetOneOf(tok, i-2, "}", "{", ";"))
      break;
    i -= 2;
  }
  
  ret i;
}

Author comment

Began life as a copy of #1017567

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025037
Snippet name: tok_findBeginningOfStatement (probably doesn't always work)
Eternal ID of this version: #1025037/6
Text MD5: ad5770276ffb46b1d7ab7e5ea6164153
Transpilation MD5: 3c662bf6450f38ea6e834cf7ce28e1ca
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-01 20:56:41
Source code size: 380 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 23 / 49
Version history: 5 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1025037 & http://1025037.tinybrain.de