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).

// combines a value with the merged token range of two PWTs
static <A> ParsedWithTokens<A> pwt_combine(A value, ParsedWithTokens p1, ParsedWithTokens p2) {
  assertSame(p1.tok, p2.tok);
  ret new ParsedWithTokens(value, p1.tok, min(p1.iStart, p2.iStart), max(p1.iRemaining, p2.iRemaining));
}

// increases the token range of a PWT merging another PWT
static <A> ParsedWithTokens<A> pwt_combine(ParsedWithTokens<A> p1, ParsedWithTokens p2) {
  ret pwt_combine(p1!, p1, p2);
}

// Second meaning: Combines all parses pb out of a list B
//   with all parses pa out of a list A
//   where pb occurred to the right of pb.
//   (Also applies a user-defined combination function merging pa and pb into a new PWT value.)

static <A, B, C> L<ParsedWithTokens<C>> pwt_combine(Iterable<ParsedWithTokens<A>> l1, Iterable<ParsedWithTokens<B>> l2, IF2<A, B, C> f) {
  new L<ParsedWithTokens<C>> out;
  for (ParsedWithTokens<A> a : l1)
    for (ParsedWithTokens<B> b : pwt_toTheRightOf(l2, a))
      out.add(pwt_combine(f.get(a!, b!), a, b));
  ret out;
}

// Same thing with 3 lists.

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) {
  new L<ParsedWithTokens<D>> out;
  for (ParsedWithTokens<A> a : l1)
    for (ParsedWithTokens<B> b : pwt_toTheRightOf(l2, a))
      for (ParsedWithTokens<C> c : pwt_toTheRightOf(l3, b))
        out.add(pwt_combine(f.get(a!, b!, c!), a, c));
  ret out;
}

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: 141 / 244
Version history: 12 change(s)
Referenced in: [show references]