jkf 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,75 +6,74 @@ module Jkf::Parser
6
6
  # initialboard : (" " nonls nl)? ("+" nonls nl)? ikkatsuline+ ("+" nonls nl)?
7
7
  def parse_initialboard
8
8
  s0 = s1 = @current_pos
9
- if match_space != :failed
9
+ if match_space == :failed
10
+ @current_pos = s1
11
+ else
10
12
  parse_nonls
11
13
  s2 = parse_nl
12
14
  @current_pos = s1 if s2 == :failed
13
- else
14
- @current_pos = s1
15
15
  end
16
16
  s2 = @current_pos
17
- if match_str("+") != :failed
17
+ if match_str("+") == :failed
18
+ @current_pos = s2
19
+ else
18
20
  parse_nonls
19
21
  @current_pos = s2 if parse_nl == :failed
20
- else
21
- @current_pos = s2
22
22
  end
23
23
  s4 = parse_ikkatsuline
24
- if s4 != :failed
24
+ if s4 == :failed
25
+ s3 = :failed
26
+ else
25
27
  s3 = []
26
28
  while s4 != :failed
27
29
  s3 << s4
28
30
  s4 = parse_ikkatsuline
29
31
  end
30
- else
31
- s3 = :failed
32
32
  end
33
- if s3 != :failed
33
+ if s3 == :failed
34
+ @current_pos = s0
35
+ :failed
36
+ else
34
37
  s4 = @current_pos
35
- if match_str("+") != :failed
38
+ if match_str("+") == :failed
39
+ @current_pos = s4
40
+ else
36
41
  parse_nonls
37
42
  @current_pos = s4 if parse_nl == :failed
38
- else
39
- @current_pos = s4
40
43
  end
41
44
  @reported_pos = s0
42
45
  transform_initialboard(s3)
43
- else
44
- @current_pos = s0
45
- :failed
46
46
  end
47
47
  end
48
48
 
49
49
  # ikkatsuline : "|" masu:masu+ "|" nonls! nl
50
50
  def parse_ikkatsuline
51
51
  s0 = @current_pos
52
- if match_str("|") != :failed
52
+ if match_str("|") == :failed
53
+ @current_pos = s0
54
+ s0 = :failed
55
+ else
53
56
  s3 = parse_masu
54
- if s3 != :failed
57
+ if s3 == :failed
58
+ s2 = :failed
59
+ else
55
60
  s2 = []
56
61
  while s3 != :failed
57
62
  s2 << s3
58
63
  s3 = parse_masu
59
64
  end
60
- else
61
- s2 = :failed
62
65
  end
63
- if s2 != :failed
64
- if match_str("|") != :failed
65
- s4 = parse_nonls!
66
- if s4 != :failed
67
- if parse_nl != :failed
68
- @reported_pos = s0
69
- s0 = s2
70
- else
71
- @current_pos = s0
72
- s0 = :failed
73
- end
74
- else
75
- @current_pos = s0
76
- s0 = :failed
77
- end
66
+ if s2 == :failed
67
+ @current_pos = s0
68
+ s0 = :failed
69
+ elsif match_str("|") != :failed
70
+ s4 = parse_nonls!
71
+ if s4 == :failed
72
+ @current_pos = s0
73
+ s0 = :failed
74
+ elsif parse_nl != :failed
75
+ @reported_pos = s0
76
+ s0 = s2
78
77
  else
79
78
  @current_pos = s0
80
79
  s0 = :failed
@@ -83,9 +82,6 @@ module Jkf::Parser
83
82
  @current_pos = s0
84
83
  s0 = :failed
85
84
  end
86
- else
87
- @current_pos = s0
88
- s0 = :failed
89
85
  end
90
86
 
91
87
  s0
@@ -95,18 +91,18 @@ module Jkf::Parser
95
91
  def parse_masu
96
92
  s0 = @current_pos
97
93
  s1 = parse_teban
98
- if s1 != :failed
94
+ if s1 == :failed
95
+ @current_pos = s0
96
+ s0 = :failed
97
+ else
99
98
  s2 = parse_piece
100
- if s2 != :failed
101
- @reported_pos = s0
102
- s0 = { "color" => s1, "kind" => s2 }
103
- else
99
+ if s2 == :failed
104
100
  @current_pos = s0
105
101
  s0 = :failed
102
+ else
103
+ @reported_pos = s0
104
+ s0 = { "color" => s1, "kind" => s2 }
106
105
  end
107
- else
108
- @current_pos = s0
109
- s0 = :failed
110
106
  end
111
107
  if s0 == :failed
112
108
  s0 = @current_pos
@@ -151,18 +147,18 @@ module Jkf::Parser
151
147
  def parse_pointer
152
148
  s0 = @current_pos
153
149
  s1 = match_str("&")
154
- if s1 != :failed
150
+ if s1 == :failed
151
+ @current_pos = s0
152
+ s0 = :failed
153
+ else
155
154
  s2 = parse_nonls
156
155
  s3 = parse_nl
157
- if s3 != :failed
158
- s0 = [s1, s2, s3]
159
- else
156
+ if s3 == :failed
160
157
  @current_pos = s0
161
158
  s0 = :failed
159
+ else
160
+ s0 = [s1, s2, s3]
162
161
  end
163
- else
164
- @current_pos = s0
165
- s0 = :failed
166
162
  end
167
163
  s0
168
164
  end
@@ -195,12 +191,12 @@ module Jkf::Parser
195
191
  s1 = match_str("成")
196
192
  s1 = "" if s1 == :failed
197
193
  s2 = match_regexp(/^[歩香桂銀金角飛王玉と杏圭全馬竜龍]/)
198
- if s2 != :failed
199
- @reported_pos = s0
200
- kind2csa(s1 + s2)
201
- else
194
+ if s2 == :failed
202
195
  @current_pos = s0
203
196
  :failed
197
+ else
198
+ @reported_pos = s0
199
+ kind2csa(s1 + s2)
204
200
  end
205
201
  end
206
202
 
@@ -211,63 +207,60 @@ module Jkf::Parser
211
207
  # ) nl
212
208
  def parse_result
213
209
  s0 = @current_pos
214
- if match_str("まで") != :failed
210
+ if match_str("まで") == :failed
211
+ @current_pos = s0
212
+ :failed
213
+ else
215
214
  s2 = match_digits!
216
- if s2 != :failed
217
- if match_str("手") != :failed
218
- s4 = @current_pos
219
- if match_str("") != :failed
220
- if parse_turn != :failed
221
- if match_str("手の") != :failed
222
- s8 = parse_result_toryo
223
- s8 = parse_result_illegal if s8 == :failed
224
- s4 = if s8 != :failed
225
- @reported_pos = s4
226
- s8
227
- else
228
- @current_pos = s4
229
- :failed
230
- end
231
- else
232
- @current_pos = s4
233
- s4 = :failed
234
- end
235
- else
236
- @current_pos = s4
237
- s4 = :failed
238
- end
239
- else
215
+ if s2 == :failed
216
+ @current_pos = s0
217
+ :failed
218
+ elsif match_str("") != :failed
219
+ s4 = @current_pos
220
+ if match_str("") == :failed
221
+ @current_pos = s4
222
+ s4 = :failed
223
+ elsif parse_turn != :failed
224
+ if match_str("手の") == :failed
240
225
  @current_pos = s4
241
226
  s4 = :failed
227
+ else
228
+ s8 = parse_result_toryo
229
+ s8 = parse_result_illegal if s8 == :failed
230
+ s4 = if s8 == :failed
231
+ @current_pos = s4
232
+ :failed
233
+ else
234
+ @reported_pos = s4
235
+ s8
236
+ end
242
237
  end
238
+ else
239
+ @current_pos = s4
240
+ s4 = :failed
241
+ end
242
+ if s4 == :failed
243
+ s4 = parse_result_timeup
243
244
  if s4 == :failed
244
- s4 = parse_result_timeup
245
+ s4 = parse_result_chudan
245
246
  if s4 == :failed
246
- s4 = parse_result_chudan
247
+ s4 = parse_result_jishogi
247
248
  if s4 == :failed
248
- s4 = parse_result_jishogi
249
+ s4 = parse_result_sennichite
249
250
  if s4 == :failed
250
- s4 = parse_result_sennichite
251
- if s4 == :failed
252
- s4 = parse_result_tsumi
253
- s4 = parse_result_fuzumi if s4 == :failed
254
- end
251
+ s4 = parse_result_tsumi
252
+ s4 = parse_result_fuzumi if s4 == :failed
255
253
  end
256
254
  end
257
255
  end
258
256
  end
259
- if s4 != :failed
260
- if parse_nl != :failed || eos?
261
- @reported_pos = s0
262
- s4
263
- else
264
- @current_pos = s0
265
- :failed
266
- end
267
- else
268
- @current_pos = s0
269
- :failed
270
- end
257
+ end
258
+ if s4 == :failed
259
+ @current_pos = s0
260
+ :failed
261
+ elsif parse_nl != :failed || eos?
262
+ @reported_pos = s0
263
+ s4
271
264
  else
272
265
  @current_pos = s0
273
266
  :failed
@@ -276,9 +269,6 @@ module Jkf::Parser
276
269
  @current_pos = s0
277
270
  :failed
278
271
  end
279
- else
280
- @current_pos = s0
281
- :failed
282
272
  end
283
273
  end
284
274
 
@@ -286,19 +276,22 @@ module Jkf::Parser
286
276
  def parse_result_toryo
287
277
  s0 = @current_pos
288
278
  s1 = match_str("勝ち")
289
- if s1 != :failed
290
- @reported_pos = s0
291
- "TORYO"
292
- else
279
+ if s1 == :failed
293
280
  @current_pos = s0
294
281
  :failed
282
+ else
283
+ @reported_pos = s0
284
+ "TORYO"
295
285
  end
296
286
  end
297
287
 
298
288
  # result_illegal : "反則" ("勝ち" | "負け")
299
289
  def parse_result_illegal
300
290
  s0 = @current_pos
301
- if match_str("反則") != :failed
291
+ if match_str("反則") == :failed
292
+ @current_pos = s0
293
+ :failed
294
+ else
302
295
  s10 = @current_pos
303
296
  s11 = match_str("勝ち")
304
297
  if s11 != :failed
@@ -315,34 +308,29 @@ module Jkf::Parser
315
308
  end
316
309
  s10 = s11
317
310
  end
318
- if s10 != :failed
319
- @reported_pos = s0
320
- s10
321
- else
311
+ if s10 == :failed
322
312
  @current_pos = s0
323
313
  :failed
314
+ else
315
+ @reported_pos = s0
316
+ s10
324
317
  end
325
- else
326
- @current_pos = s0
327
- :failed
328
318
  end
329
319
  end
330
320
 
331
321
  # result_timeup : "で時間切れにより" turn "手の勝ち"
332
322
  def parse_result_timeup
333
323
  s0 = @current_pos
334
- if match_str("で時間切れにより") != :failed
335
- if parse_turn != :failed
336
- if match_str("手の勝ち") != :failed
337
- @reported_pos = s0
338
- "TIME_UP"
339
- else
340
- @current_pos = s0
341
- :failed
342
- end
343
- else
324
+ if match_str("で時間切れにより") == :failed
325
+ @current_pos = s0
326
+ :failed
327
+ elsif parse_turn != :failed
328
+ if match_str("手の勝ち") == :failed
344
329
  @current_pos = s0
345
330
  :failed
331
+ else
332
+ @reported_pos = s0
333
+ "TIME_UP"
346
334
  end
347
335
  else
348
336
  @current_pos = s0
@@ -354,12 +342,12 @@ module Jkf::Parser
354
342
  def parse_result_chudan
355
343
  s0 = @current_pos
356
344
  s1 = match_str("で中断")
357
- if s1 != :failed
358
- @reported_pos = s0
359
- "CHUDAN"
360
- else
345
+ if s1 == :failed
361
346
  @current_pos = s0
362
347
  :failed
348
+ else
349
+ @reported_pos = s0
350
+ "CHUDAN"
363
351
  end
364
352
  end
365
353
 
@@ -367,12 +355,12 @@ module Jkf::Parser
367
355
  def parse_result_jishogi
368
356
  s0 = @current_pos
369
357
  s1 = match_str("で持将棋")
370
- if s1 != :failed
371
- @reported_pos = s0
372
- "JISHOGI"
373
- else
358
+ if s1 == :failed
374
359
  @current_pos = s0
375
360
  :failed
361
+ else
362
+ @reported_pos = s0
363
+ "JISHOGI"
376
364
  end
377
365
  end
378
366
 
@@ -380,12 +368,12 @@ module Jkf::Parser
380
368
  def parse_result_sennichite
381
369
  s0 = @current_pos
382
370
  s1 = match_str("で千日手")
383
- if s1 != :failed
384
- @reported_pos = s0
385
- "SENNICHITE"
386
- else
371
+ if s1 == :failed
387
372
  @current_pos = s0
388
373
  :failed
374
+ else
375
+ @reported_pos = s0
376
+ "SENNICHITE"
389
377
  end
390
378
  end
391
379
 
@@ -393,13 +381,13 @@ module Jkf::Parser
393
381
  def parse_result_tsumi
394
382
  s0 = @current_pos
395
383
  match_str("で")
396
- if match_str("詰") != :failed
384
+ if match_str("詰") == :failed
385
+ @current_pos = s0
386
+ :failed
387
+ else
397
388
  match_str("み")
398
389
  @reported_pos = s0
399
390
  "TSUMI"
400
- else
401
- @current_pos = s0
402
- :failed
403
391
  end
404
392
  end
405
393
 
@@ -407,12 +395,12 @@ module Jkf::Parser
407
395
  def parse_result_fuzumi
408
396
  s0 = @current_pos
409
397
  s1 = match_str("で不詰")
410
- if s1 != :failed
411
- @reported_pos = s0
412
- "FUZUMI"
413
- else
398
+ if s1 == :failed
414
399
  @current_pos = s0
415
400
  :failed
401
+ else
402
+ @reported_pos = s0
403
+ "FUZUMI"
416
404
  end
417
405
  end
418
406
 
@@ -420,18 +408,18 @@ module Jkf::Parser
420
408
  def parse_skipline
421
409
  s0 = @current_pos
422
410
  s1 = match_str("#")
423
- if s1 != :failed
411
+ if s1 == :failed
412
+ @current_pos = s0
413
+ s0 = :failed
414
+ else
424
415
  s2 = parse_nonls
425
416
  s3 = parse_newline
426
- s0 = if s3 != :failed
427
- [s1, s2, s3]
428
- else
417
+ s0 = if s3 == :failed
429
418
  @current_pos = s0
430
419
  :failed
420
+ else
421
+ [s1, s2, s3]
431
422
  end
432
- else
433
- @current_pos = s0
434
- s0 = :failed
435
423
  end
436
424
  s0
437
425
  end
@@ -454,20 +442,20 @@ module Jkf::Parser
454
442
  if s2 == :failed
455
443
  s2 = @current_pos
456
444
  s3 = match_str("\r")
457
- s2 = if s3 != :failed
445
+ s2 = if s3 == :failed
446
+ @current_pos = s2
447
+ :failed
448
+ else
458
449
  s4 = match_str("\n")
459
450
  s4 = nil if s4 == :failed
460
451
  [s3, s4]
461
- else
462
- @current_pos = s2
463
- :failed
464
452
  end
465
453
  end
466
- if s2 != :failed
467
- [s1, s2]
468
- else
454
+ if s2 == :failed
469
455
  @current_pos = s0
470
456
  :failed
457
+ else
458
+ [s1, s2]
471
459
  end
472
460
  end
473
461
 
@@ -475,16 +463,19 @@ module Jkf::Parser
475
463
  def parse_nl
476
464
  s0 = @current_pos
477
465
  s2 = parse_newline
478
- if s2 != :failed
466
+ if s2 == :failed
467
+ s1 = :failed
468
+ else
479
469
  s1 = []
480
470
  while s2 != :failed
481
471
  s1 << s2
482
472
  s2 = parse_newline
483
473
  end
484
- else
485
- s1 = :failed
486
474
  end
487
- if s1 != :failed
475
+ if s1 == :failed
476
+ @current_pos = s0
477
+ :failed
478
+ else
488
479
  s2 = []
489
480
  s3 = parse_skipline
490
481
  while s3 != :failed
@@ -492,9 +483,6 @@ module Jkf::Parser
492
483
  s3 = parse_skipline
493
484
  end
494
485
  [s1, s2]
495
- else
496
- @current_pos = s0
497
- :failed
498
486
  end
499
487
  end
500
488
 
data/lib/jkf/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Jkf
2
2
  # Gem version
3
- VERSION = "0.4.2".freeze
3
+ VERSION = "0.5.0".freeze
4
4
  end
data/manifest.scm ADDED
@@ -0,0 +1,142 @@
1
+ (use-modules ((guix licenses)
2
+ #:prefix license:)
3
+ (gnu packages ruby)
4
+ (guix build-system ruby)
5
+ (guix download)
6
+ (guix git)
7
+ (guix packages)
8
+ (guix git-download))
9
+
10
+ (define-public ruby-guard-rubocop
11
+ (package
12
+ (name "ruby-guard-rubocop")
13
+ (version "1.5.0")
14
+ (source (origin
15
+ (method url-fetch)
16
+ (uri (rubygems-uri "guard-rubocop" version))
17
+ (sha256
18
+ (base32
19
+ "0lb2fgfac97lvgwqvx2gbcimyvw2a0i76x6yabik3vmmvjbdfh9h"))))
20
+ (build-system ruby-build-system)
21
+ (arguments
22
+ `(#:tests? #f)) ;TODO
23
+ (propagated-inputs (list ruby-guard ruby-rubocop))
24
+ (synopsis
25
+ "Automatically checks Ruby code style with RuboCop when files are
26
+ modified")
27
+ (description
28
+ "@code{Guard::RuboCop} automatically checks Ruby code style with
29
+ RuboCop when files are modified.")
30
+ (home-page "https://github.com/rubocop/guard-rubocop")
31
+ (license license:expat)))
32
+
33
+ (define-public ruby-guard-compat
34
+ (package
35
+ (name "ruby-guard-compat")
36
+ (version "1.2.1")
37
+ (source (origin
38
+ (method url-fetch)
39
+ (uri (rubygems-uri "guard-compat" version))
40
+ (sha256
41
+ (base32
42
+ "1zj6sr1k8w59mmi27rsii0v8xyy2rnsi09nqvwpgj1q10yq1mlis"))))
43
+ (build-system ruby-build-system)
44
+ (arguments
45
+ `(#:test-target "spec"))
46
+ (native-inputs (list ruby-rspec ruby-rubocop))
47
+ (synopsis "Helps creating valid Guard plugins and testing them")
48
+ (description "guard-compat helps creating valid Guard plugins and testing them.")
49
+ (home-page "https://github.com/guard/guard-compat")
50
+ (license license:expat)))
51
+
52
+ (define-public ruby-ruby-dep
53
+ (package
54
+ (name "ruby-ruby-dep")
55
+ (version "1.5.0")
56
+ (source (origin
57
+ (method git-fetch)
58
+ (uri (git-reference
59
+ (url "https://github.com/e2/ruby_dep")
60
+ (commit "4e79416a55dff4b3ff50e73c8fbd0455de1e68b7")))
61
+ (file-name (git-file-name name version))
62
+ (sha256
63
+ (base32
64
+ "0vv2bm4lghh5pl8zi0ihp6hpbp7xlk8d5h888nhxr725in0ypy9x"))))
65
+ (build-system ruby-build-system)
66
+ (arguments
67
+ `(#:test-target "spec"
68
+ #:tests? #f ;FIXME: needs gem_isolator, but cyclic dependencies
69
+ ))
70
+ (native-inputs (list ruby-rspec))
71
+ (synopsis
72
+ "Creates a version constraint of supported Rubies, suitable for a
73
+ gemspec file")
74
+ (description
75
+ "This package creates a version constraint of supported Rubies,
76
+ suitable for a gemspec file.")
77
+ (home-page "https://github.com/e2/ruby_dep")
78
+ (license license:expat)))
79
+
80
+ (define-public ruby-gem-isolator
81
+ (package
82
+ (name "ruby-gem-isolator")
83
+ (version "0.2.3")
84
+ (source (origin
85
+ (method git-fetch)
86
+ (uri (git-reference
87
+ (url "https://github.com/e2/gem_isolator")
88
+ (commit "1ec35362d946e682089a3983e7063593231d5188")))
89
+ (file-name (git-file-name name version))
90
+ (sha256
91
+ (base32
92
+ "1kkg7y2lw2jpdcdw33f2pvz9q14rlnx29l3a2qcwc5smivd03kww"))))
93
+ (build-system ruby-build-system)
94
+ (arguments
95
+ `(#:test-target "spec"
96
+ #:tests? #f ;FIXME: uninitialized constant Pathname
97
+ ))
98
+ (native-inputs (list ruby-rspec ruby-nenv ruby-rubocop))
99
+ (propagated-inputs (list ruby-ruby-dep))
100
+ (synopsis
101
+ "Good for testing dependencies of a gem and/or different gem version
102
+ combinations")
103
+ (description
104
+ "gem_isolator is good for testing dependencies of a gem and/or
105
+ different gem version combinations.")
106
+ (home-page "https://github.com/e2/gem_isolator")
107
+ (license license:expat)))
108
+
109
+ (define-public ruby-guard-rspec
110
+ (package
111
+ (name "ruby-guard-rspec")
112
+ (version "4.7.3")
113
+ (source (origin
114
+ (method url-fetch)
115
+ (uri (rubygems-uri "guard-rspec" version))
116
+ (sha256
117
+ (base32
118
+ "1jkm5xp90gm4c5s51pmf92i9hc10gslwwic6mvk72g0yplya0yx4"))))
119
+ (build-system ruby-build-system)
120
+ (arguments
121
+ `(#:test-target "spec"
122
+ #:tests? #f ;FIXME: uninitialized constant Bundler
123
+ ))
124
+ (native-inputs (list ruby-rubocop ruby-launchy ruby-gem-isolator bundler ruby))
125
+ (propagated-inputs (list ruby-guard ruby-guard-compat ruby-rspec))
126
+ (synopsis "Automatically run your specs (much like autotest)")
127
+ (description
128
+ "@code{Guard::RSpec} automatically run your specs (much like autotest).")
129
+ (home-page "https://github.com/guard/guard-rspec")
130
+ (license license:expat)))
131
+
132
+ (packages->manifest (list ruby-rake
133
+ ruby-yard
134
+ ruby-redcarpet
135
+ ruby-rubocop
136
+ ruby-guard-rubocop
137
+ ruby-rubocop-rake
138
+ ruby-rubocop-rspec
139
+ ruby-rspec
140
+ ruby-guard-rspec
141
+ ruby-simplecov
142
+ ruby))