fbtxt-parser 0.9.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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/Manifest.txt +50 -0
  4. data/README.md +22 -0
  5. data/Rakefile +53 -0
  6. data/lib/fbtxt/parser/debuggable.rb +53 -0
  7. data/lib/fbtxt/parser/lexer-logger.rb +20 -0
  8. data/lib/fbtxt/parser/lexer-on_goal.rb +167 -0
  9. data/lib/fbtxt/parser/lexer-on_group_def.rb +31 -0
  10. data/lib/fbtxt/parser/lexer-on_prop_lineup.rb +79 -0
  11. data/lib/fbtxt/parser/lexer-on_prop_misc.rb +123 -0
  12. data/lib/fbtxt/parser/lexer-on_prop_penalties.rb +40 -0
  13. data/lib/fbtxt/parser/lexer-on_round_def.rb +37 -0
  14. data/lib/fbtxt/parser/lexer-on_top.rb +133 -0
  15. data/lib/fbtxt/parser/lexer-prep_doc.rb +131 -0
  16. data/lib/fbtxt/parser/lexer-prep_line.rb +63 -0
  17. data/lib/fbtxt/parser/lexer-tokenize.rb +468 -0
  18. data/lib/fbtxt/parser/lexer.rb +231 -0
  19. data/lib/fbtxt/parser/lexer_buffer.rb +68 -0
  20. data/lib/fbtxt/parser/lexer_token.rb +126 -0
  21. data/lib/fbtxt/parser/parse_tree--core.rb +29 -0
  22. data/lib/fbtxt/parser/parse_tree-match.rb +309 -0
  23. data/lib/fbtxt/parser/parse_tree-props.rb +233 -0
  24. data/lib/fbtxt/parser/parse_tree.rb +202 -0
  25. data/lib/fbtxt/parser/parser-runtime.rb +379 -0
  26. data/lib/fbtxt/parser/parser-top.rb +102 -0
  27. data/lib/fbtxt/parser/parser.rb +2343 -0
  28. data/lib/fbtxt/parser/token-date--helpers.rb +130 -0
  29. data/lib/fbtxt/parser/token-date--names.rb +108 -0
  30. data/lib/fbtxt/parser/token-date.rb +200 -0
  31. data/lib/fbtxt/parser/token-date_duration.rb +171 -0
  32. data/lib/fbtxt/parser/token-geo.rb +134 -0
  33. data/lib/fbtxt/parser/token-goals--helpers.rb +114 -0
  34. data/lib/fbtxt/parser/token-goals.rb +306 -0
  35. data/lib/fbtxt/parser/token-group.rb +29 -0
  36. data/lib/fbtxt/parser/token-note.rb +40 -0
  37. data/lib/fbtxt/parser/token-prop.rb +309 -0
  38. data/lib/fbtxt/parser/token-prop_name.rb +83 -0
  39. data/lib/fbtxt/parser/token-round.rb +88 -0
  40. data/lib/fbtxt/parser/token-score--helpers.rb +189 -0
  41. data/lib/fbtxt/parser/token-score.rb +60 -0
  42. data/lib/fbtxt/parser/token-score_full.rb +331 -0
  43. data/lib/fbtxt/parser/token-score_fuller.rb +434 -0
  44. data/lib/fbtxt/parser/token-score_legs.rb +59 -0
  45. data/lib/fbtxt/parser/token-status.rb +192 -0
  46. data/lib/fbtxt/parser/token-status_inline.rb +112 -0
  47. data/lib/fbtxt/parser/token-text.rb +221 -0
  48. data/lib/fbtxt/parser/token-time.rb +144 -0
  49. data/lib/fbtxt/parser/token.rb +224 -0
  50. data/lib/fbtxt/parser/version.rb +24 -0
  51. data/lib/fbtxt/parser.rb +140 -0
  52. metadata +145 -0
@@ -0,0 +1,60 @@
1
+ module Fbtxt
2
+ class Lexer
3
+
4
+
5
+ ###
6
+ ##
7
+ ## add support for score awarded (inline style)
8
+ ## 3-0 awd 3-0 awd. 3-0awd
9
+ ## 0-1 awd or 0-1 AWD etc.
10
+
11
+ ##
12
+ ## note - keep AWD w/o dot - why? why not?
13
+
14
+ SCORE_AWD_RE = %r{
15
+ (?<score_awd>
16
+ \b
17
+ (?<score1>\d{1,2}) - (?<score2>\d{1,2})
18
+ [ ]?
19
+ (?-i: awd\.? | AWD )
20
+ ## POSITIVE lookahead - requires space
21
+ (?= [ ])
22
+ )}ix
23
+
24
+ ###
25
+ ##
26
+ ## add support for score abandoned (inline style)
27
+ ## 2-1 abd. or 2-1 ABD
28
+ SCORE_ABD_RE = %r{
29
+ (?<score_abd>
30
+ \b
31
+ (?<score1>\d{1,2}) - (?<score2>\d{1,2})
32
+ [ ]?
33
+ (?-i: abd\.? | ABD )
34
+ ## POSITIVE lookahead - requires space
35
+ (?= [ ])
36
+ )}ix
37
+
38
+ #####
39
+ ## 2-1
40
+ ###
41
+ ### note - was SCORE__FT__RE
42
+ ### changed to "generic" SCORE_RE
43
+ ### and
44
+ ## (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
45
+ ## changed
46
+ ## (?<score1>\d{1,2}) - (?<score2>\d{1,2})
47
+ ## to
48
+ ## pattern match not necessarily the full-time (ft) scoreline!!!
49
+ ## - pattern also used for goal seq(uence) e.g. 1-0 Kane, 1-1 Johnson
50
+ SCORE_RE = %r{
51
+ (?<score>
52
+ \b
53
+ (?<score1>\d{1,2}) - (?<score2>\d{1,2})
54
+ \b
55
+ )}ix
56
+
57
+
58
+
59
+ end # class Lexer
60
+ end # module Fbtxt
@@ -0,0 +1,331 @@
1
+ module Fbtxt
2
+ class Lexer
3
+
4
+
5
+ ## todo/fix
6
+ ## for internal helper constants
7
+ ## use trailing underline
8
+ ## e.g. P_EN_, AGG_EN_ etc!!!
9
+
10
+
11
+ ## todo/check: use ‹› (unicode chars) to mark optional parts in regex constant name - why? why not?
12
+
13
+ #####
14
+ # english helpers (penalty, extra time, ...)
15
+ ## note - p must go last (shortest match)
16
+ # pso = penalty shootout
17
+ ### - note - remove PSO for now (may add later back) - why? why not?
18
+ #
19
+ # todo/fix/clean-up - keep it simple - remove optional trailing dot (.)
20
+ # from pen., p., agg. etc. - why? why not?
21
+ # always use (simply) pen, p, agg
22
+ # (also) remove a.e.t. / a.e.t option - why? why not?
23
+ #
24
+ ## UPDATE mar/2026: addd pens too - keep - why? why not?
25
+ ## (4-3 pens)
26
+ ## (4-3 Pens) -- keep mixed Pens/Pen. too - why? why not?
27
+ ## (4-3 Pen.)
28
+ P_EN = '(?-i: PEN | P |' +
29
+ '[Pp]ens | [Pp]en\.? | p\.? )' # e.g. p., p, pen, pen., etc.
30
+
31
+
32
+ ## fix - change ET_EN to AET_EN!!! - why? why not?
33
+ ## check - allow Aet too - why? why not?
34
+ ## or A.e.t ??
35
+ ET_EN = '(?-i: AET | ' +
36
+ 'aet | a\.e\.t\.? )' # note: make last . optional (e.g a.e.t) allowed too
37
+ # AET_EN = ET_EN
38
+
39
+ ####
40
+ ## after (golden goal/sudden death) extra time - add more options/styles - why? why not?
41
+ AETGG_EN = '(?-i: AET/GG | AGGET | ASDET | ' +
42
+ 'aet/gg | a\.e\.t\.?/g\.g\.? | agget | asdet )'
43
+ ## after (silver goal) extra time
44
+ AETSG_EN = '(?-i: AET/SG | ASGET | ' +
45
+ 'aet/sg | a\.e\.t\.?/s\.g\.? | asget )'
46
+
47
+ ## agg/agg. or AGG
48
+ AGG_EN = '(?-i: AGG | agg\.? )' ## aggregate e..g 4-4 agg etc.
49
+
50
+
51
+
52
+ ## regex score helpers
53
+ ## note - MUST double escape \d e.g. \\d!!! if not "simple" string (e.g. '' but %Q<>)
54
+
55
+ ##
56
+ ## fix - change SCORE_P to SCORE_FULL_P
57
+ ## SCORE_ET to SCORE_FULL_ET
58
+ ##
59
+ ## (re)use SCORE_P, SCORE_ET for score only part!!!
60
+ ##
61
+ ## fix/fix/fix - rename to SCORE_P_ SCORE_ET_
62
+ ## mark internals with TRAILING underscore (leading NOT possible!)
63
+
64
+ SCORE_P = %Q< (?<p1>\\d{1,2}) - (?<p2>\\d{1,2})
65
+ [ ]? #{P_EN}
66
+ >
67
+ SCORE_ET = %Q< (?<et1>\\d{1,2}) - (?<et2>\\d{1,2})
68
+ [ ]? #{ET_EN}
69
+ >
70
+
71
+
72
+ SCORE_LOOKAHEAD = '(?= [ ,\]] | $)'
73
+
74
+
75
+
76
+ ####
77
+ ## after extra-time with golden goal/sudden death & silver goal rule
78
+ ## note - golden goal & silver goal EXCLUDE penalties!!!
79
+ ##
80
+ ## 4-3 a.e.t/g.g.
81
+ ## 4-3 aet/gg
82
+ ## 4-3agget -or- 4-3 asdet
83
+ ## 2-1 aet/sg
84
+ ## -or-
85
+ ## 4-3 aet/gg (3-3, 2-1)
86
+ SCORE__ET_GG_SG__RE = %r{
87
+ (?<score_full>
88
+ \b
89
+ (?<et1>\d{1,2}) - (?<et2>\d{1,2})
90
+ [ ]? (?:
91
+ (?<aetgg> #{AETGG_EN})
92
+ |
93
+ (?<aetsg> #{AETSG_EN})
94
+ )
95
+ ### note:
96
+ ## add optional full-time, half-time score
97
+ (?:
98
+ [ ]+
99
+ \(
100
+ [ ]*
101
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
102
+ [ ]*
103
+ (?:
104
+ , [ ]*
105
+ (?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
106
+ [ ]*
107
+ )?
108
+ )? # note: make half time (HT) score optional for now
109
+ \)
110
+ )?
111
+ #{SCORE_LOOKAHEAD}
112
+ )}ix
113
+
114
+
115
+ ## note: allow SPECIAL cases WITHOUT full time scores (just a.e.t or pen. + a.e.t.)
116
+ ## 3-4 pen. 2-2 a.e.t.
117
+ ## 3-4 pen. 2-2 a.e.t.
118
+ ## 2-2 a.e.t.
119
+ SCORE__P_ET__RE = %r{
120
+ (?<score_full>
121
+ \b
122
+ (?: #{SCORE_P} [ ]+
123
+ )? ## note: make penalty (P) score optional for now
124
+ #{SCORE_ET}
125
+ #{SCORE_LOOKAHEAD}
126
+ )}ix
127
+ ## todo/check: remove loakahead assertion here - why require space?
128
+ ## note: \b works only after non-alphanum e.g. )
129
+
130
+
131
+ ## note: allow SPECIAL cases WITHOUT full time scores
132
+ ## AND with pen in last position!
133
+ ## 2-2 a.e.t., 3-4 pen.
134
+ ## 2-2 a.e.t. 3-4 pen. ## or without comma separator - why? why not?
135
+ SCORE__ET_P__RE = %r{
136
+ (?<score_full>
137
+ \b
138
+ #{SCORE_ET}
139
+ (?: [ ]*,[ ]* | [ ]+ )
140
+ #{SCORE_P}
141
+ #{SCORE_LOOKAHEAD}
142
+ )}ix
143
+ ## todo/check: remove loakahead assertion here - why require space?
144
+ ## note: \b works only after non-alphanum e.g. )
145
+
146
+ ### special case (i) - full time with penalties
147
+ ## 2-2, 3-4 pen.
148
+ SCORE__FT_P__RE = %r{
149
+ (?<score_full>
150
+ \b
151
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
152
+ [ ]*,[ ]* ## note - comma required!!!
153
+ #{SCORE_P}
154
+ #{SCORE_LOOKAHEAD}
155
+ )}ix
156
+
157
+ ### special case (ii) - full time & half-time with penalties
158
+ ## 2-2 (1-1), 3-4 pen.
159
+ SCORE__FT_HT_P__RE = %r{
160
+ (?<score_full>
161
+ \b
162
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
163
+ [ ]*
164
+ \(
165
+ (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
166
+ \)
167
+ [ ]*,[ ]* ## note - comma required!!!
168
+ #{SCORE_P}
169
+ #{SCORE_LOOKAHEAD}
170
+ )}ix
171
+
172
+
173
+
174
+
175
+ ## note: allow SPECIAL with penalty only
176
+ ## 3-4 pen. or 3-4p etc.
177
+ SCORE__P__RE = %r{
178
+ (?<score_full>
179
+ \b
180
+ #{SCORE_P}
181
+ #{SCORE_LOOKAHEAD}
182
+ )}ix
183
+ ## todo/check: remove loakahead assertion here - why require space?
184
+ ## note: \b works only after non-alphanum e.g. )
185
+
186
+ ####
187
+ ## support short all-in-one e.g.
188
+ ## e.g. 3-4 pen. 2-2 a.e.t. ( 1-1, 1-1 ) becomes
189
+ ## 3-4 pen. (2-2, 1-1, 1-1)
190
+
191
+ SCORE__P_ET_FT_HT_V2__RE = %r{
192
+ (?<score_full>
193
+ \b
194
+ #{SCORE_P} [ ]+
195
+ \(
196
+ [ ]*
197
+ (?<et1>\d{1,2}) - (?<et2>\d{1,2})
198
+ [ ]*, [ ]*
199
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
200
+ [ ]*, [ ]*
201
+ (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
202
+ [ ]*
203
+ \)
204
+ #{SCORE_LOOKAHEAD}
205
+ )}ix ## todo/check: remove loakahead assertion here - why require space?
206
+ ## note: \b works only after non-alphanum e.g. )
207
+
208
+
209
+ # e.g. 2-2 a.e.t. (1-1, 1-0), 5-1 pen.
210
+ SCORE__ET_FT_HT_P__RE = %r{
211
+ (?<score_full>
212
+ \b
213
+ #{SCORE_ET} [ ]+
214
+ \(
215
+ [ ]*
216
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
217
+ [ ]*
218
+ (?:
219
+ , [ ]*
220
+ (?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
221
+ [ ]*
222
+ )?
223
+ )? # note: make half time (HT) score optional for now
224
+ \)
225
+ (?: [ ]*,[ ]* | [ ]+)
226
+ #{SCORE_P}
227
+ #{SCORE_LOOKAHEAD}
228
+ )}ix ## todo/check: remove loakahead assertion here - why require space?
229
+ ## note: \b works only after non-alphanum e.g. )
230
+
231
+
232
+
233
+ ## e.g. 3-4 pen. 2-2 a.e.t. (1-1, 1-1) or
234
+ ## 3-4p 2-2aet (1-1, ) or
235
+ ## 3-4 pen. 2-2 a.e.t. (1-1) or
236
+ ## 2-2 a.e.t. (1-1, 1-1) or
237
+ ## 2-2 a.e.t. (1-1, ) or
238
+ ## 2-2 a.e.t. (1-1)
239
+
240
+ SCORE__P_ET_FT_HT__RE = %r{
241
+ (?<score_full>
242
+ \b
243
+ (?:
244
+ #{SCORE_P} [ ]+
245
+ )? ## note - make penalty (P) score optional for now
246
+ #{SCORE_ET} [ ]+
247
+ \(
248
+ [ ]*
249
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
250
+ [ ]*
251
+ (?:
252
+ , [ ]*
253
+ (?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
254
+ [ ]*
255
+ )?
256
+ )? # note: make half time (HT) score optional for now
257
+ \)
258
+ #{SCORE_LOOKAHEAD}
259
+ )}ix ## todo/check: remove loakahead assertion here - why require space?
260
+ ## note: \b works only after non-alphanum e.g. )
261
+
262
+ ###
263
+ ## special case for case WITHOUT extra time!!
264
+ ## same as above (but WITHOUT extra time and pen required)
265
+ SCORE__P_FT_HT__RE = %r{
266
+ (?<score_full>
267
+ \b
268
+ #{SCORE_P} [ ]+
269
+ \(
270
+ [ ]*
271
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
272
+ [ ]*
273
+ (?:
274
+ , [ ]*
275
+ (?: (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
276
+ [ ]*
277
+ )?
278
+ )? # note: make half time (HT) score optional for now
279
+ \)
280
+ #{SCORE_LOOKAHEAD}
281
+ )}ix ## todo/check: remove loakahead assertion here - why require space?
282
+ ## note: \b works only after non-alphanum e.g. )
283
+
284
+
285
+ ##########
286
+ ## e.g. 2-1 (1-1)
287
+ SCORE__FT_HT__RE = %r{
288
+ (?<score_full>
289
+ \b
290
+ (?<ft1>\d{1,2}) - (?<ft2>\d{1,2})
291
+ [ ]+ \( [ ]*
292
+ (?<ht1>\d{1,2}) - (?<ht2>\d{1,2})
293
+ [ ]* \)
294
+ #{SCORE_LOOKAHEAD}
295
+ )}ix ## todo/check: remove loakahead assertion here - why require space?
296
+ ## note: \b works only after non-alphanum e.g. )
297
+
298
+
299
+
300
+
301
+
302
+
303
+ #############################################
304
+ # map tables
305
+ # note: order matters; first come-first matched/served
306
+
307
+ ## note 2-2, 5-1 pen. must get priority (get before SCORE_LEGS!!!)
308
+ ## break out
309
+ ## note - no need for Regexp.union for now (only single regex!)
310
+
311
+ SCORE_FULL_1ST_RE = SCORE__FT_P__RE # e.g. 2-2, 5-1 pen.
312
+
313
+
314
+ SCORE_FULL_RE = Regexp.union(
315
+ SCORE__ET_GG_SG__RE, # e.g. 3-1 aet/gg
316
+ SCORE__P_ET_FT_HT_V2__RE, # e.g. 5-1 pen. (2-2, 1-1, 1-0)
317
+ SCORE__ET_FT_HT_P__RE, # e.g. 2-2 a.e.t. (1-1, 1-0), 5-1 pen.
318
+ SCORE__P_ET_FT_HT__RE, # e.g. 5-1 pen. 2-2 a.e.t. (1-1, 1-0)
319
+ SCORE__P_FT_HT__RE, # e.g. 5-1 pen. (1-1)
320
+ SCORE__ET_P__RE, # e.g. 2-2 a.e.t., 5-1 pen.
321
+ SCORE__FT_HT_P__RE, # e.g. 2-2 (1-1), 5-1 pen.
322
+ SCORE__P_ET__RE, # e.g. 5-1 pen. 2-2 a.e.t. or 2-2 a.e.t. (w/o pen)
323
+ SCORE__P__RE, # e.g. 5-1 pen.
324
+ SCORE__FT_HT__RE, # e.g. 1-1 (1-0)
325
+ ## note - keep basic score as its own token!!!!
326
+ ## that is, SCORE & SCORE_MORE
327
+ ### SCORE__FT__RE, # e.g. 1-1 -- note - must go last!!!
328
+ )
329
+
330
+ end # class Lexer
331
+ end # module Fbtxt