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

36
LINES

< > BotCompany Repo | #1034677 // findFunctionDefsAtCurlyLevel_indexed [dev.]

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

Libraryless. Click here for Pure Java version (5994L/33K).

static LS findFunctionDefsAtCurlyLevel_indexed(int targetCurlyLevel, IContentsIndexedList2<S> tok) {
  new LS functions;
  new OrderedMultiIterator<HasIndex> multiIterator;
  
  for (keyword : findFunctionDefs_keywords())
    multiIterator.add(tok.indicesOf_treeSetOfHasIndex(keyword));
  multiIterator.add(tok.indicesOf_treeSetOfHasIndex("{"));
  multiIterator.add(tok.indicesOf_treeSetOfHasIndex("}"));
  multiIterator.add(tok.indicesOf_treeSetOfHasIndex("meta"));
  
  int curlyLevel = 0;
  new BitSet ignore;
  while (multiIterator.hasNext()) {
    HasIndex idx = multiIterator.next();
    int i = idx!;
    if (ignore.get(i)) continue;
    S t = tok.get(i);
  
    // Account for meta-for (don't change curly level)
    if (eq(t, "meta")) {
      if (eqSubList(tok, i+1, "", "-", "", "for")) {
        var r = tok_findFirstBlock(tok, i);
        ignore.set(r.start);
        ignore.set(r.end-1);
      }
    } else if (eq(t, "{"))
      ++curlyLevel;
    else if (eq(t, "}"))
      --curlyLevel;
    else // it's a function keyword
      if (curlyLevel == targetCurlyLevel)
        findFunctionDefs_step(tok, i, functions);
  }
  
  ret functions;
}

Author comment

Began life as a copy of #1034500

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034677
Snippet name: findFunctionDefsAtCurlyLevel_indexed [dev.]
Eternal ID of this version: #1034677/4
Text MD5: 5a94bd51a77f12d4737b77f1aa78e775
Transpilation MD5: 86c5aa2069670c4de6131b75ac813c68
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-01 19:53:52
Source code size: 1189 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 166 / 256
Version history: 3 change(s)
Referenced in: [show references]