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

44
LINES

< > BotCompany Repo | #1031426 // tok_hashLocalIdentifiers

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

Transpiled version (2957L) is out of date.

1  
scope tok_hashLocalIdentifiers
2  
3  
// process #abc local identifier declaration
4  
// => scope + "abc"
5  
static LS tok_hashLocalIdentifiers(LS tok, S scope) {
6  
  ret Obj(tok, scope)!;
7  
}
8  
9  
srecord #Obj(LS tok, S scope) {
10  
  bool verbose;
11  
  selfType verbose(bool verbose)  { this.verbose = verbose; this; }
12  
  
13  
  LS get() {
14  
    tok = cloneList(tok);
15  
    scope = unnull(scope);
16  
    if (endsWithLetterOrDigit(scope)) scope += "_";
17  
    new HashSet<S> names;
18  
  
19  
    // first pass (find # declarations)
20  
    for (int k = 1; k < l(tok); k += 2) {
21  
      S t = _get(tok, k+2);
22  
      if (eqGet(tok, k, "#") && isIdentifier(t)) {
23  
        if (verbose)
24  
          print("Local name found: " + t);
25  
        names.add(t);
26  
        replaceTokens(tok, k, k+3, scope + t);
27  
      }
28  
    }
29  
    
30  
    // early exit if nothing to do
31  
    if (empty(names)) ret tok;
32  
      
33  
    // second pass (references to scoped variables)
34  
    for (int k = 1; k < l(tok); k += 2) {
35  
      S t = _get(tok, k);
36  
      if (isIdentifier(t) && names.contains(t))
37  
        tok.set(k, scope + t);
38  
    }
39  
    
40  
    ret tok;
41  
  }
42  
}
43  
44  
end scope

Author comment

Began life as a copy of #1015648

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031426
Snippet name: tok_hashLocalIdentifiers
Eternal ID of this version: #1031426/9
Text MD5: 4ef05b6126c89f378acdc29e5ef8a05b
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-12 07:52:55
Source code size: 1112 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 255 / 433
Version history: 8 change(s)
Referenced in: [show references]