sportdb-parser 0.6.20 → 0.7.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Manifest.txt +15 -8
  4. data/Rakefile +1 -2
  5. data/lib/sportdb/parser/blocktxt.rb +99 -0
  6. data/lib/sportdb/parser/lexer.rb +958 -395
  7. data/lib/sportdb/parser/lexer_buffer.rb +97 -0
  8. data/lib/sportdb/parser/lexer_tty.rb +111 -0
  9. data/lib/sportdb/parser/parser.rb +1772 -857
  10. data/lib/sportdb/parser/parser_runtime.rb +379 -0
  11. data/lib/sportdb/parser/racc_parser.rb +1 -1
  12. data/lib/sportdb/parser/racc_tree.rb +327 -41
  13. data/lib/sportdb/parser/token-date.rb +160 -178
  14. data/lib/sportdb/parser/token-date_duration.rb +190 -0
  15. data/lib/sportdb/parser/token-geo.rb +59 -59
  16. data/lib/sportdb/parser/token-goals.rb +460 -0
  17. data/lib/sportdb/parser/token-group.rb +43 -0
  18. data/lib/sportdb/parser/token-note.rb +40 -0
  19. data/lib/sportdb/parser/token-prop.rb +70 -54
  20. data/lib/sportdb/parser/token-prop_name.rb +74 -0
  21. data/lib/sportdb/parser/token-round.rb +102 -0
  22. data/lib/sportdb/parser/token-score.rb +323 -47
  23. data/lib/sportdb/parser/token-score_fuller.rb +435 -0
  24. data/lib/sportdb/parser/token-score_legs.rb +59 -0
  25. data/lib/sportdb/parser/token-status.rb +157 -160
  26. data/lib/sportdb/parser/token-table.rb +149 -0
  27. data/lib/sportdb/parser/token-text.rb +72 -23
  28. data/lib/sportdb/parser/token-time.rb +141 -0
  29. data/lib/sportdb/parser/token.rb +242 -105
  30. data/lib/sportdb/parser/token_helpers.rb +92 -0
  31. data/lib/sportdb/parser/version.rb +2 -2
  32. data/lib/sportdb/parser.rb +29 -4
  33. metadata +19 -32
  34. data/config/rounds_de.txt +0 -125
  35. data/config/rounds_en.txt +0 -29
  36. data/config/rounds_es.txt +0 -26
  37. data/config/rounds_misc.txt +0 -25
  38. data/config/rounds_pt.txt +0 -4
  39. data/config/zones_en.txt +0 -20
  40. data/lib/sportdb/parser/lang.rb +0 -298
  41. data/lib/sportdb/parser/token-minute.rb +0 -205
@@ -0,0 +1,379 @@
1
+
2
+ # frozen_string_literal: true
3
+ #--
4
+ # Copyright (c) 1999-2006 Minero Aoki
5
+ #
6
+ # This program is free software.
7
+ # You can distribute/modify this program under the same terms of ruby.
8
+ #
9
+ # As a special exception, when this code is copied by Racc
10
+ # into a Racc output file, you may use that output file
11
+ # without restriction.
12
+ #++
13
+
14
+
15
+ module Racc
16
+ class ParseError < StandardError; end
17
+ end
18
+ unless defined?(::ParseError)
19
+ ParseError = Racc::ParseError # :nodoc:
20
+ end
21
+
22
+
23
+
24
+ module Racc
25
+ VERSION = '1.8.1'
26
+ Version = VERSION
27
+
28
+
29
+ class Parser
30
+ def _racc_setup
31
+ @yydebug = false unless self.class::Racc_debug_parser
32
+ @yydebug = false unless defined?(@yydebug)
33
+ if @yydebug
34
+ @racc_debug_out = $stderr unless defined?(@racc_debug_out)
35
+ @racc_debug_out ||= $stderr
36
+ end
37
+ arg = self.class::Racc_arg
38
+ arg[13] = true if arg.size < 14
39
+ arg
40
+ end
41
+
42
+ def _racc_init_sysvars
43
+ @racc_state = [0]
44
+ @racc_tstack = []
45
+ @racc_vstack = []
46
+
47
+ @racc_t = nil
48
+ @racc_val = nil
49
+
50
+ @racc_read_next = true
51
+
52
+ @racc_user_yyerror = false
53
+ @racc_error_status = 0
54
+ end
55
+
56
+ # The entry point of the parser. This method is used with #next_token.
57
+ # If Racc wants to get token (and its value), calls next_token.
58
+ #
59
+ # Example:
60
+ # def parse
61
+ # @q = [[1,1],
62
+ # [2,2],
63
+ # [3,3],
64
+ # [false, '$']]
65
+ # do_parse
66
+ # end
67
+ #
68
+ # def next_token
69
+ # @q.shift
70
+ # end
71
+ def do_parse
72
+ _racc_do_parse_rb(_racc_setup(), false)
73
+ end
74
+
75
+ # The method to fetch next token.
76
+ # If you use #do_parse method, you must implement #next_token.
77
+ #
78
+ # The format of return value is [TOKEN_SYMBOL, VALUE].
79
+ # +token-symbol+ is represented by Ruby's symbol by default, e.g. :IDENT
80
+ # for 'IDENT'. ";" (String) for ';'.
81
+ #
82
+ # The final symbol (End of file) must be false.
83
+ def next_token
84
+ raise NotImplementedError, "#{self.class}\#next_token is not defined"
85
+ end
86
+
87
+ def _racc_do_parse_rb(arg, in_debug)
88
+ action_table, action_check, action_default, action_pointer,
89
+ _, _, _, _,
90
+ _, _, token_table, * = arg
91
+
92
+ _racc_init_sysvars
93
+ tok = act = i = nil
94
+
95
+ catch(:racc_end_parse) {
96
+ while true
97
+ if i = action_pointer[@racc_state[-1]]
98
+ if @racc_read_next
99
+ if @racc_t != 0 # not EOF
100
+ tok, @racc_val = next_token()
101
+ unless tok # EOF
102
+ @racc_t = 0
103
+ else
104
+ @racc_t = (token_table[tok] or 1) # error token
105
+ end
106
+ racc_read_token(@racc_t, tok, @racc_val) if @yydebug
107
+ @racc_read_next = false
108
+ end
109
+ end
110
+ i += @racc_t
111
+ unless i >= 0 and
112
+ act = action_table[i] and
113
+ action_check[i] == @racc_state[-1]
114
+ act = action_default[@racc_state[-1]]
115
+ end
116
+ else
117
+ act = action_default[@racc_state[-1]]
118
+ end
119
+ while act = _racc_evalact(act, arg)
120
+ ;
121
+ end
122
+ end
123
+ }
124
+ end
125
+
126
+
127
+
128
+ ###
129
+ ### common
130
+ ###
131
+
132
+ def _racc_evalact(act, arg)
133
+ action_table, action_check, _, action_pointer,
134
+ _, _, _, _,
135
+ _, _, _, shift_n,
136
+ reduce_n, * = arg
137
+ nerr = 0 # tmp
138
+
139
+ if act > 0 and act < shift_n
140
+ #
141
+ # shift
142
+ #
143
+ if @racc_error_status > 0
144
+ @racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF
145
+ end
146
+ @racc_vstack.push @racc_val
147
+ @racc_state.push act
148
+ @racc_read_next = true
149
+ if @yydebug
150
+ @racc_tstack.push @racc_t
151
+ racc_shift @racc_t, @racc_tstack, @racc_vstack
152
+ end
153
+
154
+ elsif act < 0 and act > -reduce_n
155
+ #
156
+ # reduce
157
+ #
158
+ code = catch(:racc_jump) {
159
+ @racc_state.push _racc_do_reduce(arg, act)
160
+ false
161
+ }
162
+ if code
163
+ case code
164
+ when 1 # yyerror
165
+ @racc_user_yyerror = true # user_yyerror
166
+ return -reduce_n
167
+ when 2 # yyaccept
168
+ return shift_n
169
+ else
170
+ raise '[Racc Bug] unknown jump code'
171
+ end
172
+ end
173
+
174
+ elsif act == shift_n
175
+ #
176
+ # accept
177
+ #
178
+ racc_accept if @yydebug
179
+ throw :racc_end_parse, @racc_vstack[0]
180
+
181
+ elsif act == -reduce_n
182
+ #
183
+ # error
184
+ #
185
+ case @racc_error_status
186
+ when 0
187
+ unless arg[21] # user_yyerror
188
+ nerr += 1
189
+ on_error @racc_t, @racc_val, @racc_vstack
190
+ end
191
+ when 3
192
+ if @racc_t == 0 # is $
193
+ # We're at EOF, and another error occurred immediately after
194
+ # attempting auto-recovery
195
+ throw :racc_end_parse, nil
196
+ end
197
+ @racc_read_next = true
198
+ end
199
+ @racc_user_yyerror = false
200
+ @racc_error_status = 3
201
+ while true
202
+ if i = action_pointer[@racc_state[-1]]
203
+ i += 1 # error token
204
+ if i >= 0 and
205
+ (act = action_table[i]) and
206
+ action_check[i] == @racc_state[-1]
207
+ break
208
+ end
209
+ end
210
+ throw :racc_end_parse, nil if @racc_state.size <= 1
211
+ @racc_state.pop
212
+ @racc_vstack.pop
213
+ if @yydebug
214
+ @racc_tstack.pop
215
+ racc_e_pop @racc_state, @racc_tstack, @racc_vstack
216
+ end
217
+ end
218
+ return act
219
+
220
+ else
221
+ raise "[Racc Bug] unknown action #{act.inspect}"
222
+ end
223
+
224
+ racc_next_state(@racc_state[-1], @racc_state) if @yydebug
225
+
226
+ nil
227
+ end
228
+
229
+ def _racc_do_reduce(arg, act)
230
+ _, _, _, _,
231
+ goto_table, goto_check, goto_default, goto_pointer,
232
+ nt_base, reduce_table, _, _,
233
+ _, use_result, * = arg
234
+
235
+ state = @racc_state
236
+ vstack = @racc_vstack
237
+ tstack = @racc_tstack
238
+
239
+ i = act * -3
240
+ len = reduce_table[i]
241
+ reduce_to = reduce_table[i+1]
242
+ method_id = reduce_table[i+2]
243
+ void_array = []
244
+
245
+ tmp_t = tstack[-len, len] if @yydebug
246
+ tmp_v = vstack[-len, len]
247
+ tstack[-len, len] = void_array if @yydebug
248
+ vstack[-len, len] = void_array
249
+ state[-len, len] = void_array
250
+
251
+ # tstack must be updated AFTER method call
252
+ if use_result
253
+ vstack.push __send__(method_id, tmp_v, vstack, tmp_v[0])
254
+ else
255
+ vstack.push __send__(method_id, tmp_v, vstack)
256
+ end
257
+ tstack.push reduce_to
258
+
259
+ racc_reduce(tmp_t, reduce_to, tstack, vstack) if @yydebug
260
+
261
+ k1 = reduce_to - nt_base
262
+ if i = goto_pointer[k1]
263
+ i += state[-1]
264
+ if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1
265
+ return curstate
266
+ end
267
+ end
268
+ goto_default[k1]
269
+ end
270
+
271
+ # This method is called when a parse error is found.
272
+ #
273
+ # ERROR_TOKEN_ID is an internal ID of token which caused error.
274
+ # You can get string representation of this ID by calling
275
+ # #token_to_str.
276
+ #
277
+ # ERROR_VALUE is a value of error token.
278
+ #
279
+ # value_stack is a stack of symbol values.
280
+ # DO NOT MODIFY this object.
281
+ #
282
+ # This method raises ParseError by default.
283
+ #
284
+ # If this method returns, parsers enter "error recovering mode".
285
+ def on_error(t, val, vstack)
286
+ raise ParseError, sprintf("parse error on value %s (%s)",
287
+ val.inspect, token_to_str(t) || '?')
288
+ end
289
+
290
+ # Enter error recovering mode.
291
+ # This method does not call #on_error.
292
+ def yyerror
293
+ throw :racc_jump, 1
294
+ end
295
+
296
+ # Exit parser.
297
+ # Return value is +Symbol_Value_Stack[0]+.
298
+ def yyaccept
299
+ throw :racc_jump, 2
300
+ end
301
+
302
+ # Leave error recovering mode.
303
+ def yyerrok
304
+ @racc_error_status = 0
305
+ end
306
+
307
+ # For debugging output
308
+ def racc_read_token(t, tok, val)
309
+ @racc_debug_out.print 'read '
310
+ @racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
311
+ @racc_debug_out.puts val.inspect
312
+ @racc_debug_out.puts
313
+ end
314
+
315
+ def racc_shift(tok, tstack, vstack)
316
+ @racc_debug_out.puts "shift #{racc_token2str tok}"
317
+ racc_print_stacks tstack, vstack
318
+ @racc_debug_out.puts
319
+ end
320
+
321
+ def racc_reduce(toks, sim, tstack, vstack)
322
+ out = @racc_debug_out
323
+ out.print 'reduce '
324
+ if toks.empty?
325
+ out.print ' <none>'
326
+ else
327
+ toks.each {|t| out.print ' ', racc_token2str(t) }
328
+ end
329
+ out.puts " --> #{racc_token2str(sim)}"
330
+ racc_print_stacks tstack, vstack
331
+ @racc_debug_out.puts
332
+ end
333
+
334
+ def racc_accept
335
+ @racc_debug_out.puts 'accept'
336
+ @racc_debug_out.puts
337
+ end
338
+
339
+ def racc_e_pop(state, tstack, vstack)
340
+ @racc_debug_out.puts 'error recovering mode: pop token'
341
+ racc_print_states state
342
+ racc_print_stacks tstack, vstack
343
+ @racc_debug_out.puts
344
+ end
345
+
346
+ def racc_next_state(curstate, state)
347
+ @racc_debug_out.puts "goto #{curstate}"
348
+ racc_print_states state
349
+ @racc_debug_out.puts
350
+ end
351
+
352
+ def racc_print_stacks(t, v)
353
+ out = @racc_debug_out
354
+ out.print ' ['
355
+ t.each_index do |i|
356
+ out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
357
+ end
358
+ out.puts ' ]'
359
+ end
360
+
361
+ def racc_print_states(s)
362
+ out = @racc_debug_out
363
+ out.print ' ['
364
+ s.each {|st| out.print ' ', st }
365
+ out.puts ' ]'
366
+ end
367
+
368
+ def racc_token2str(tok)
369
+ self.class::Racc_token_to_s_table[tok] or
370
+ raise "[Racc Bug] can't convert token #{tok} to string"
371
+ end
372
+
373
+ # Convert internal ID of token symbol to the string.
374
+ def token_to_str(t)
375
+ self.class::Racc_token_to_s_table[t]
376
+ end
377
+
378
+ end
379
+ end
@@ -30,7 +30,7 @@ def initialize( txt, debug: false )
30
30
  end
31
31
 
32
32
 
33
- def debug( value ) @debug = value; end
33
+ def debug( value ) @debug = value; end ### fix: use setter-style e.g. debug=(value) !!!
34
34
  def debug?() @debug == true; end
35
35
 
36
36
  ## debug - trace / print message