jkf 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/ki2.rb
CHANGED
@@ -16,7 +16,10 @@ module Jkf::Parser
|
|
16
16
|
s1 << s2
|
17
17
|
s2 = parse_header
|
18
18
|
end
|
19
|
-
if s1
|
19
|
+
if s1 == :failed
|
20
|
+
@current_pos = s0
|
21
|
+
s0 = :failed
|
22
|
+
else
|
20
23
|
s2 = parse_initialboard
|
21
24
|
s2 = nil if s2 == :failed
|
22
25
|
s3 = []
|
@@ -26,7 +29,10 @@ module Jkf::Parser
|
|
26
29
|
s4 = parse_header
|
27
30
|
end
|
28
31
|
s4 = parse_moves
|
29
|
-
if s4
|
32
|
+
if s4 == :failed
|
33
|
+
@current_pos = s0
|
34
|
+
s0 = :failed
|
35
|
+
else
|
30
36
|
s5 = []
|
31
37
|
s6 = parse_fork
|
32
38
|
while s6 != :failed
|
@@ -35,13 +41,7 @@ module Jkf::Parser
|
|
35
41
|
end
|
36
42
|
@reported_pos = s0
|
37
43
|
s0 = transform_root(s1, s2, s3, s4, s5)
|
38
|
-
else
|
39
|
-
@current_pos = s0
|
40
|
-
s0 = :failed
|
41
44
|
end
|
42
|
-
else
|
43
|
-
@current_pos = s0
|
44
|
-
s0 = :failed
|
45
45
|
end
|
46
46
|
s0
|
47
47
|
end
|
@@ -50,38 +50,36 @@ module Jkf::Parser
|
|
50
50
|
def parse_header
|
51
51
|
s0 = @current_pos
|
52
52
|
s2 = match_regexp(/^[^*:\r\n]/)
|
53
|
-
if s2
|
53
|
+
if s2 == :failed
|
54
|
+
s1 = :failed
|
55
|
+
else
|
54
56
|
s1 = []
|
55
57
|
while s2 != :failed
|
56
58
|
s1 << s2
|
57
59
|
s2 = match_regexp(/^[^:\r\n]/)
|
58
60
|
end
|
59
|
-
else
|
60
|
-
s1 = :failed
|
61
61
|
end
|
62
|
-
if s1
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
s5 = parse_nl
|
71
|
-
end
|
72
|
-
else
|
73
|
-
s4 = :failed
|
74
|
-
end
|
75
|
-
if s4 != :failed
|
76
|
-
@reported_pos = s0
|
77
|
-
s0 = { "k" => s1.join, "v" => s3.join }
|
78
|
-
else
|
79
|
-
@current_pos = s0
|
80
|
-
s0 = :failed
|
81
|
-
end
|
62
|
+
if s1 == :failed
|
63
|
+
@current_pos = s0
|
64
|
+
s0 = :failed
|
65
|
+
elsif match_str(":") != :failed
|
66
|
+
s3 = parse_nonls
|
67
|
+
s5 = parse_nl
|
68
|
+
if s5 == :failed
|
69
|
+
s4 = :failed
|
82
70
|
else
|
71
|
+
s4 = []
|
72
|
+
while s5 != :failed
|
73
|
+
s4 << s5
|
74
|
+
s5 = parse_nl
|
75
|
+
end
|
76
|
+
end
|
77
|
+
if s4 == :failed
|
83
78
|
@current_pos = s0
|
84
79
|
s0 = :failed
|
80
|
+
else
|
81
|
+
@reported_pos = s0
|
82
|
+
s0 = { "k" => s1.join, "v" => s3.join }
|
85
83
|
end
|
86
84
|
else
|
87
85
|
@current_pos = s0
|
@@ -95,24 +93,24 @@ module Jkf::Parser
|
|
95
93
|
def parse_header_teban
|
96
94
|
s0 = @current_pos
|
97
95
|
s1 = parse_turn
|
98
|
-
if s1
|
96
|
+
if s1 == :failed
|
97
|
+
@current_pos = s0
|
98
|
+
:failed
|
99
|
+
else
|
99
100
|
s2 = match_str("手番")
|
100
|
-
if s2
|
101
|
+
if s2 == :failed
|
102
|
+
@current_pos = s0
|
103
|
+
:failed
|
104
|
+
else
|
101
105
|
s3 = parse_nl
|
102
|
-
if s3
|
103
|
-
@reported_pos = s0
|
104
|
-
{ "k" => "手番", "v" => s1 }
|
105
|
-
else
|
106
|
+
if s3 == :failed
|
106
107
|
@current_pos = s0
|
107
108
|
:failed
|
109
|
+
else
|
110
|
+
@reported_pos = s0
|
111
|
+
{ "k" => "手番", "v" => s1 }
|
108
112
|
end
|
109
|
-
else
|
110
|
-
@current_pos = s0
|
111
|
-
:failed
|
112
113
|
end
|
113
|
-
else
|
114
|
-
@current_pos = s0
|
115
|
-
:failed
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
@@ -120,7 +118,10 @@ module Jkf::Parser
|
|
120
118
|
def parse_moves
|
121
119
|
s0 = @current_pos
|
122
120
|
s1 = parse_firstboard
|
123
|
-
if s1
|
121
|
+
if s1 == :failed
|
122
|
+
@current_pos = s0
|
123
|
+
s0 = :failed
|
124
|
+
else
|
124
125
|
s2 = []
|
125
126
|
s3 = parse_move
|
126
127
|
while s3 != :failed
|
@@ -135,9 +136,6 @@ module Jkf::Parser
|
|
135
136
|
tl << { "special" => res } if res && !tl[tl.length - 1]["special"]
|
136
137
|
tl
|
137
138
|
end.call(s1, s2, s3)
|
138
|
-
else
|
139
|
-
@current_pos = s0
|
140
|
-
s0 = :failed
|
141
139
|
end
|
142
140
|
s0
|
143
141
|
end
|
@@ -161,7 +159,10 @@ module Jkf::Parser
|
|
161
159
|
def parse_move
|
162
160
|
s0 = @current_pos
|
163
161
|
s1 = parse_line
|
164
|
-
if s1
|
162
|
+
if s1 == :failed
|
163
|
+
@current_pos = s0
|
164
|
+
s0 = :failed
|
165
|
+
else
|
165
166
|
s2 = []
|
166
167
|
s3 = parse_comment
|
167
168
|
while s3 != :failed
|
@@ -183,9 +184,6 @@ module Jkf::Parser
|
|
183
184
|
ret["comments"] = c if !c.empty?
|
184
185
|
ret
|
185
186
|
end.call(s1, s2)
|
186
|
-
else
|
187
|
-
@current_pos = s0
|
188
|
-
s0 = :failed
|
189
187
|
end
|
190
188
|
|
191
189
|
s0
|
@@ -195,14 +193,20 @@ module Jkf::Parser
|
|
195
193
|
def parse_line
|
196
194
|
s0 = @current_pos
|
197
195
|
s1 = match_regexp(/^[▲△]/)
|
198
|
-
if s1
|
196
|
+
if s1 == :failed
|
197
|
+
@current_pos = s0
|
198
|
+
s0 = :failed
|
199
|
+
else
|
199
200
|
s1 = if s1 == "▲"
|
200
201
|
{ "color" => 0 }
|
201
202
|
else
|
202
203
|
{ "color" => 1 }
|
203
204
|
end
|
204
205
|
s2 = parse_fugou
|
205
|
-
if s2
|
206
|
+
if s2 == :failed
|
207
|
+
@current_pos = s0
|
208
|
+
s0 = :failed
|
209
|
+
else
|
206
210
|
s3 = []
|
207
211
|
s4 = parse_nl
|
208
212
|
s4 = match_space if s4 == :failed
|
@@ -213,13 +217,7 @@ module Jkf::Parser
|
|
213
217
|
end
|
214
218
|
@reported_pos = s0
|
215
219
|
s0 = s2.merge(s1)
|
216
|
-
else
|
217
|
-
@current_pos = s0
|
218
|
-
s0 = :failed
|
219
220
|
end
|
220
|
-
else
|
221
|
-
@current_pos = s0
|
222
|
-
s0 = :failed
|
223
221
|
end
|
224
222
|
s0
|
225
223
|
end
|
@@ -228,9 +226,15 @@ module Jkf::Parser
|
|
228
226
|
def parse_fugou
|
229
227
|
s0 = @current_pos
|
230
228
|
s1 = parse_place
|
231
|
-
if s1
|
229
|
+
if s1 == :failed
|
230
|
+
@current_pos = s0
|
231
|
+
:failed
|
232
|
+
else
|
232
233
|
s2 = parse_piece
|
233
|
-
if s2
|
234
|
+
if s2 == :failed
|
235
|
+
@current_pos = s0
|
236
|
+
:failed
|
237
|
+
else
|
234
238
|
s3 = parse_soutai
|
235
239
|
s3 = nil if s3 == :failed
|
236
240
|
s4 = parse_dousa
|
@@ -242,13 +246,7 @@ module Jkf::Parser
|
|
242
246
|
s6 = nil if s6 == :failed
|
243
247
|
@reported_pos = s0
|
244
248
|
transform_fugou(s1, s2, s3, s4, s5, s6)
|
245
|
-
else
|
246
|
-
@current_pos = s0
|
247
|
-
:failed
|
248
249
|
end
|
249
|
-
else
|
250
|
-
@current_pos = s0
|
251
|
-
:failed
|
252
250
|
end
|
253
251
|
end
|
254
252
|
|
@@ -256,28 +254,28 @@ module Jkf::Parser
|
|
256
254
|
def parse_place
|
257
255
|
s0 = @current_pos
|
258
256
|
s1 = parse_num
|
259
|
-
if s1
|
257
|
+
if s1 == :failed
|
258
|
+
@current_pos = s0
|
259
|
+
s0 = :failed
|
260
|
+
else
|
260
261
|
s2 = parse_numkan
|
261
|
-
if s2
|
262
|
-
@reported_pos = s0
|
263
|
-
s0 = { "x" => s1, "y" => s2 }
|
264
|
-
else
|
262
|
+
if s2 == :failed
|
265
263
|
@current_pos = s0
|
266
264
|
s0 = :failed
|
265
|
+
else
|
266
|
+
@reported_pos = s0
|
267
|
+
s0 = { "x" => s1, "y" => s2 }
|
267
268
|
end
|
268
|
-
else
|
269
|
-
@current_pos = s0
|
270
|
-
s0 = :failed
|
271
269
|
end
|
272
270
|
if s0 == :failed
|
273
271
|
s0 = @current_pos
|
274
|
-
if match_regexp("同")
|
272
|
+
if match_regexp("同") == :failed
|
273
|
+
@current_pos = s0
|
274
|
+
s0 = :failed
|
275
|
+
else
|
275
276
|
match_str(" ")
|
276
277
|
@reported_pos = s0
|
277
278
|
s0 = { "same" => true }
|
278
|
-
else
|
279
|
-
@current_pos = s0
|
280
|
-
s0 = :failed
|
281
279
|
end
|
282
280
|
end
|
283
281
|
s0
|
@@ -296,18 +294,18 @@ module Jkf::Parser
|
|
296
294
|
# "*" nonls nl
|
297
295
|
def parse_comment
|
298
296
|
s0 = @current_pos
|
299
|
-
if match_str("*")
|
297
|
+
if match_str("*") == :failed
|
298
|
+
@current_pos = s0
|
299
|
+
s0 = :failed
|
300
|
+
else
|
300
301
|
s2 = parse_nonls
|
301
|
-
if parse_nl
|
302
|
-
@reported_pos = s0
|
303
|
-
s0 = s2.join
|
304
|
-
else
|
302
|
+
if parse_nl == :failed
|
305
303
|
@current_pos = s0
|
306
304
|
s0 = :failed
|
305
|
+
else
|
306
|
+
@reported_pos = s0
|
307
|
+
s0 = s2.join
|
307
308
|
end
|
308
|
-
else
|
309
|
-
@current_pos = s0
|
310
|
-
s0 = :failed
|
311
309
|
end
|
312
310
|
s0
|
313
311
|
end
|
@@ -315,35 +313,33 @@ module Jkf::Parser
|
|
315
313
|
# fork : "変化:" " "* [0-9]+ "手" nl moves
|
316
314
|
def parse_fork
|
317
315
|
s0 = @current_pos
|
318
|
-
if match_str("変化:")
|
316
|
+
if match_str("変化:") == :failed
|
317
|
+
@current_pos = s0
|
318
|
+
s0 = :failed
|
319
|
+
else
|
319
320
|
match_spaces
|
320
321
|
s3 = match_digits!
|
321
|
-
if s3
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
end
|
332
|
-
else
|
322
|
+
if s3 == :failed
|
323
|
+
@current_pos = s0
|
324
|
+
s0 = :failed
|
325
|
+
elsif match_str("手") != :failed
|
326
|
+
if parse_nl == :failed
|
327
|
+
@current_pos = s0
|
328
|
+
s0 = :failed
|
329
|
+
else
|
330
|
+
s6 = parse_moves
|
331
|
+
if s6 == :failed
|
333
332
|
@current_pos = s0
|
334
333
|
s0 = :failed
|
334
|
+
else
|
335
|
+
@reported_pos = s0
|
336
|
+
s0 = { "te" => s3.join.to_i, "moves" => s6[1..-1] }
|
335
337
|
end
|
336
|
-
else
|
337
|
-
@current_pos = s0
|
338
|
-
s0 = :failed
|
339
338
|
end
|
340
339
|
else
|
341
340
|
@current_pos = s0
|
342
341
|
s0 = :failed
|
343
342
|
end
|
344
|
-
else
|
345
|
-
@current_pos = s0
|
346
|
-
s0 = :failed
|
347
343
|
end
|
348
344
|
s0
|
349
345
|
end
|