sportdb-parser 0.6.4 → 0.6.5
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 +4 -4
- data/CHANGELOG.md +1 -1
- data/lib/sportdb/parser/lexer.rb +59 -12
- data/lib/sportdb/parser/parser.rb +630 -461
- data/lib/sportdb/parser/racc_tree.rb +38 -3
- data/lib/sportdb/parser/token-prop.rb +40 -0
- data/lib/sportdb/parser/token.rb +8 -0
- data/lib/sportdb/parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cb697dbecb7802a9701c60527bb67125dc7ac550b6c5c80f67044e51683eb15
|
4
|
+
data.tar.gz: d53cc9c126b93a4702b2c633daf863a3e4d4b63397f7c5ac60bd0646ab1d2da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 341aa9f1b25259db42452f28bd69f5643ecb5a3b45755a88565aac2b7a2842bc34d8d2a53e7d3b7a4b96c15c199c000167f4e94e608486a4ae9fefa9756bc7a0
|
7
|
+
data.tar.gz: d983116b79d9f361e136ef989ac02041ea735cfda42614f0ff08f5fd43899d7deebc135a82c020ff6dc7c9c6cf6ee413bbff7cdc9f65e41a682b3bf5cb5b082f
|
data/CHANGELOG.md
CHANGED
data/lib/sportdb/parser/lexer.rb
CHANGED
@@ -327,9 +327,27 @@ def _tokenize_line( line )
|
|
327
327
|
if m
|
328
328
|
### switch into new mode
|
329
329
|
## switch context to PROP_RE
|
330
|
-
@re = PROP_RE
|
331
330
|
puts " ENTER PROP_RE MODE" if debug?
|
332
|
-
|
331
|
+
key = m[:key]
|
332
|
+
|
333
|
+
|
334
|
+
### todo - add prop yellow/red cards too - why? why not?
|
335
|
+
if ['sent off', 'red cards'].include?( key.downcase)
|
336
|
+
@re = PROP_CARDS_RE ## use CARDS_RE ???
|
337
|
+
tokens << [:PROP_REDCARDS, m[:key]]
|
338
|
+
elsif ['yellow cards'].include?( key.downcase )
|
339
|
+
@re = PROP_CARDS_RE
|
340
|
+
tokens << [:PROP_YELLOWCARDS, m[:key]]
|
341
|
+
elsif ['ref', 'referee'].include?( key.downcase )
|
342
|
+
@re = PROP_RE ## (re)use prop setup for now - why? why not?
|
343
|
+
tokens << [:PROP_REFEREE, m[:key]]
|
344
|
+
elsif ['goals'].include?( key.downcase )
|
345
|
+
@re = PROP_GOAL_RE
|
346
|
+
tokens << [:PROP_GOALS, m[:key]]
|
347
|
+
else ## assume (team) line-up
|
348
|
+
@re = PROP_RE ## use LINEUP_RE ???
|
349
|
+
tokens << [:PROP, m[:key]]
|
350
|
+
end
|
333
351
|
|
334
352
|
offsets = [m.begin(0), m.end(0)]
|
335
353
|
pos = offsets[1] ## update pos
|
@@ -420,10 +438,44 @@ def _tokenize_line( line )
|
|
420
438
|
## note: racc requires pairs e.g. [:TOKEN, VAL]
|
421
439
|
## for VAL use "text" or ["text", { opts }] array
|
422
440
|
|
423
|
-
|
424
|
-
|
441
|
+
t = if @re == PROP_CARDS_RE
|
442
|
+
if m[:space] || m[:spaces]
|
443
|
+
nil ## skip space(s)
|
444
|
+
elsif m[:prop_name]
|
445
|
+
[:PROP_NAME, m[:name]]
|
446
|
+
elsif m[:minute]
|
447
|
+
minute = {}
|
448
|
+
minute[:m] = m[:value].to_i(10)
|
449
|
+
minute[:offset] = m[:value2].to_i(10) if m[:value2]
|
450
|
+
## note - for debugging keep (pass along) "literal" minute
|
451
|
+
[:MINUTE, [m[:minute], minute]]
|
452
|
+
elsif m[:sym]
|
453
|
+
sym = m[:sym]
|
454
|
+
case sym
|
455
|
+
when ',' then [:',']
|
456
|
+
when ';' then [:';']
|
457
|
+
when '-' then [:'-']
|
458
|
+
else
|
459
|
+
nil ## ignore others (e.g. brackets [])
|
460
|
+
end
|
461
|
+
else
|
462
|
+
## report error
|
463
|
+
puts "!!! TOKENIZE ERROR (PROP_CARDS_RE) - no match found"
|
464
|
+
nil
|
465
|
+
end
|
466
|
+
elsif @re == PROP_RE ### todo/fix - change to LINEUP_RE !!!!
|
425
467
|
if m[:space] || m[:spaces]
|
426
468
|
nil ## skip space(s)
|
469
|
+
elsif m[:prop_key] ## check for inline prop keys
|
470
|
+
key = m[:key]
|
471
|
+
## supported for now coach/trainer (add manager?)
|
472
|
+
if ['coach',
|
473
|
+
'trainer'].include?( key.downcase )
|
474
|
+
[:COACH, m[:key]] ## use COACH_KEY or such - why? why not?
|
475
|
+
else
|
476
|
+
## report error - for unknown (inline) prop key in lineup
|
477
|
+
nil
|
478
|
+
end
|
427
479
|
elsif m[:prop_name]
|
428
480
|
if m[:name] == 'Y'
|
429
481
|
[:YELLOW_CARD, m[:name]]
|
@@ -451,11 +503,6 @@ def _tokenize_line( line )
|
|
451
503
|
when '(' then [:'(']
|
452
504
|
when ')' then [:')']
|
453
505
|
when '-' then [:'-']
|
454
|
-
# when '.' then
|
455
|
-
# ## switch back to top-level mode!!
|
456
|
-
# puts " LEAVE PROP_RE MODE, BACK TO TOP_LEVEL/RE" if debug?
|
457
|
-
# @re = RE
|
458
|
-
# [:'.']
|
459
506
|
else
|
460
507
|
nil ## ignore others (e.g. brackets [])
|
461
508
|
end
|
@@ -464,7 +511,7 @@ def _tokenize_line( line )
|
|
464
511
|
puts "!!! TOKENIZE ERROR (PROP_RE) - no match found"
|
465
512
|
nil
|
466
513
|
end
|
467
|
-
elsif @re == GOAL_RE
|
514
|
+
elsif @re == GOAL_RE || @re == PROP_GOAL_RE
|
468
515
|
if m[:space] || m[:spaces]
|
469
516
|
nil ## skip space(s)
|
470
517
|
elsif m[:prop_name] ## note - change prop_name to player
|
@@ -663,8 +710,8 @@ def _tokenize_line( line )
|
|
663
710
|
##
|
664
711
|
## if in prop mode continue if last token is [,-]
|
665
712
|
## otherwise change back to "standard" mode
|
666
|
-
if @re == PROP_RE
|
667
|
-
if [:',', :'-'].include?( tokens[-1][0] )
|
713
|
+
if @re == PROP_RE || @re == PROP_CARDS_RE || @re == PROP_GOAL_RE
|
714
|
+
if [:',', :'-', :';'].include?( tokens[-1][0] )
|
668
715
|
## continue/stay in PROP_RE mode
|
669
716
|
## todo/check - auto-add PROP_CONT token or such
|
670
717
|
## to help parser with possible NEWLINE
|