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

28
LINES

< > BotCompany Repo | #1017131 // jMatchStart function - match first tokens, return rest

JavaX fragment (include)

1  
// This function supports all the special stuff like <int>
2  
3  
static bool jMatchStart(S pat, S s) {
4  
  return jMatchStart(pat, s, null);
5  
}
6  
7  
// matches are as you expect, plus an extra item for the rest string
8  
static bool jMatchStart(S pat, S s, Matches matches) {
9  
  if (s == null) false;
10  
  ret jMatchStart(pat, javaTok(s), matches);
11  
}
12  
13  
sbool jMatchStart(S pat, LS toks) {
14  
  ret jMatchStart(pat, toks, null);
15  
}
16  
17  
sbool jMatchStart(S pat, LS toks, Matches matches) {
18  
  L<S> tokpat = jfind_preprocess(javaTok(pat));
19  
  if (toks.size() < tokpat.size()) ret false;
20  
  S[] m = match2x(tokpat, toks.subList(0, tokpat.size()));
21  
  if (m == null) false;
22  
  if (matches != null) {
23  
    matches.m = new S[m.length+1];
24  
    arraycopy(m, matches.m);
25  
    matches.m[m.length] = join(toks.subList(tokpat.size(), toks.size())); // for Matches.rest()
26  
  }
27  
  true;
28  
}

Author comment

Began life as a copy of #1001793

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017131
Snippet name: jMatchStart function - match first tokens, return rest
Eternal ID of this version: #1017131/6
Text MD5: 51d1cb2ece23650d4c9e33003897abb3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-23 20:07:14
Source code size: 863 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 428 / 482
Version history: 5 change(s)
Referenced in: [show references]