rb_cfg_parser 0.1.1 → 0.1.3

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: d9103c8c06f978609933e4ffc3c7aaa4e4af44860e5feb1a8d94f6a76daac847
4
- data.tar.gz: 5f893f3b5042113a90de05ba58d6b36f0d98c500fdc71ef6938af471bbf0f6e5
3
+ metadata.gz: c5baa2915b2b314917d8ebb3ec36c91cb469aa90916dce32e81c01fee87aa0b0
4
+ data.tar.gz: 76ce42f3803d1062423aeb16a2a348522e2e6ad1cb9cf8e051c547351c3ba1d6
5
5
  SHA512:
6
- metadata.gz: ae76c8dc9b3a1ea6bc380c7c94423da7184b603fd36e522daf1d7959ee710bc4c54d0b76be3fc5b62691e2ea825c7f5fc13cab7b6dcf79beb81fcef94af73e31
7
- data.tar.gz: 6af35ac2f6dfaab81984c1018de0c4df97edde92770786cb63cf63b744e97139e32ff993cc2054e16dafcdb0d0e0739787269a1940031f387b2b171cf45c823e
6
+ metadata.gz: f300605313b2c367dddc1b560b0bf978a3655b2922961c69a754f4fade8099e667a58f0ecc26b90fee7d8e14c8ef30ccaacfa113db95cfb9f93c5b74f97d421e
7
+ data.tar.gz: 8718b39a993f5c793ce5b79bc130c3b05f58f4409926bee8491704186bc5feabfe91dc8492be8161dbf57ce45d6517f47042ea81c874139284fe9e05ee50f137
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) since 2025: rb-cfg-parser ruby App
3
+ Copyright (c) since 2025: rb-cfg-parser Ruby Gem
4
4
  description: ruby gem to parse and load .cfg files
5
5
  author: J. Arrizza email: cppgent0@gmail.com
6
6
 
@@ -9,6 +9,7 @@ class RbCfgParser
9
9
  attr_writer :log_cb
10
10
 
11
11
  ###
12
+ # constructor
12
13
  def initialize
13
14
  @rex = CfgLexer.new
14
15
  @fsm = :start
@@ -20,18 +21,22 @@ class RbCfgParser
20
21
  @curr_values = nil
21
22
  @curr_section = nil
22
23
  @curr_section_lineno = 0
23
- @log_cb = method(:print_line)
24
+ @log_cb = method(:_print_raw_line)
24
25
  @verbose = 0
25
26
  @content = {}
26
27
  end
27
28
 
28
29
  ###
30
+ # parse the given file
31
+ # @return the content as a hash
29
32
  def parse_file(path)
30
33
  file_content = File.read(path)
31
34
  parse_str(file_content)
32
35
  end
33
36
 
34
37
  ###
38
+ # parse the given string
39
+ # @return the content as a hash
35
40
  def parse_str(text)
36
41
  text = text.join("\n") if text.is_a?(Array)
37
42
  @rex.scan_setup(text)
@@ -42,7 +47,8 @@ class RbCfgParser
42
47
 
43
48
  loop do
44
49
  break if @token.nil?
45
- print_dbg(format('fsm:%-17s tok[%d]:%-13s val:%-10s next[%d]=%s', @fsm, @tok_posn, @token[0], @token[1], @next_tok_posn, @next_token))
50
+ # print_dbg(format('fsm:%-17s tok[%d]:%-13s val:%-10s next[%d]=%s',
51
+ # @fsm, @tok_posn, @token[0], @token[1], @next_tok_posn, @next_token))
46
52
 
47
53
  if @token[0] == :newline
48
54
  @lineno += 1
@@ -77,6 +83,9 @@ class RbCfgParser
77
83
  end
78
84
 
79
85
  ###
86
+ # in the start fsm state:
87
+ # read and handle the next value
88
+ # @return None
80
89
  def fsm_start
81
90
  if @token[0] == :newline
82
91
  @lineno += 1
@@ -99,6 +108,9 @@ class RbCfgParser
99
108
  end
100
109
 
101
110
  ###
111
+ # in the read_section fsm state:
112
+ # read and handle the next value
113
+ # @return None
102
114
  def fsm_read_section
103
115
  if @token[0] == :vrbl
104
116
  @curr_section = @token[1]
@@ -118,6 +130,9 @@ class RbCfgParser
118
130
  end
119
131
 
120
132
  ###
133
+ # in the assignments fsm state:
134
+ # read and handle the next value
135
+ # @return None
121
136
  def fsm_assignments
122
137
  if @token[0] == :newline
123
138
  # skip
@@ -141,6 +156,9 @@ class RbCfgParser
141
156
  end
142
157
 
143
158
  ###
159
+ # in the asgmt_read_values fsm state:
160
+ # read and handle the next value
161
+ # @return None
144
162
  def fsm_asgmt_read_values
145
163
  if @token[0] == :newline
146
164
  # handle empty value
@@ -193,6 +211,8 @@ class RbCfgParser
193
211
  end
194
212
 
195
213
  ###
214
+ # strip any quotes (single or double) from the given value
215
+ # @return the updated value
196
216
  def strip_quotes(val)
197
217
  if (val[0] == "'" && val[-1] == "'") || (val[0] == '"' && val[-1] == '"')
198
218
  val[1..-2]
@@ -202,6 +222,8 @@ class RbCfgParser
202
222
  end
203
223
 
204
224
  ###
225
+ # reset the section info
226
+ # @return None
205
227
  def reset_section
206
228
  @curr_section = nil
207
229
  @curr_section_lineno = @lineno
@@ -210,6 +232,8 @@ class RbCfgParser
210
232
  end
211
233
 
212
234
  ###
235
+ # save the current section that was found
236
+ # @return None
213
237
  def save_curr_section
214
238
  if @content.include?(@curr_section)
215
239
  raise_err("found duplicate section: \"#{@curr_section}\"")
@@ -219,6 +243,8 @@ class RbCfgParser
219
243
  end
220
244
 
221
245
  ###
246
+ # save the current assignment that found
247
+ # @return None
222
248
  def save_curr_assignment
223
249
  if @content[@curr_section].include?(@curr_vrbl)
224
250
  raise_err("found duplicate variable: \"#{@curr_vrbl}\" in section: \"#{@curr_section}\"")
@@ -229,6 +255,8 @@ class RbCfgParser
229
255
  end
230
256
 
231
257
  ###
258
+ # get the next token from the input stream, set token and tok_posn
259
+ # @return None
232
260
  def get_next_token
233
261
  @token = @next_token
234
262
  @tok_posn = @next_tok_posn
@@ -246,22 +274,41 @@ class RbCfgParser
246
274
  end
247
275
 
248
276
  ###
277
+ # raise an exception indicating an unexpected token was found
278
+ # @return does not return
249
279
  def raise_unexpected_token
250
280
  raise_err("Unexpected token #{@token}")
251
281
  end
252
282
 
253
283
  ###
254
- def raise_err(text)
255
- raise("\nline: #{@lineno}] in state: #{@fsm}, #{text}")
284
+ # raise an exception with the given text
285
+ # @param msg additional message to print
286
+ # @return does not return
287
+ def raise_err(msg)
288
+ raise("\nline: #{@lineno}] in state: #{@fsm}, #{msg}")
256
289
  end
257
290
 
258
291
  ###
292
+ # print a debug line
293
+ # @param msg line to print
294
+ # @return None
259
295
  def print_dbg(msg)
260
296
  @log_cb.call(format('DBG line: %3d] %s', @lineno, msg)) if @verbose > 1
261
297
  end
262
298
 
263
299
  ###
300
+ # print a line
301
+ # @param msg line to print
302
+ # @return None
264
303
  def print_line(msg)
265
304
  @log_cb.call(format(' --> line: %3d] %s', @lineno, msg)) if @verbose.positive?
266
305
  end
306
+
307
+ ###
308
+ # default callback to print a simple line to stdout
309
+ # @param msg line to print
310
+ # @return None
311
+ def _print_raw_line(msg)
312
+ # skip
313
+ end
267
314
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
  ## current version
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.3'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_cfg_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Arrizza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-18 00:00:00.000000000 Z
11
+ date: 2025-06-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ruby gem to parse and load .cfg files
14
14
  email: cppgent0@gmail.com