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

34
LINES

< > BotCompany Repo | #1028582 // pwt_combine

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5002L/28K).

1  
// combines a value with the merged token range of two PWTs
2  
static <A> ParsedWithTokens<A> pwt_combine(A value, ParsedWithTokens p1, ParsedWithTokens p2) {
3  
  assertSame(p1.tok, p2.tok);
4  
  ret new ParsedWithTokens(value, p1.tok, min(p1.iStart, p2.iStart), max(p1.iRemaining, p2.iRemaining));
5  
}
6  
7  
// increases the token range of a PWT merging another PWT
8  
static <A> ParsedWithTokens<A> pwt_combine(ParsedWithTokens<A> p1, ParsedWithTokens p2) {
9  
  ret pwt_combine(p1!, p1, p2);
10  
}
11  
12  
// Second meaning: Combines all parses pb out of a list B
13  
//   with all parses pa out of a list A
14  
//   where pb occurred to the right of pb.
15  
//   (Also applies a user-defined combination function merging pa and pb into a new PWT value.)
16  
17  
static <A, B, C> L<ParsedWithTokens<C>> pwt_combine(Iterable<ParsedWithTokens<A>> l1, Iterable<ParsedWithTokens<B>> l2, IF2<A, B, C> f) {
18  
  new L<ParsedWithTokens<C>> out;
19  
  for (ParsedWithTokens<A> a : l1)
20  
    for (ParsedWithTokens<B> b : pwt_toTheRightOf(l2, a))
21  
      out.add(pwt_combine(f.get(a!, b!), a, b));
22  
  ret out;
23  
}
24  
25  
// Same thing with 3 lists.
26  
27  
static <A, B, C, D> L<ParsedWithTokens<D>> pwt_combine(Iterable<ParsedWithTokens<A>> l1, Iterable<ParsedWithTokens<B>> l2, Iterable<ParsedWithTokens<C>> l3, IF3<A, B, C, D> f) {
28  
  new L<ParsedWithTokens<D>> out;
29  
  for (ParsedWithTokens<A> a : l1)
30  
    for (ParsedWithTokens<B> b : pwt_toTheRightOf(l2, a))
31  
      for (ParsedWithTokens<C> c : pwt_toTheRightOf(l3, b))
32  
        out.add(pwt_combine(f.get(a!, b!, c!), a, c));
33  
  ret out;
34  
}

Author comment

Began life as a copy of #1028581

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028582
Snippet name: pwt_combine
Eternal ID of this version: #1028582/13
Text MD5: a2d036dfd29d74fe1585510faa1a223f
Transpilation MD5: 1a549a231ee3e7ea84b468350cc25a91
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-15 00:46:34
Source code size: 1537 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 151 / 266
Version history: 12 change(s)
Referenced in: [show references]