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

45
LINES

< > BotCompany Repo | #1002749 // snlMatch2

JavaX fragment (include)

1  
// snlMatch2 keeps existing matches and restores matches on false
2  
3  
static boolean snlMatch2(S pat, S snl, SNLMatches matches) {
4  
  ret snlMatch2(snlToTree_cached(pat), snlToTree(snl), matches);
5  
}
6  
7  
static boolean snlMatch2(Lisp pat, S snl, SNLMatches matches) {
8  
  ret snlMatch2(pat, snlToTree(snl), matches);
9  
}
10  
11  
static boolean snlMatch2(S pat, Lisp snl, SNLMatches matches) {
12  
  ret snlMatch2(snlToTree_cached(pat), snl, matches);
13  
}
14  
15  
static boolean snlMatch2(Lisp pat, Lisp snl, SNLMatches matches) {
16  
  int level = matches.save();
17  
  if (snlMatch2_sub(pat, snl, matches))
18  
    ret true;
19  
  matches.restore(level);
20  
  ret false;
21  
}
22  
23  
static boolean snlMatch2_sub(Lisp pat, Lisp snl, SNLMatches m) {
24  
  if (pat == null || snl == null) ret false;
25  
  if (pat.isA("*"))
26  
    ret true;
27  
  if (startsWithUpperCase(pat.head))
28  
    ret snlMatch2_putMatch(m, pat.head, snl);
29  
    
30  
  if (neq(pat.head, snl.head)) ret false;
31  
  
32  
  // heads identical, proceed to children
33  
  int n = pat.size();
34  
  if (n != snl.size()) ret false;
35  
  
36  
  for (int i = 0; i < n; i++)
37  
    if (!snlMatch2_sub(pat.get(i), snl.get(i), m))
38  
      ret false;
39  
      
40  
  ret true;
41  
}
42  
43  
static boolean snlMatch2_putMatch(SNLMatches matches, S key, Lisp val) {
44  
  ret matches.put(key, val);
45  
}

Author comment

Began life as a copy of #1002728

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: #1002749
Snippet name: snlMatch2
Eternal ID of this version: #1002749/1
Text MD5: ccc768f6124765692e605c40a47f5db0
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:49:52
Source code size: 1269 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 714 / 974
Referenced in: [show references]