jkf 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +16 -0
- data/.rubocop.yml +7 -1008
- data/.rubocop_todo.yml +452 -3
- data/CHANGELOG.md +46 -0
- data/Gemfile +5 -3
- data/README.en.md +31 -17
- data/README.md +6 -4
- data/Rakefile +5 -0
- data/jkf.gemspec +3 -0
- data/lib/jkf/converter/csa.rb +14 -6
- data/lib/jkf/converter/kif.rb +5 -3
- data/lib/jkf/converter/kifuable.rb +1 -3
- data/lib/jkf/parser/csa.rb +224 -236
- data/lib/jkf/parser/ki2.rb +102 -106
- data/lib/jkf/parser/kif.rb +181 -197
- data/lib/jkf/parser/kifuable.rb +156 -168
- data/lib/jkf/version.rb +1 -1
- data/manifest.scm +142 -0
- data/po/all.pot +170 -0
- data/po/en.po +200 -0
- data/po4a.cfg +11 -0
- metadata +12 -9
- data/.codeclimate.yml +0 -28
- data/.travis.yml +0 -9
data/lib/jkf/parser/kif.rb
CHANGED
@@ -35,7 +35,10 @@ module Jkf::Parser
|
|
35
35
|
end
|
36
36
|
parse_split
|
37
37
|
s6 = parse_moves
|
38
|
-
if s6
|
38
|
+
if s6 == :failed
|
39
|
+
@current_pos = s0
|
40
|
+
s0 = :failed
|
41
|
+
else
|
39
42
|
s7 = []
|
40
43
|
s8 = parse_fork
|
41
44
|
while s8 != :failed
|
@@ -45,9 +48,6 @@ module Jkf::Parser
|
|
45
48
|
parse_nl
|
46
49
|
@reported_pos = s0
|
47
50
|
s0 = transform_root(s2, s3, s4, s6, s7)
|
48
|
-
else
|
49
|
-
@current_pos = s0
|
50
|
-
s0 = :failed
|
51
51
|
end
|
52
52
|
|
53
53
|
s0
|
@@ -59,29 +59,27 @@ module Jkf::Parser
|
|
59
59
|
def parse_header
|
60
60
|
s0 = @current_pos
|
61
61
|
s2 = match_regexp(/^[^:\r\n]/)
|
62
|
-
if s2
|
62
|
+
if s2 == :failed
|
63
|
+
s1 = :failed
|
64
|
+
else
|
63
65
|
s1 = []
|
64
66
|
while s2 != :failed
|
65
67
|
s1 << s2
|
66
68
|
s2 = match_regexp(/^[^:\r\n]/)
|
67
69
|
end
|
68
|
-
else
|
69
|
-
s1 = :failed
|
70
70
|
end
|
71
|
-
if s1
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
s0 = s1
|
78
|
-
else
|
79
|
-
@current_pos = s0
|
80
|
-
s0 = :failed
|
81
|
-
end
|
82
|
-
else
|
71
|
+
if s1 == :failed
|
72
|
+
@current_pos = s0
|
73
|
+
s0 = :failed
|
74
|
+
elsif match_str(":") != :failed
|
75
|
+
s3 = parse_nonls
|
76
|
+
if parse_nl == :failed
|
83
77
|
@current_pos = s0
|
84
78
|
s0 = :failed
|
79
|
+
else
|
80
|
+
@reported_pos = s0
|
81
|
+
s1 = { "k" => s1.join, "v" => s3.join }
|
82
|
+
s0 = s1
|
85
83
|
end
|
86
84
|
else
|
87
85
|
@current_pos = s0
|
@@ -90,18 +88,16 @@ module Jkf::Parser
|
|
90
88
|
if s0 == :failed
|
91
89
|
s0 = @current_pos
|
92
90
|
s1 = parse_turn
|
93
|
-
if s1
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
else
|
99
|
-
@current_pos = s0
|
100
|
-
s0 = :failed
|
101
|
-
end
|
102
|
-
else
|
91
|
+
if s1 == :failed
|
92
|
+
@current_pos = s0
|
93
|
+
s0 = :failed
|
94
|
+
elsif match_str("手番") != :failed
|
95
|
+
if parse_nl == :failed
|
103
96
|
@current_pos = s0
|
104
97
|
s0 = :failed
|
98
|
+
else
|
99
|
+
@reported_pos = s0
|
100
|
+
s0 = { "k" => "手番", "v" => s1 }
|
105
101
|
end
|
106
102
|
else
|
107
103
|
@current_pos = s0
|
@@ -109,14 +105,12 @@ module Jkf::Parser
|
|
109
105
|
end
|
110
106
|
if s0 == :failed
|
111
107
|
s0 = @current_pos
|
112
|
-
if match_str("盤面回転")
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
s0 = :failed
|
119
|
-
end
|
108
|
+
if match_str("盤面回転") == :failed
|
109
|
+
@current_pos = s0
|
110
|
+
s0 = :failed
|
111
|
+
elsif parse_nl != :failed
|
112
|
+
@reported_pos = s0
|
113
|
+
s0 = nil
|
120
114
|
else
|
121
115
|
@current_pos = s0
|
122
116
|
s0 = :failed
|
@@ -136,19 +130,19 @@ module Jkf::Parser
|
|
136
130
|
def parse_split
|
137
131
|
s0 = @current_pos
|
138
132
|
s1 = match_str("手数----指手--")
|
139
|
-
if s1
|
133
|
+
if s1 == :failed
|
134
|
+
@current_pos = s0
|
135
|
+
s0 = :failed
|
136
|
+
else
|
140
137
|
s2 = match_str("-------消費時間--")
|
141
138
|
s2 = nil if s2 == :failed
|
142
139
|
s3 = parse_nl
|
143
|
-
if s3
|
144
|
-
s0 = [s1, s2, s3]
|
145
|
-
else
|
140
|
+
if s3 == :failed
|
146
141
|
@current_pos = s0
|
147
142
|
s0 = :failed
|
143
|
+
else
|
144
|
+
s0 = [s1, s2, s3]
|
148
145
|
end
|
149
|
-
else
|
150
|
-
@current_pos = s0
|
151
|
-
s0 = :failed
|
152
146
|
end
|
153
147
|
s0
|
154
148
|
end
|
@@ -157,7 +151,10 @@ module Jkf::Parser
|
|
157
151
|
def parse_moves
|
158
152
|
s0 = @current_pos
|
159
153
|
s1 = parse_firstboard
|
160
|
-
if s1
|
154
|
+
if s1 == :failed
|
155
|
+
@current_pos = s0
|
156
|
+
s0 = :failed
|
157
|
+
else
|
161
158
|
parse_split
|
162
159
|
s2 = []
|
163
160
|
s3 = parse_move
|
@@ -168,9 +165,6 @@ module Jkf::Parser
|
|
168
165
|
parse_result
|
169
166
|
@reported_pos = s0
|
170
167
|
s0 = s2.unshift(s1)
|
171
|
-
else
|
172
|
-
@current_pos = s0
|
173
|
-
s0 = :failed
|
174
168
|
end
|
175
169
|
s0
|
176
170
|
end
|
@@ -194,7 +188,10 @@ module Jkf::Parser
|
|
194
188
|
def parse_move
|
195
189
|
s0 = @current_pos
|
196
190
|
s1 = parse_line
|
197
|
-
if s1
|
191
|
+
if s1 == :failed
|
192
|
+
@current_pos = s0
|
193
|
+
s0 = :failed
|
194
|
+
else
|
198
195
|
s2 = []
|
199
196
|
s3 = parse_comment
|
200
197
|
while s3 != :failed
|
@@ -204,9 +201,6 @@ module Jkf::Parser
|
|
204
201
|
parse_pointer
|
205
202
|
@reported_pos = s0
|
206
203
|
s0 = transform_move(s1, s2)
|
207
|
-
else
|
208
|
-
@current_pos = s0
|
209
|
-
s0 = :failed
|
210
204
|
end
|
211
205
|
s0
|
212
206
|
end
|
@@ -216,22 +210,25 @@ module Jkf::Parser
|
|
216
210
|
s0 = @current_pos
|
217
211
|
match_spaces
|
218
212
|
s2 = parse_te
|
219
|
-
if s2
|
213
|
+
if s2 == :failed
|
214
|
+
@current_pos = s0
|
215
|
+
s0 = :failed
|
216
|
+
else
|
220
217
|
match_spaces
|
221
218
|
s4 = @current_pos
|
222
219
|
s5 = parse_fugou
|
223
|
-
if s5
|
220
|
+
if s5 == :failed
|
221
|
+
@current_pos = s4
|
222
|
+
s4 = :failed
|
223
|
+
else
|
224
224
|
s6 = parse_from
|
225
|
-
if s6
|
226
|
-
@reported_pos = s4
|
227
|
-
s4 = transform_teban_fugou_from(s2, s5, s6)
|
228
|
-
else
|
225
|
+
if s6 == :failed
|
229
226
|
@current_pos = s4
|
230
227
|
s4 = :failed
|
228
|
+
else
|
229
|
+
@reported_pos = s4
|
230
|
+
s4 = transform_teban_fugou_from(s2, s5, s6)
|
231
231
|
end
|
232
|
-
else
|
233
|
-
@current_pos = s4
|
234
|
-
s4 = :failed
|
235
232
|
end
|
236
233
|
if s4 == :failed
|
237
234
|
s4 = @current_pos
|
@@ -244,25 +241,22 @@ module Jkf::Parser
|
|
244
241
|
@reported_pos = s4
|
245
242
|
s4 = s5.join
|
246
243
|
end
|
247
|
-
if s4
|
244
|
+
if s4 == :failed
|
245
|
+
@current_pos = s0
|
246
|
+
s0 = :failed
|
247
|
+
else
|
248
248
|
match_spaces
|
249
249
|
s6 = parse_time
|
250
250
|
s6 = nil if s6 == :failed
|
251
251
|
match_str("+")
|
252
|
-
if parse_nl
|
253
|
-
@reported_pos = s0
|
254
|
-
s0 = { "move" => s4, "time" => s6 }
|
255
|
-
else
|
252
|
+
if parse_nl == :failed
|
256
253
|
@current_pos = s0
|
257
254
|
s0 = :failed
|
255
|
+
else
|
256
|
+
@reported_pos = s0
|
257
|
+
s0 = { "move" => s4, "time" => s6 }
|
258
258
|
end
|
259
|
-
else
|
260
|
-
@current_pos = s0
|
261
|
-
s0 = :failed
|
262
259
|
end
|
263
|
-
else
|
264
|
-
@current_pos = s0
|
265
|
-
s0 = :failed
|
266
260
|
end
|
267
261
|
s0
|
268
262
|
end
|
@@ -276,20 +270,20 @@ module Jkf::Parser
|
|
276
270
|
def parse_fugou
|
277
271
|
s0 = @current_pos
|
278
272
|
s1 = parse_place
|
279
|
-
if s1
|
273
|
+
if s1 == :failed
|
274
|
+
@current_pos = s0
|
275
|
+
s0 = :failed
|
276
|
+
else
|
280
277
|
s2 = parse_piece
|
281
|
-
if s2
|
278
|
+
if s2 == :failed
|
279
|
+
@current_pos = s0
|
280
|
+
s0 = :failed
|
281
|
+
else
|
282
282
|
s3 = match_str("成")
|
283
283
|
s3 = nil if s3 == :failed
|
284
284
|
@reported_pos = s0
|
285
285
|
s0 = { "to" => s1, "piece" => s2, "promote" => !!s3 }
|
286
|
-
else
|
287
|
-
@current_pos = s0
|
288
|
-
s0 = :failed
|
289
286
|
end
|
290
|
-
else
|
291
|
-
@current_pos = s0
|
292
|
-
s0 = :failed
|
293
287
|
end
|
294
288
|
s0
|
295
289
|
end
|
@@ -298,18 +292,18 @@ module Jkf::Parser
|
|
298
292
|
def parse_place
|
299
293
|
s0 = @current_pos
|
300
294
|
s1 = parse_num
|
301
|
-
if s1
|
295
|
+
if s1 == :failed
|
296
|
+
@current_pos = s0
|
297
|
+
s0 = :failed
|
298
|
+
else
|
302
299
|
s2 = parse_numkan
|
303
|
-
if s2
|
304
|
-
@reported_pos = s0
|
305
|
-
s0 = { "x" => s1, "y" => s2 }
|
306
|
-
else
|
300
|
+
if s2 == :failed
|
307
301
|
@current_pos = s0
|
308
302
|
s0 = :failed
|
303
|
+
else
|
304
|
+
@reported_pos = s0
|
305
|
+
s0 = { "x" => s1, "y" => s2 }
|
309
306
|
end
|
310
|
-
else
|
311
|
-
@current_pos = s0
|
312
|
-
s0 = :failed
|
313
307
|
end
|
314
308
|
if s0 == :failed
|
315
309
|
s0 = @current_pos
|
@@ -334,29 +328,27 @@ module Jkf::Parser
|
|
334
328
|
s0 = s1
|
335
329
|
if s0 == :failed
|
336
330
|
s0 = @current_pos
|
337
|
-
if match_str("(")
|
331
|
+
if match_str("(") == :failed
|
332
|
+
@current_pos = s0
|
333
|
+
s0 = :failed
|
334
|
+
else
|
338
335
|
s2 = match_regexp(/^[1-9]/)
|
339
|
-
if s2
|
336
|
+
if s2 == :failed
|
337
|
+
@current_pos = s0
|
338
|
+
s0 = :failed
|
339
|
+
else
|
340
340
|
s3 = match_regexp(/^[1-9]/)
|
341
|
-
if s3
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
s0 = :failed
|
348
|
-
end
|
341
|
+
if s3 == :failed
|
342
|
+
@current_pos = s0
|
343
|
+
s0 = :failed
|
344
|
+
elsif match_str(")") != :failed
|
345
|
+
@reported_pos = s0
|
346
|
+
s0 = { "x" => s2.to_i, "y" => s3.to_i }
|
349
347
|
else
|
350
348
|
@current_pos = s0
|
351
349
|
s0 = :failed
|
352
350
|
end
|
353
|
-
else
|
354
|
-
@current_pos = s0
|
355
|
-
s0 = :failed
|
356
351
|
end
|
357
|
-
else
|
358
|
-
@current_pos = s0
|
359
|
-
s0 = :failed
|
360
352
|
end
|
361
353
|
end
|
362
354
|
s0
|
@@ -365,39 +357,39 @@ module Jkf::Parser
|
|
365
357
|
# time : "(" " "* ms " "* "/" " "* (hms | ms) " "* ")"
|
366
358
|
def parse_time
|
367
359
|
s0 = @current_pos
|
368
|
-
if match_str("(")
|
360
|
+
if match_str("(") == :failed
|
361
|
+
@current_pos = s0
|
362
|
+
s0 = :failed
|
363
|
+
else
|
369
364
|
match_spaces
|
370
365
|
s3 = parse_ms
|
371
|
-
if s3
|
366
|
+
if s3 == :failed
|
367
|
+
@current_pos = s0
|
368
|
+
s0 = :failed
|
369
|
+
else
|
372
370
|
match_spaces
|
373
|
-
if match_str("/")
|
371
|
+
if match_str("/") == :failed
|
372
|
+
@current_pos = s0
|
373
|
+
s0 = :failed
|
374
|
+
else
|
374
375
|
match_spaces
|
375
376
|
s5 = parse_hms
|
376
377
|
s5 = parse_ms(with_hour: true) if s5 == :failed
|
377
|
-
if s5
|
378
|
+
if s5 == :failed
|
379
|
+
@current_pos = s0
|
380
|
+
s0 = :failed
|
381
|
+
else
|
378
382
|
match_spaces
|
379
|
-
if match_str(")")
|
380
|
-
@reported_pos = s0
|
381
|
-
s0 = { "now" => s3, "total" => s5 }
|
382
|
-
else
|
383
|
+
if match_str(")") == :failed
|
383
384
|
@current_pos = s0
|
384
385
|
s0 = :failed
|
386
|
+
else
|
387
|
+
@reported_pos = s0
|
388
|
+
s0 = { "now" => s3, "total" => s5 }
|
385
389
|
end
|
386
|
-
else
|
387
|
-
@current_pos = s0
|
388
|
-
s0 = :failed
|
389
390
|
end
|
390
|
-
else
|
391
|
-
@current_pos = s0
|
392
|
-
s0 = :failed
|
393
391
|
end
|
394
|
-
else
|
395
|
-
@current_pos = s0
|
396
|
-
s0 = :failed
|
397
392
|
end
|
398
|
-
else
|
399
|
-
@current_pos = s0
|
400
|
-
s0 = :failed
|
401
393
|
end
|
402
394
|
s0
|
403
395
|
end
|
@@ -407,26 +399,22 @@ module Jkf::Parser
|
|
407
399
|
s0 = @current_pos
|
408
400
|
s1 = match_digits!
|
409
401
|
|
410
|
-
if s1
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
s0 = :failed
|
422
|
-
end
|
423
|
-
else
|
424
|
-
@current_pos = s0
|
425
|
-
s0 = :failed
|
426
|
-
end
|
427
|
-
else
|
402
|
+
if s1 == :failed
|
403
|
+
@current_pos = s0
|
404
|
+
s0 = :failed
|
405
|
+
elsif match_str(":") != :failed
|
406
|
+
s3 = match_digits!
|
407
|
+
if s3 == :failed
|
408
|
+
@current_pos = s0
|
409
|
+
s0 = :failed
|
410
|
+
elsif match_str(":") != :failed
|
411
|
+
s5 = match_digits!
|
412
|
+
if s5 == :failed
|
428
413
|
@current_pos = s0
|
429
414
|
s0 = :failed
|
415
|
+
else
|
416
|
+
@reported_pos = s0
|
417
|
+
s0 = { "h" => s1.join.to_i, "m" => s3.join.to_i, "s" => s5.join.to_i }
|
430
418
|
end
|
431
419
|
else
|
432
420
|
@current_pos = s0
|
@@ -443,27 +431,25 @@ module Jkf::Parser
|
|
443
431
|
def parse_ms(with_hour: false)
|
444
432
|
s0 = @current_pos
|
445
433
|
s1 = match_digits!
|
446
|
-
if s1
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
s = s3.join.to_i
|
453
|
-
if with_hour
|
454
|
-
h = m / 60
|
455
|
-
m = m % 60
|
456
|
-
s0 = { "h" => h, "m" => m, "s" => s }
|
457
|
-
else
|
458
|
-
s0 = { "m" => m, "s" => s }
|
459
|
-
end
|
460
|
-
else
|
461
|
-
@current_pos = s0
|
462
|
-
s0 = :failed
|
463
|
-
end
|
464
|
-
else
|
434
|
+
if s1 == :failed
|
435
|
+
@current_pos = s0
|
436
|
+
s0 = :failed
|
437
|
+
elsif match_str(":") != :failed
|
438
|
+
s3 = match_digits!
|
439
|
+
if s3 == :failed
|
465
440
|
@current_pos = s0
|
466
441
|
s0 = :failed
|
442
|
+
else
|
443
|
+
@reported_pos = s0
|
444
|
+
m = s1.join.to_i
|
445
|
+
s = s3.join.to_i
|
446
|
+
if with_hour
|
447
|
+
h = m / 60
|
448
|
+
m = m % 60
|
449
|
+
s0 = { "h" => h, "m" => m, "s" => s }
|
450
|
+
else
|
451
|
+
s0 = { "m" => m, "s" => s }
|
452
|
+
end
|
467
453
|
end
|
468
454
|
else
|
469
455
|
@current_pos = s0
|
@@ -475,34 +461,34 @@ module Jkf::Parser
|
|
475
461
|
# comment : "*" nonls nl | "&" nonls nl
|
476
462
|
def parse_comment
|
477
463
|
s0 = @current_pos
|
478
|
-
if match_str("*")
|
464
|
+
if match_str("*") == :failed
|
465
|
+
@current_pos = s0
|
466
|
+
s0 = :failed
|
467
|
+
else
|
479
468
|
s2 = parse_nonls
|
480
|
-
if parse_nl
|
481
|
-
@reported_pos = s0
|
482
|
-
s0 = s2.join
|
483
|
-
else
|
469
|
+
if parse_nl == :failed
|
484
470
|
@current_pos = s0
|
485
471
|
s0 = :failed
|
472
|
+
else
|
473
|
+
@reported_pos = s0
|
474
|
+
s0 = s2.join
|
486
475
|
end
|
487
|
-
else
|
488
|
-
@current_pos = s0
|
489
|
-
s0 = :failed
|
490
476
|
end
|
491
477
|
if s0 == :failed
|
492
478
|
s0 = @current_pos
|
493
479
|
s1 = match_str("&")
|
494
|
-
if s1
|
480
|
+
if s1 == :failed
|
481
|
+
@current_pos = s0
|
482
|
+
s0 = :failed
|
483
|
+
else
|
495
484
|
s2 = parse_nonls
|
496
|
-
if parse_nl
|
497
|
-
@reported_pos = s0
|
498
|
-
s0 = "&" + s2.join
|
499
|
-
else
|
485
|
+
if parse_nl == :failed
|
500
486
|
@current_pos = s0
|
501
487
|
s0 = :failed
|
488
|
+
else
|
489
|
+
@reported_pos = s0
|
490
|
+
s0 = "&" + s2.join
|
502
491
|
end
|
503
|
-
else
|
504
|
-
@current_pos = s0
|
505
|
-
s0 = :failed
|
506
492
|
end
|
507
493
|
end
|
508
494
|
s0
|
@@ -511,35 +497,33 @@ module Jkf::Parser
|
|
511
497
|
# fork : "変化:" " "* [0-9]+ "手" nl moves
|
512
498
|
def parse_fork
|
513
499
|
s0 = @current_pos
|
514
|
-
if match_str("変化:")
|
500
|
+
if match_str("変化:") == :failed
|
501
|
+
@current_pos = s0
|
502
|
+
s0 = :failed
|
503
|
+
else
|
515
504
|
match_spaces
|
516
505
|
s3 = parse_te
|
517
|
-
if s3
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
end
|
528
|
-
else
|
506
|
+
if s3 == :failed
|
507
|
+
@current_pos = s0
|
508
|
+
s0 = :failed
|
509
|
+
elsif match_str("手") != :failed
|
510
|
+
if parse_nl == :failed
|
511
|
+
@current_pos = s0
|
512
|
+
s0 = :failed
|
513
|
+
else
|
514
|
+
s6 = parse_moves
|
515
|
+
if s6 == :failed
|
529
516
|
@current_pos = s0
|
530
517
|
s0 = :failed
|
518
|
+
else
|
519
|
+
@reported_pos = s0
|
520
|
+
s0 = { "te" => s3.join.to_i, "moves" => s6[1..-1] }
|
531
521
|
end
|
532
|
-
else
|
533
|
-
@current_pos = s0
|
534
|
-
s0 = :failed
|
535
522
|
end
|
536
523
|
else
|
537
524
|
@current_pos = s0
|
538
525
|
s0 = :failed
|
539
526
|
end
|
540
|
-
else
|
541
|
-
@current_pos = s0
|
542
|
-
s0 = :failed
|
543
527
|
end
|
544
528
|
s0
|
545
529
|
end
|
@@ -606,7 +590,7 @@ module Jkf::Parser
|
|
606
590
|
|
607
591
|
# teban to color
|
608
592
|
def teban2color(teban)
|
609
|
-
teban = teban.to_i unless teban.is_a?
|
593
|
+
teban = teban.to_i unless teban.is_a? Integer
|
610
594
|
(teban + 1) % 2
|
611
595
|
end
|
612
596
|
|