1 | scope gazelle_addVarSplittersToRules. |
2 | |
3 | sclass #VarSplitter { |
4 | S var; |
5 | bool debug; |
6 | |
7 | *() {} |
8 | *(S *var, bool *debug) {} |
9 | |
10 | SS get(SS map, LS tokC, LS tokI, RuleEngine2_MatchedRule matched) { |
11 | if (map == null) null; |
12 | S value = getOrKeep(map, curly(var)); |
13 | LS tok1 = matched.tokenize(var); |
14 | LS tok2 = matched.tokenize(uncurly(value)); |
15 | if (debug) print("VarSplitter: " + tok1 + " / " + tok2); |
16 | if (l(tok1) != l(tok2)) null; |
17 | int oldSize = l(map); |
18 | for (int i = 1; i < l(tok1); i += 2) |
19 | if (!strictPutIC(map, tok1.get(i), tok2.get(i))) null; |
20 | if (debug) print("VarSplitter done => " + map); |
21 | matched.nPossibleVars = matched.nPossibleVars() + l(map)-oldSize; |
22 | ret map; |
23 | } |
24 | } |
25 | |
26 | svoid gazelle_addVarSplittersToRules(RuleEngine2 engine, O... _) { |
27 | new Matches m; |
28 | bool debug = boolPar debug(_); |
29 | for (final RuleEngine2.Rule r : engine.rules) { |
30 | continue unless jmatchAny("split *", r.comments, m) && isQuoted(m.get(0)); |
31 | S var = $1; |
32 | if (debug) print("Made splitter for: " + var); |
33 | r.addMapMassager(new VarSplitter(var, debug)); |
34 | } |
35 | } |
36 | |
37 | end scope |
Began life as a copy of #1021688
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: | #1021811 |
Snippet name: | gazelle_addVarSplittersToRules |
Eternal ID of this version: | #1021811/12 |
Text MD5: | a9b93e691bfaeae52d59ca6a5a4b966c |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-03-02 18:47:46 |
Source code size: | 1131 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 282 / 336 |
Version history: | 11 change(s) |
Referenced in: | [show references] |