scope tok_hashLocalIdentifiers // process #abc local identifier declaration // => scope + "abc" static LS tok_hashLocalIdentifiers(LS tok, S scope) { ret Obj(tok, scope)!; } srecord #Obj(LS tok, S scope) { bool verbose; selfType verbose(bool verbose) { this.verbose = verbose; this; } LS get() { tok = cloneList(tok); scope = unnull(scope); if (endsWithLetterOrDigit(scope)) scope += "_"; new HashSet names; // first pass (find # declarations) for (int k = 1; k < l(tok); k += 2) { S t = _get(tok, k+2); if (eqGet(tok, k, "#") && isIdentifier(t)) { if (verbose) print("Local name found: " + t); names.add(t); replaceTokens(tok, k, k+3, scope + t); } } // early exit if nothing to do if (empty(names)) ret tok; // second pass (references to scoped variables) for (int k = 1; k < l(tok); k += 2) { S t = _get(tok, k); if (isIdentifier(t) && names.contains(t)) tok.set(k, scope + t); } ret tok; } } end scope