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

43
LINES

< > BotCompany Repo | #1014202 // parseDoubleArrowTreeCI

JavaX fragment (include)

1  
static S parseDoubleArrowTreeCI_defaultKey = "<default>";
2  
3  
static Map<S, O> parseDoubleArrowTreeCI(S text) {
4  
  L<S> lines = withoutEmpties(rtrimAll(lines(text)));
5  
  if (empty(lines)) null;
6  
7  
  new L<Map<S, O>> nodes;
8  
  new L<Int> indents; // indent of children
9  
  
10  
  Map<S, O> tree = ciMap();
11  
  nodes.add(tree);
12  
  indents.add(countIndent(first(lines)));
13  
  
14  
  for i over lines: {
15  
    S s = lines.get(i);
16  
    int indent = countIndent(s);
17  
    
18  
    while (indent < last(indents)) {
19  
      removeLast(nodes);
20  
      removeLast(indents);
21  
    }
22  
    
23  
    L<S> x = splitAtDoubleArrow(s);
24  
    if (l(x) == 2) { // leaf (or tree with default)
25  
      S next = get(lines, i+1);
26  
      if (next != null && countIndent(next) > indent) { // tree with default
27  
        Map<S, O> newTree = ciMap();
28  
        last(nodes).put(first(x), newTree);
29  
        nodes.add(newTree);
30  
        indents.add(indent+1);
31  
        newTree.put(parseDoubleArrowTreeCI_defaultKey, second(x));
32  
      } else // leaf
33  
        last(nodes).put(first(x), second(x));
34  
    } else {
35  
      Map<S, O> newTree = ciMap();
36  
      last(nodes).put(trim(s), newTree);
37  
      nodes.add(newTree);
38  
      indents.add(indent+1);
39  
    }
40  
  }
41  
  
42  
  ret tree;
43  
}

Author comment

Began life as a copy of #1014190

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014202
Snippet name: parseDoubleArrowTreeCI
Eternal ID of this version: #1014202/10
Text MD5: 63720218c82f3b2dce5711c3fa3c29e0
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-16 00:16:03
Source code size: 1222 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 294 / 325
Version history: 9 change(s)
Referenced in: [show references]