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

18
LINES

< > BotCompany Repo | #1018415 // matchEnd function - match last tokens, return rest

JavaX fragment (include)

1  
static boolean matchEnd(S pat, S s) {
2  
  return matchEnd(pat, s, null);
3  
}
4  
5  
// matches are as you expect, plus an extra item for the rest string
6  
static boolean matchEnd(S pat, S s, Matches matches) {
7  
  if (s == null) false;
8  
  L<S> tokpat = parse3(pat), toks = parse3(s);
9  
  if (toks.size() < tokpat.size()) false;
10  
  S[] m = match2(tokpat, takeLast(l(tokpat), toks));
11  
  if (m == null) false;
12  
  if (matches != null) {
13  
    matches.m = new S[m.length+1];
14  
    arraycopy(m, matches.m);
15  
    matches.m[m.length] = join(dropLast(l(tokpat), toks)); // for Matches.rest()
16  
  }
17  
  true;
18  
}

Author comment

Began life as a copy of #1001793

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018415
Snippet name: matchEnd function - match last tokens, return rest
Eternal ID of this version: #1018415/3
Text MD5: affcdfed33cf940dc7d13366051a851a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-13 00:05:16
Source code size: 588 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 360 / 400
Version history: 2 change(s)
Referenced in: [show references]