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

1  
!7
2  
3  
abstract sclass Proposal {
4  
  int localScore() { ret 0; }
5  
  toString { ret "[" + localScore() + "] " + sfu(this); }
6  
  Proposal parent;
7  
  
8  
  selfType parent(Proposal parent) { this.parent = parent; this; }
9  
}
10  
11  
static noToString record EnclosedIn(S l, LS contents, S r) extends Proposal {
12  
  int localScore() { ret scoreOneIfBracketPair(l, r); }
13  
}
14  
15  
static noToString record Infix(LS l, S op, LS r) extends Proposal {}
16  
17  
svoid parse(LS tok, Proposal parent) {
18  
  // drop first and last
19  
  if (l(tok) >= 3)
20  
    emit(new EnclosedIn(first(tok), dropFirstAndLast2(tok), last(tok)).parent(parent));
21  
  for (int i = 1; i < l(tok)-1; i++)
22  
    emit(new Infix(subList(tok, 0, i), tok.get(i), subList(tok, i+1)).parent(parent));
23  
}
24  
25  
p-exp {
26  
  LS tok = javaTokC("[(a|b), (c|d), (e|f)]");
27  
  parse(tok, null);
28  
}

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: 239 / 810
Version history: 10 change(s)
Referenced in: [show references]