Libraryless. Click here for Pure Java version (12912L/74K).
1 | static boolean nlMatch(S pat, S nl, Map<S, Lisp> matches) { |
2 | matches.clear(); |
3 | ret nlMatch_sub(nlParse/*_cached*/(pat), nlParse(nl), matches); |
4 | } |
5 | |
6 | static boolean nlMatch(Lisp pat, S nl, Map<S, Lisp> matches) { |
7 | matches.clear(); |
8 | ret nlMatch_sub(pat, nlParse(nl), matches); |
9 | } |
10 | |
11 | static boolean nlMatch(S pat, Lisp nl, Map<S, Lisp> matches) { |
12 | matches.clear(); |
13 | ret nlMatch_sub(nlParse/*_cached*/(pat), nl, matches); |
14 | } |
15 | |
16 | static boolean nlMatch(Lisp pat, Lisp nl, Map<S, Lisp> matches) { |
17 | matches.clear(); |
18 | ret nlMatch_sub(pat, nl, matches); |
19 | } |
20 | |
21 | static boolean nlMatch_sub(Lisp pat, Lisp nl, Map<S, Lisp> m) { |
22 | if (pat == null || nl == null) ret false; |
23 | if (pat.isA("*")) |
24 | ret true; |
25 | if (nlIsVar(pat)) |
26 | ret nlMatch_putMatch(m, pat.head, nl); |
27 | |
28 | if (neq(pat.head, nl.head)) ret false; |
29 | |
30 | // heads identical, proceed to children |
31 | int n = pat.size(); |
32 | if (n != nl.size()) ret false; |
33 | |
34 | for (int i = 0; i < n; i++) |
35 | if (!nlMatch_sub(pat.get(i), nl.get(i), m)) |
36 | ret false; |
37 | |
38 | ret true; |
39 | } |
40 | |
41 | static boolean nlMatch_putMatch(Map<S, Lisp> matches, S key, Lisp val) { |
42 | key = dropPrefix("$", key); |
43 | if (matches.containsKey(key) && neq(matches.get(key), val)) |
44 | fail("multi-matching not implemented"); |
45 | matches.put(key, val); |
46 | ret true; |
47 | } |
Began life as a copy of #1002721
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: | #1002842 |
Snippet name: | nlMatch |
Eternal ID of this version: | #1002842/1 |
Text MD5: | 947e58870acfb91fe020207518a96827 |
Transpilation MD5: | b46422b680d71ffc11b7227f74e97dad |
Author: | stefan |
Category: | eleu / nl |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-03-02 21:04:45 |
Source code size: | 1310 bytes / 47 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 574 / 739 |
Referenced in: | [show references] |