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

28
LINES

< > BotCompany Repo | #1026471 // Creator/Critic Parser Spike v2

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (8491L/61K).

!7

abstract sclass Proposal {
  int localScore() { ret 0; }
  toString { ret "[" + localScore() + "] " + sfu(this); }
  Proposal parent;
  
  selfType parent(Proposal parent) { this.parent = parent; this; }
}

static noToString record EnclosedIn(S l, LS contents, S r) extends Proposal {
  int localScore() { ret scoreOneIfBracketPair(l, r); }
}

static noToString record Infix(LS l, S op, LS r) extends Proposal {}

svoid parse(LS tok, Proposal parent) {
  // drop first and last
  if (l(tok) >= 3)
    emit(new EnclosedIn(first(tok), dropFirstAndLast2(tok), last(tok)).parent(parent));
  for (int i = 1; i < l(tok)-1; i++)
    emit(new Infix(subList(tok, 0, i), tok.get(i), subList(tok, i+1)).parent(parent));
}

p-exp {
  LS tok = javaTokC("[(a|b), (c|d), (e|f)]");
  parse(tok, null);
}

Author comment

Began life as a copy of #1026470

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: #1026471
Snippet name: Creator/Critic Parser Spike v2
Eternal ID of this version: #1026471/11
Text MD5: 1d4ce324c9a6298a247504229f07e2e4
Transpilation MD5: 442ce3d734109b07d65699ba6bd271db
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-05 14:28:32
Source code size: 818 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 139 / 521
Version history: 10 change(s)
Referenced in: [show references]