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

30
LINES

< > BotCompany Repo | #1026385 // AngleBracketVarsToConditions

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

Libraryless. Click here for Pure Java version (2887L/18K).

/* e.g. "he is called <a name>" =>

  he is called $1
    & $1 is (a name)

*/

sclass AngleBracketVarsToConditions {
  S mainLine;
  new LS conditions;
  
  swappable S makeDollarVar() { ret main makeDollarVar(); }
  swappable S categoryToNounPhrase(S s) { ret aOrAn_opt(s); }
  swappable S makeCondition(S var, S type) {
    ret var + " is " + roundOpt(categoryToNounPhrase(type));
  }

  S go(S s) {
    LS tok = javaTokWithAngleBrackets(s);
    conditions.clear();
    for (int i : indicesOfAngleBracketVars(tok)) {
      S var = makeDollarVar();
      conditions.add(makeCondition(var, deAngleBracket(tok.get(i))));
      tok.set(i, var);
    }
    ret mainLine = join(tok);
  }
  
  S joined() { ret joinWithAmpersand(itemPlusList(mainLine, conditions)); }
}

Author comment

Began life as a copy of #1025963

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: #1026385
Snippet name: AngleBracketVarsToConditions
Eternal ID of this version: #1026385/11
Text MD5: f6471e254575c40953cf814146b122ff
Transpilation MD5: 6472eaafdb2966890d095a98b1ec5d74
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-03 00:26:51
Source code size: 793 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 298 / 678
Version history: 10 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)