1 | sbool matchDoubleRest(S pat, S s) {
|
2 | ret matchDoubleRest(pat, s, null); |
3 | } |
4 | |
5 | // matches are as you expect, plus an extra item for half of the rest string |
6 | sbool matchDoubleRest(S pat, S s, Matches matches) {
|
7 | if (s == null) false; |
8 | ret matchDoubleRest(pat, parse3_cachedInput(s), matches); |
9 | } |
10 | |
11 | sbool matchDoubleRest(S pat, LS toks, Matches matches) {
|
12 | if (toks == null) false; |
13 | LS tokpat = parse3_cachedPattern(pat); |
14 | int n = toks.size(), nPat = tokpat.size(); |
15 | if (n <= nPat || odd((n-nPat)/2)) ret false; |
16 | int nRest = (n-nPat)/4; |
17 | ifdef matchDoubleRest_debug |
18 | print(+nRest); |
19 | endifdef |
20 | S[] m = match2(tokpat, subList(toks, 0, nPat)); |
21 | if (m == null) false; |
22 | for (int i = nPat; i < nPat+nRest*2; i += 2) |
23 | if (neqic(toks.get(i), toks.get(i+nRest*2))) {
|
24 | ifdef matchDoubleRest_debug |
25 | print("fail at " + i + ": " + toks.get(i) + " / " + toks.get(i+nRest*2));
|
26 | endifdef |
27 | ret false; |
28 | } |
29 | |
30 | if (matches != null) {
|
31 | matches.m = new S[m.length+1]; |
32 | arraycopy(m, matches.m); |
33 | matches.m[m.length] = joinSubList(toks, nPat, nPat+nRest*2-1); // for Matches.rest() |
34 | } |
35 | |
36 | true; |
37 | } |
Began life as a copy of #1001793
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: | #1023234 |
| Snippet name: | matchDoubleRest function - e.g. "is" matches "is green green" or "is good luck good luck" |
| Eternal ID of this version: | #1023234/8 |
| Text MD5: | 9675fd28101292c6e3478afc523a66a2 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-05-19 00:09:07 |
| Source code size: | 1155 bytes / 37 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 449 / 518 |
| Version history: | 7 change(s) |
| Referenced in: | [show references] |