fbtok 0.5.2 → 0.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eef844f7c201c7ead0ccc9ed46324f32b17e33b837aa43d37cd0b6bbab6fc4b
4
- data.tar.gz: 985a3e86686c326fa816db8fcef1385ccc8c5372ac740f46992a9a019685f451
3
+ metadata.gz: dfc4498d40f6906734e5fbff0f1931782e0a49e302490468715891ed5018d4e6
4
+ data.tar.gz: 298261705a027c7b08560418f0ace0d7a6f7d1c088500f3acc5b80ab20666ad9
5
5
  SHA512:
6
- metadata.gz: e0ac5582359acf8fe7c5fb3391c9970e4dcd93f7e2742d92b8b558b2f4c840a9589ed6c157d115f6a98170a5865aa50457078eea2266cfde526b5a8b97630c33
7
- data.tar.gz: 6af6b00555bc59d5745eba085ce599782b08f6bb5e33982fcd07b260ce9ca1f3df062bc6ee05514f737ec24ebd9ad9b422c94839e76e07871fa75b206e476552
6
+ metadata.gz: a433fe38169042980bfaaa030cf2f59c50dd146251b79dece1524b8f80dbfc51435c0de2d41046a88782a6c470e74a34a7e9db893603b4b3facb8395cf2f0068
7
+ data.tar.gz: eaa790f1b4d474cabf4198b7d9e2e1c0411531cd017cd822c9baf6d73e8d5b6562f64d3881784c621f348acc27edc481193137321648ca351449a874d18e94c4
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.5.2
1
+ ### 0.5.4
2
2
  ### 0.0.1 / 2025-01-02
3
3
 
4
4
  * Everything is new. First release.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
2
2
 
3
3
 
4
4
  Hoe.spec 'fbtok' do
5
- self.version = '0.5.2'
5
+ self.version = '0.5.4'
6
6
 
7
7
  self.summary = "fbtok - football.txt lint tools incl. tokenizer, parser & more"
8
8
  self.description = summary
@@ -40,8 +40,10 @@ if opts[:debug]
40
40
  puts "ARGV:"
41
41
  p args
42
42
 
43
+ SportDb::Lexer.debug = true
44
+ RaccMatchParser.debug = true
45
+ SportDb::MatchParser.debug = true
43
46
  SportDb::QuickMatchReader.debug = true
44
- SportDb::MatchParser.debug = true
45
47
  else
46
48
  SportDb::QuickMatchReader.debug = false
47
49
  SportDb::MatchParser.debug = false
@@ -6,9 +6,10 @@ def self.main( args=ARGV )
6
6
 
7
7
  opts = {
8
8
  debug: true,
9
+ # warn: false,
10
+
9
11
  file: nil,
10
12
  seasons: [],
11
- # warn: false,
12
13
  }
13
14
 
14
15
 
@@ -53,11 +54,9 @@ if opts[:debug]
53
54
  p opts
54
55
  puts "ARGV:"
55
56
  p args
56
- end
57
-
58
57
 
59
- # SportDb::Parser::Linter.debug = opts[:debug]
60
- # SportDb::Parser::Linter.warn = opts[:warn]
58
+ SportDb::Lexer.debug = true
59
+ end
61
60
 
62
61
 
63
62
 
@@ -99,7 +98,7 @@ specs.each_with_index do |rec,i|
99
98
  puts "==> [#{i+1}/#{specs.size}, #{j+1}/#{datafiles.size}] reading >#{path}<..."
100
99
 
101
100
  txt = read_text( path )
102
- lexer = SportDb::Lexer.new( txt, debug: opts[:debug] )
101
+ lexer = SportDb::Lexer.new( txt )
103
102
  tokens, more_errors = lexer.tokenize_with_errors
104
103
 
105
104
  ####
@@ -4,11 +4,18 @@ module Fbtree
4
4
  def self.main( args=ARGV )
5
5
 
6
6
 
7
+
7
8
  opts = {
8
9
  debug: true,
10
+ ## warn: false,
11
+
12
+ json: false,
13
+ yaml: false,
14
+
9
15
  file: nil,
16
+ tty: false,
17
+
10
18
  seasons: [],
11
- ## warn: false,
12
19
  }
13
20
 
14
21
  parser = OptionParser.new do |parser|
@@ -29,6 +36,13 @@ parser = OptionParser.new do |parser|
29
36
  # end
30
37
 
31
38
 
39
+ parser.on( "-f FILE", "--file FILE",
40
+ "read datafiles (pathspecs) via .csv file") do |file|
41
+ opts[:file] = file
42
+ ## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
43
+ opts[:debug] = false
44
+ end
45
+
32
46
  parser.on( "--seasons SEASONS",
33
47
  "filter by seasons (default: #{opts[:seasons]})") do |seasons|
34
48
  opts[:seasons] = seasons
@@ -36,13 +50,20 @@ parser = OptionParser.new do |parser|
36
50
  .map { |season| Season.parse(season.strip) }
37
51
  end
38
52
 
39
- parser.on( "-f FILE", "--file FILE",
40
- "read datafiles (pathspecs) via .csv file") do |file|
41
- opts[:file] = file
42
- ## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
43
- opts[:debug] = false
53
+
54
+ parser.on( "-j", "--json",
55
+ "turn on output in json (default: #{opts[:json]})" ) do |json|
56
+ opts[:json] = true
57
+ end
58
+ parser.on( "-y", "--yaml",
59
+ "turn on output in yaml (default: #{opts[:yaml]})" ) do |yaml|
60
+ opts[:yaml] = true
44
61
  end
45
62
 
63
+ parser.on( "-t", "--terminal", "--tty",
64
+ "force terminal/tty input (default: #{opts[:tty]})" ) do |tty|
65
+ opts[:tty] = tty
66
+ end
46
67
  end
47
68
  parser.parse!( args )
48
69
 
@@ -51,10 +72,66 @@ if opts[:debug]
51
72
  p opts
52
73
  puts "ARGV:"
53
74
  p args
75
+
76
+ SportDb::Lexer.debug = true
77
+ RaccMatchParser.debug = true
54
78
  end
55
79
 
56
80
 
57
81
 
82
+ ## special case for typed input via terminal/tty
83
+ if opts[:tty]
84
+
85
+ puts "type your football.TXT lines here (exit with ctrl-z and return):"
86
+ lines = STDIN.readlines ## note - readlines incl. trailing newline!
87
+
88
+ txt = lines.join ## note - join with no space (already incl. trailing newline!)
89
+
90
+ puts "--- parsing #{lines.size} line(s) ---"
91
+ puts txt
92
+ puts "--- results ---"
93
+
94
+ tree, errors = parse_with_errors( txt, opts )
95
+
96
+ if errors.size > 0
97
+ puts
98
+ pp errors
99
+ puts
100
+ puts "!! #{errors.size} parse error(s)"
101
+ exit 1
102
+ else
103
+ puts
104
+ puts "OK no parse errors found"
105
+ exit 0
106
+ end
107
+ end
108
+
109
+
110
+
111
+ ## check for piped input e.g. $ curl | fbtree
112
+ if !STDIN.tty? ## input NOT via tty (teletype terminal)
113
+
114
+ txt = STDIN.read
115
+
116
+ puts "--- parsing ---"
117
+ puts txt
118
+ puts "--- results ---"
119
+
120
+ tree, errors = parse_with_errors( txt, opts )
121
+
122
+ if errors.size > 0
123
+ puts
124
+ pp errors
125
+ puts
126
+ puts "!! #{errors.size} parse error(s)"
127
+ exit 1
128
+ else
129
+ puts
130
+ puts "OK no parse errors found"
131
+ exit 0
132
+ end
133
+ end
134
+
58
135
 
59
136
 
60
137
 
@@ -70,6 +147,11 @@ specs = if opts[:file]
70
147
  nil
71
148
  end
72
149
 
150
+ ##
151
+ ## maybe change to:
152
+ ## Env.fbpath( default)
153
+ ## or fb_path or such - why? why not?
154
+
73
155
  path = SportDb::Pathspec.path(
74
156
  ['/sports/sportdb/sport.db.v2/parser/fbtxt-specs',
75
157
  '/sports/sportdb/sport.db.v2/parser/fbtxt-samples',
@@ -87,9 +169,6 @@ specs = if opts[:file]
87
169
  ## opts[:debug] = false
88
170
  ## end
89
171
 
90
- # SportDb::Parser::Linter.debug = opts[:debug]
91
- # SportDb::Parser::Linter.warn = opts[:warn]
92
-
93
172
 
94
173
 
95
174
  if opts[:seasons].size > 0
@@ -108,20 +187,17 @@ specs.each_with_index do |rec,i|
108
187
  puts "==> [#{i+1}/#{specs.size}, #{j+1}/#{datafiles.size}] reading >#{path}<..."
109
188
 
110
189
  txt = read_text( path )
111
- parser = RaccMatchParser.new( txt, debug: opts[:debug] )
112
- tree = parser.parse
190
+ tree, more_errors = parse_with_errors( txt, opts )
113
191
 
114
- dump_tree_stats( tree )
115
-
116
- if parser.errors?
192
+ if more_errors.size > 0
117
193
  ## note - auto-add filename to errors
118
- parser.errors.each do |msg|
194
+ more_errors.each do |msg|
119
195
  ###
120
196
  ### errors << [ path, *msg ] # note: use splat (*) to add extra values (starting with msg)
121
197
  errors << [path, msg]
122
198
  end
123
199
 
124
- log << [:ERROR, path, "#{parser.errors.size} parse error(s), #{tree.size} tree node(s)"]
200
+ log << [:ERROR, path, "#{more_errors.size} parse error(s), #{tree.size} tree node(s)"]
125
201
  else
126
202
  log << [:OK, path, "#{tree.size} tree node(s)"]
127
203
  end
@@ -184,4 +260,31 @@ def self.dump_tree_stats( tree )
184
260
  end
185
261
 
186
262
 
263
+
264
+ def self.parse_with_errors( txt, opts={} )
265
+ parser = RaccMatchParser.new( txt )
266
+ tree = parser.parse
267
+
268
+ dump_tree_stats( tree )
269
+
270
+ if opts[:yaml]
271
+ puts "--- yaml ---"
272
+ puts YAML.dump( tree )
273
+ end
274
+
275
+ if opts[:json]
276
+ puts "--- json ---"
277
+ ## puts JSON.pretty_generate( tree )
278
+ ##
279
+ ## note - use hacky but more beautiful pretty_print
280
+ txtjson = tree.as_json.pretty_inspect
281
+ txtjson = txtjson.gsub( '=>', ': ' )
282
+ puts txtjson
283
+ end
284
+
285
+
286
+ [tree, parser.errors]
287
+ end
288
+
289
+
187
290
  end # module Fbtree
@@ -46,6 +46,8 @@ if opts[:debug]
46
46
  puts "ARGV:"
47
47
  p args
48
48
 
49
+ SportDb::Lexer.debug = true
50
+ RaccMatchParser.debug = true
49
51
  SportDb::MatchParser.debug = true
50
52
  else
51
53
  SportDb::MatchParser.debug = false
@@ -1,33 +1,5 @@
1
1
 
2
2
 
3
- ##
4
- ## note - add find_dir( name, path: ) helper
5
- ## move upstream into cocos - why? why not?
6
- def find_dir( name, path: [] )
7
- return File.expand_path( name ) if Dir.exist?( name )
8
-
9
- ## note - if name starts with / or \ assume it's absolute!!
10
- ## do NOT search!!!
11
- ## note - search still works for
12
- ## ./austria or ../austria or such
13
- ##
14
- ## todo/check/fix-fix-fix
15
- ## is there a File.absolute? or such method for reuse??
16
- ##
17
- ## todo/fix-fix-fix add absolute check upstream to find_file too!!!
18
- return nil if name.start_with?( %r{[/\\]} )
19
-
20
- path.each do |basedir|
21
- ## todo/check - always make sure basedir is an absolute/expanded path - why? why not?
22
- dirpath = File.expand_path( name, basedir )
23
- return dirpath if Dir.exist?( dirpath )
24
- end
25
-
26
- nil ## return nil if not found
27
- end
28
-
29
-
30
-
31
3
 
32
4
 
33
5
  module SportDb
@@ -161,6 +133,15 @@ def self.find( path, seasons: nil )
161
133
  next if /squad/i.match?( basename )
162
134
  next if /\.v[0-9][0-9_]*/i.match?( basename )
163
135
 
136
+ ### exclude
137
+ ## logs.txt or logs.xxx.txt etc
138
+ ## log.txt or log.xxx.txt etc
139
+ ## -or-
140
+ ## errors.txt or errors.xxx.txt etc
141
+ next if /^logs?($|\.)/i.match?( basename )
142
+ next if /^errors?($|\.)/i.match?( basename )
143
+
144
+
164
145
  #####
165
146
  ### exclude dirs with:
166
147
  ## - squad or wiki
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbtok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-11 00:00:00.000000000 Z
11
+ date: 2026-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-parser