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

116
LINES

< > TinyBrain | #1008907 - CtxExpr etc.

JavaX fragment (include)

abstract sclass CtxExpr {
  // assumes that ctxContext() is set
  
  abstract bool get();
  abstract S str();
}

abstract sclass CtxGeneral extends CtxExpr {
  bool get() { ret eqic(str(), "true"); }
}

abstract sclass CtxBool extends CtxExpr {
  S str() { ret get() ? "true" : "false"; }
}

CtxGeneral > CtxConst {
  S value;
  
  *() {}
  *(S *value) {}
  
  // assume it's a regexp when queried with get()
  // and a string constant when queried with str()
  // (maybe we don't need this trick anymore)
  S str() { ret value; }
  bool get() { ret ctxEvalPattern(value); }
}

CtxGeneral > CtxVar {
  S var;
  
  *() {}
  *(S *var) {}
  
  S str() { ret ctxGetVar(var); }
}

CtxBool > CtxNeg {
  CtxExpr e;
  
  *() {}
  *(CtxExpr *e) {}
  
  bool get() { ret !e.get(); }
}

CtxBool > CtxAnd {  
  CtxExpr a, b;
  
  *() {}
  *(CtxExpr *a, CtxExpr *b) {}

  bool get() { ret a.get() && b.get(); }
}

CtxBool > CtxOr {  
  CtxExpr a, b;
  
  *() {}
  *(CtxExpr *a, CtxExpr *b) {}
  
  bool get() { ret a.get() || b.get(); }
}

CtxBool > CtxRegexp {
  S pattern;
  
  *() {}
  *(S *pattern) {}
  
  bool get() { ret ctxEvalPattern(pattern); }
}

CtxBool > CtxComp {
  CtxExpr a, b;
  
  *() {}
  *(CtxExpr *a, CtxExpr *b) {}
  
  bool get() { ret eq(a.str(), b.str()); }
}

CtxBool > CtxUneq {
  CtxExpr a, b;
  
  *() {}
  *(CtxExpr *a, CtxExpr *b) {}

  bool get() { ret neq(a.str(), b.str()); }
}

CtxBool > CtxMatch {
  CtxExpr var;
  S pattern;
  
  *() {}
  *(CtxExpr *var, S *pattern) {}
  
  bool get() { ret ctxEvalPattern(pattern, var.str()); }
}

CtxGeneral > CtxFCall {
  S fname;
  new L<CtxExpr> args;
  
  *() {}
  *(S *fname) {}
  
  void add(CtxExpr arg) {
    args.add(arg);
  }
  
  S str() {
    ret ctxCallFunction(fname, map(func(CtxExpr e) { e.str() }, args));
  }
}

download  show line numbers  debug dex   

Travelled to 3 computer(s): cfunsshuasjs, onxytkatvevr, tvejysmllsmz

No comments. add comment

Snippet ID: #1008907
Snippet name: CtxExpr etc.
Eternal ID of this version: #1008907/20
Text MD5: f683734af02b5339100b63abde95a49c
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-01 19:03:41
Source code size: 1903 bytes / 116 lines
Pitched / IR pitched: No / No
Views / Downloads: 50 / 373
Version history: 19 change(s)
Referenced in: [show]