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

49
LINES

< > BotCompany Repo | #1027559 // tok_expandIfQuoted

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

Libraryless. Click here for Pure Java version (3412L/21K).

sS tok_expandIfQuoted(S s) { ret applyTranspilationFunction tok_expandIfQuoted(s); }

svoid tok_expandIfQuoted(LS tok) {
  jreplace(tok, "if <quoted> || <quoted>",
    "if (matchOneOf(s, m, $2, $5))");
    
  // "bla * bla | blubb * blubb"
  jreplace_dyn(tok, "if <quoted>", func(L<S> tok, int cIdx) -> S {
    S s = unquote(tok.get(cIdx+2));
    //print("multimatch: " + quote(s));
    new L<S> l;
    for (S pat : splitAtJavaToken(s, "|")) {
      //print("multimatch part: " + quote(pat));
      if (pat.contains("..."))
        l.add("matchX(" + quote(trim(pat)) + ", s, m)");
      else if (javaTok(pat).contains("*"))
        l.add("match(" + quote(trim(pat)) + ", s, m)");
      else
        l.add("match(" + quote(trim(pat)) + ", s)");
    }
    ret "if (" + join(" || ", l) + ")";
  }, tokcondition {
    ret javaTokC(unquote(tok.get(i+3))).contains("|");
  });
  
  tok_transpileIfQuoted_dollarVars(tok);
  
  // "...bla..."
  jreplace(tok, "if <quoted>", "if (find3plusRestsX($2, s, m))",
    tokcondition {
      ret startsAndEndsWith(unquote(tok.get(i+3)), "...");
    });
    
  // "bla..."
  jreplace(tok, "if <quoted>", "if (matchStartX($2, s, m))",
    tokcondition {
      ret unquote(tok.get(i+3)).endsWith("...");
    });
    
  // "bla"
  jreplace(tok, "if <quoted>", "if (match($2, s))",
    tokcondition {
      ret !javaTokC(unquote(tok.get(i+3))).contains("*");
    });
    
  // "bla * bla"
  jreplace(tok, "if <quoted>", "if (match($2, s, m))");
  jreplace(tok, "if match <quoted>", "if (match($3, s, m))");
}

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: #1027559
Snippet name: tok_expandIfQuoted
Eternal ID of this version: #1027559/4
Text MD5: dd35c127d376521d583f314f72370401
Transpilation MD5: a9b46301928d3515cf43304793707db9
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-29 20:11:45
Source code size: 1584 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 184 / 282
Version history: 3 change(s)
Referenced in: [show references]