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

35
LINES

< > BotCompany Repo | #1027176 // gazelle_deepTransform_withTrail - call a transforming function on all inner parts of input

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

Transpiled version (3056L) is out of date.

// transformer can return null or input on no change
// will not call transformer on individual words
// returns null if no change
static WithTrail<S> lambdaMapLike gazelle_deepTransform_withTrail(IF1<S, WithTrail<S>> transformer, S input, O... _) {
  if (transformer == null) null;
  
  // call transformer on whole input, return if change
  WithTrail<S> transformed = transformer.get(input);
  if (transformed != null) ret transformed;

  // transformer didn't do anything, tokenize & go through parts
  O tokenizer = optPar tokenizer(_, f javaTokWithBrackets);
  LS tok = callTokenizer(tokenizer, input);
  
  new L trails;
  bool changes;
  
  for ping (int i = 1; i < l(tok); i += 2) {
    S t = tok.get(i);
    if (tok_isRoundOrCurlyBracketed(t)) {
      S unBracketed = tok_deRoundOrCurlyBracket(t);
      transformed = gazelle_deepTransform_withTrail(transformer, unBracketed, _);
      if (transformed != null) {
        if (!changes) tok = cloneList(tok); // in case a caching tokenizer was used
        
        // enclose in brackets & replace
        tok.set(i, startsWith(t, "(") ? roundOpt(transformed!) : curlyOpt(transformed!));
        trails.add(transformed.trail);
        set changes;
      }
    }
  }
  
  ret changes ? WithTrail(litmap(op := "gazelle_deepTransform_withTrail", +input, +trails), join(tok)) : null;
}

Author comment

Began life as a copy of #1027141

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027176
Snippet name: gazelle_deepTransform_withTrail - call a transforming function on all inner parts of input
Eternal ID of this version: #1027176/4
Text MD5: ecfd93d43d629a3270bf259f891457f5
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-24 12:14:01
Source code size: 1373 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 235 / 316
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)