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

116
LINES

< > BotCompany Repo | #1008907 // CtxExpr etc.

JavaX fragment (include)

1  
abstract sclass CtxExpr {
2  
  // assumes that ctxContext() is set
3  
  
4  
  abstract bool get();
5  
  abstract S str();
6  
}
7  
8  
abstract sclass CtxGeneral extends CtxExpr {
9  
  bool get() { ret eqic(str(), "true"); }
10  
}
11  
12  
abstract sclass CtxBool extends CtxExpr {
13  
  S str() { ret get() ? "true" : "false"; }
14  
}
15  
16  
sclass CtxConst extends CtxGeneral {
17  
  S value;
18  
  
19  
  *() {}
20  
  *(S *value) {}
21  
  
22  
  // assume it's a regexp when queried with get()
23  
  // and a string constant when queried with str()
24  
  // (maybe we don't need this trick anymore)
25  
  S str() { ret value; }
26  
  bool get() { ret ctxEvalPattern(value); }
27  
}
28  
29  
sclass CtxVar extends CtxGeneral {
30  
  S var;
31  
  
32  
  *() {}
33  
  *(S *var) {}
34  
  
35  
  S str() { ret ctxGetVar(var); }
36  
}
37  
38  
sclass CtxNeg extends CtxBool {
39  
  CtxExpr e;
40  
  
41  
  *() {}
42  
  *(CtxExpr *e) {}
43  
  
44  
  bool get() { ret !e.get(); }
45  
}
46  
47  
sclass CtxAnd extends CtxBool {  
48  
  CtxExpr a, b;
49  
  
50  
  *() {}
51  
  *(CtxExpr *a, CtxExpr *b) {}
52  
53  
  bool get() { ret a.get() && b.get(); }
54  
}
55  
56  
sclass CtxOr extends CtxBool {  
57  
  CtxExpr a, b;
58  
  
59  
  *() {}
60  
  *(CtxExpr *a, CtxExpr *b) {}
61  
  
62  
  bool get() { ret a.get() || b.get(); }
63  
}
64  
65  
sclass CtxRegexp extends CtxBool {
66  
  S pattern;
67  
  
68  
  *() {}
69  
  *(S *pattern) {}
70  
  
71  
  bool get() { ret ctxEvalPattern(pattern); }
72  
}
73  
74  
sclass CtxComp extends CtxBool {
75  
  CtxExpr a, b;
76  
  
77  
  *() {}
78  
  *(CtxExpr *a, CtxExpr *b) {}
79  
  
80  
  bool get() { ret eq(a.str(), b.str()); }
81  
}
82  
83  
sclass CtxUneq extends CtxBool {
84  
  CtxExpr a, b;
85  
  
86  
  *() {}
87  
  *(CtxExpr *a, CtxExpr *b) {}
88  
89  
  bool get() { ret neq(a.str(), b.str()); }
90  
}
91  
92  
sclass CtxMatch extends CtxBool {
93  
  CtxExpr var;
94  
  S pattern;
95  
  
96  
  *() {}
97  
  *(CtxExpr *var, S *pattern) {}
98  
  
99  
  bool get() { ret ctxEvalPattern(pattern, var.str()); }
100  
}
101  
102  
sclass CtxFCall extends CtxGeneral {
103  
  S fname;
104  
  new L<CtxExpr> args;
105  
  
106  
  *() {}
107  
  *(S *fname) {}
108  
  
109  
  void add(CtxExpr arg) {
110  
    args.add(arg);
111  
  }
112  
  
113  
  S str() {
114  
    ret ctxCallFunction(fname, map(func(CtxExpr e) -> S { e.str() }, args));
115  
  }
116  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008907
Snippet name: CtxExpr etc.
Eternal ID of this version: #1008907/23
Text MD5: 489c415eab0f334cb800ef417025a4a9
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-09-27 14:56:46
Source code size: 2038 bytes / 116 lines
Pitched / IR pitched: No / No
Views / Downloads: 660 / 1567
Version history: 22 change(s)
Referenced in: [show references]