1 | static boolean snlMatch(S pat, S snl, Map<S, Lisp> matches) { |
2 | matches.clear(); |
3 | ret snlMatch_sub(snlToTree_cached(pat), snlToTree(snl), matches); |
4 | } |
5 | |
6 | static boolean snlMatch(Lisp pat, S snl, Map<S, Lisp> matches) { |
7 | matches.clear(); |
8 | ret snlMatch_sub(pat, snlToTree(snl), matches); |
9 | } |
10 | |
11 | static boolean snlMatch(S pat, Lisp snl, Map<S, Lisp> matches) { |
12 | matches.clear(); |
13 | ret snlMatch_sub(snlToTree_cached(pat), snl, matches); |
14 | } |
15 | |
16 | static boolean snlMatch(Lisp pat, Lisp snl, Map<S, Lisp> matches) { |
17 | matches.clear(); |
18 | ret snlMatch_sub(pat, snl, matches); |
19 | } |
20 | |
21 | static boolean snlMatch_sub(Lisp pat, Lisp snl, Map<S, Lisp> m) { |
22 | if (pat == null || snl == null) ret false; |
23 | if (pat.isA("*")) |
24 | ret true; |
25 | if (startsWithUpperCase(pat.head)) |
26 | ret snlMatch_putMatch(m, pat.head, snl); |
27 | |
28 | if (neq(pat.head, snl.head)) ret false; |
29 | |
30 | // heads identical, proceed to children |
31 | int n = pat.size(); |
32 | if (n != snl.size()) ret false; |
33 | |
34 | for (int i = 0; i < n; i++) |
35 | if (!snlMatch_sub(pat.get(i), snl.get(i), m)) |
36 | ret false; |
37 | |
38 | ret true; |
39 | } |
40 | |
41 | static boolean snlMatch_putMatch(Map<S, Lisp> matches, S key, Lisp val) { |
42 | if (matches.containsKey(key) && neq(matches.get(key), val)) |
43 | fail("multi-matching not implemented"); |
44 | matches.put(key, val); |
45 | ret true; |
46 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002721 |
Snippet name: | snlMatch |
Eternal ID of this version: | #1002721/1 |
Text MD5: | 55b771ac4547b91a9ae76c074dde1f48 |
Author: | stefan |
Category: | eleu / nl |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-19 21:25:10 |
Source code size: | 1322 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 665 / 716 |
Referenced in: | [show references] |