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

28
LINES

< > BotCompany Repo | #1006347 - tok_autoCloseBrackets

JavaX fragment (include)

static S tok_autoCloseBrackets(S s) {
  ret join(tok_autoCloseBrackets(javaTok(s)));
}

// modifies tok
static L<S> tok_autoCloseBrackets(L<S> tok) {
  bigloop: for (int i = 1; i < l(tok); i += 2) {
    if (eq(tok.get(i), ";")) {
      int j, level = 0;
      for (j = i-2; j >= 0; j -= 2) {
        S t = tok.get(j);
        if (eqOneOf(t, ";", "{")) break;
        if (eq(t, "}")) break; // TODO: skip over until other end of bracket
        else if (eq(t, ")")) --level;
        else if (eq(t, "(")) {
          if (eq(get(tok, j-2), "for")) break;
          if (eq(get(tok, j-4), "for")) break; // for ping
          ++level;
        }
      }
      while (level-- > 0) {
        tok.add(i++, ")");
        tok.add(i++, "");
      }
    }
  }
  ret tok;
}

Author comment

Began life as a copy of #1006346

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, sawdedvomwva, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1006347
Snippet name: tok_autoCloseBrackets
Eternal ID of this version: #1006347/3
Text MD5: ca804d3c60278e14b4856413479ac97e
Author: stefan
Category: javax / magic transformation
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-11 16:38:50
Source code size: 786 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 369 / 452
Version history: 2 change(s)
Referenced in: [show references]

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