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).

1  
/* e.g. "he is called <a name>" =>
2  
3  
  he is called $1
4  
    & $1 is (a name)
5  
6  
*/
7  
8  
sclass AngleBracketVarsToConditions {
9  
  S mainLine;
10  
  new LS conditions;
11  
  
12  
  swappable S makeDollarVar() { ret main makeDollarVar(); }
13  
  swappable S categoryToNounPhrase(S s) { ret aOrAn_opt(s); }
14  
  swappable S makeCondition(S var, S type) {
15  
    ret var + " is " + roundOpt(categoryToNounPhrase(type));
16  
  }
17  
18  
  S go(S s) {
19  
    LS tok = javaTokWithAngleBrackets(s);
20  
    conditions.clear();
21  
    for (int i : indicesOfAngleBracketVars(tok)) {
22  
      S var = makeDollarVar();
23  
      conditions.add(makeCondition(var, deAngleBracket(tok.get(i))));
24  
      tok.set(i, var);
25  
    }
26  
    ret mainLine = join(tok);
27  
  }
28  
  
29  
  S joined() { ret joinWithAmpersand(itemPlusList(mainLine, conditions)); }
30  
}

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: 297 / 678
Version history: 10 change(s)
Referenced in: [show references]