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

45
LINES

< > BotCompany Repo | #1002749 // snlMatch2

JavaX fragment (include)

// snlMatch2 keeps existing matches and restores matches on false

static boolean snlMatch2(S pat, S snl, SNLMatches matches) {
  ret snlMatch2(snlToTree_cached(pat), snlToTree(snl), matches);
}

static boolean snlMatch2(Lisp pat, S snl, SNLMatches matches) {
  ret snlMatch2(pat, snlToTree(snl), matches);
}

static boolean snlMatch2(S pat, Lisp snl, SNLMatches matches) {
  ret snlMatch2(snlToTree_cached(pat), snl, matches);
}

static boolean snlMatch2(Lisp pat, Lisp snl, SNLMatches matches) {
  int level = matches.save();
  if (snlMatch2_sub(pat, snl, matches))
    ret true;
  matches.restore(level);
  ret false;
}

static boolean snlMatch2_sub(Lisp pat, Lisp snl, SNLMatches m) {
  if (pat == null || snl == null) ret false;
  if (pat.isA("*"))
    ret true;
  if (startsWithUpperCase(pat.head))
    ret snlMatch2_putMatch(m, pat.head, snl);
    
  if (neq(pat.head, snl.head)) ret false;
  
  // heads identical, proceed to children
  int n = pat.size();
  if (n != snl.size()) ret false;
  
  for (int i = 0; i < n; i++)
    if (!snlMatch2_sub(pat.get(i), snl.get(i), m))
      ret false;
      
  ret true;
}

static boolean snlMatch2_putMatch(SNLMatches matches, S key, Lisp val) {
  ret matches.put(key, val);
}

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: 617 / 873
Referenced in: [show references]