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

51
LINES

< > BotCompany Repo | #1022817 // Attractor, DefaultAttractor, MatchAttractor [Include]

JavaX fragment (include)

// not persistable
sclass Attractor implements IAttractor, Runnable {
  F1<S, Bool> tester;
  Runnable action;
  S input; // when matched

  *() {}
  *(F1<S, Bool> *tester, Runnable *action) {}
  *(Runnable *action) {}
  
  public bool matches(ExtS s) {
    ret matches(s!);
  }
  
  public bool matches(S s) {
    ret isTrue(callF(tester, s));
  }
  
  public void run {
    callF(action);
  }
  
  toString { ret standard_toString(this); }
  
  public bool matches_public(ExtS s) {
    input = s!;
    ret matches(s);
  }
  
  public bool matches_public(S s) {
    input = s;
    ret matches(s);
  }
}

sclass DefaultAttractor > Attractor {
  *() { this(null); }
  *(Runnable *action) { tester = f1_true(); }
}

sclass MatchAttractor > Attractor {
  S pattern;
  
  *() {}
  *(S *pattern) {}
  *(S *pattern, Runnable *action) {}
  
  public bool matches(S s) {
    ret matchX2(pattern, s);
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1022817
Snippet name: Attractor, DefaultAttractor, MatchAttractor [Include]
Eternal ID of this version: #1022817/19
Text MD5: eafa1a241370e432b1fea74a21dad493
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-27 15:30:28
Source code size: 947 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 321 / 963
Version history: 18 change(s)
Referenced in: [show references]