vdf 1.0.1 → 1.0.2

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vdf/parse.rb +24 -22
  3. data/lib/vdf/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d59421040845ace586a5c85a1bd21f04197956ecf167864ce816e76fb2f1313
4
- data.tar.gz: c11b0824a64d2d5c83fedffe3cfefdf75739528d42844b899e8e820d600dbc48
3
+ metadata.gz: 671fed7feb60fe6633dbf7f0e59be7871b6ebcdce21526f4a48a2995f74bab30
4
+ data.tar.gz: 27d447b2bdaa23854f08b8d39765baec1119e80362e565eceb3c07761144faa8
5
5
  SHA512:
6
- metadata.gz: acbbf17141f9d37ceb9afa01a6ce343f3769e18c56b411afd70a4b23d04cdc4c83db9d6907476da71115a0514d3f1a9e0319e333d1e1f9a6334027bd56fcf407
7
- data.tar.gz: 29a20503e1a355834385e07f303ade165a52b1f6479a6b16e55b4e1af188a088bdf5e9c6b63985104c77646455d89174a783aeb4838d4918d81b0d68b2475fcb
6
+ metadata.gz: 52725af93ca37ad09273f16ffc1cad5c1ea90c89703187e915a8c8855806795a33f2378c07a76b7ef81e59de6344338ae8f5ac81104c3621d777283a24e2abca
7
+ data.tar.gz: 335f96798e24298f69aeda8a8df290bf5245126951c69e556312b53d5b98fe998653d324620c76fbce6ce717de9e96db31b5ddbc9c79ae39a09506ffa1e6e2e5
data/lib/vdf/parse.rb CHANGED
@@ -10,27 +10,26 @@ module VDF
10
10
  Regexp::MULTILINE
11
11
  )
12
12
 
13
- def parse(text)
14
- lines = text.lines
15
- object = {}
16
- stack = [object]
17
- expect = false
18
- skip_lines = 0
13
+ def parse(input)
14
+ raise ArgumentError, "Input has to respond to :each_line or :to_str" unless input.respond_to?(:each_line) || input.respond_to?(:to_str)
15
+ input = StringIO.new(input) unless input.respond_to? :pos
19
16
 
20
- lines.each_with_index do |line, i|
21
- if skip_lines > 0
22
- skip_lines -= 1
23
- next
24
- end
17
+ result = {}
18
+ stack = [result]
19
+ expect = false
20
+ i = 0
25
21
 
26
- line.strip!
27
- next if line == -'' || line[0] == -'/'
22
+ enum = input.each_line.lazy
23
+ enum.with_index do |line, _|
24
+ i += 1
25
+ line.encode!("UTF-8").strip!
26
+ next if line.empty? || line[0] == -'/'
28
27
 
29
28
  if line.start_with?(-'{')
30
29
  expect = false
31
30
  next
32
31
  elsif expect
33
- raise ParserError, "Invalid syntax on line #{i+1}"
32
+ raise ParserError, "Invalid syntax on line #{i+1} (Expected identifier)"
34
33
  end
35
34
 
36
35
  if line.start_with?(-'}')
@@ -39,9 +38,8 @@ module VDF
39
38
  end
40
39
 
41
40
  loop do
42
- m = REGEX.match(line)
43
- if m.nil?
44
- raise ParserError, "Invalid syntax on line #{i+1}"
41
+ if (m = REGEX.match(line)).nil?
42
+ raise ParserError, "Invalid syntax on line #{i+1} (Line didn't match regex)"
45
43
  end
46
44
 
47
45
  key = m[2] || m[3]
@@ -51,16 +49,20 @@ module VDF
51
49
  if stack[-1][key].nil?
52
50
  stack[-1][key] = {}
53
51
  end
54
- stack.push(stack[-1][key])
52
+ stack << stack[-1][key]
55
53
  expect = true
56
54
  else
57
55
  if m[7].nil? && m[8].nil?
58
- line << -"\n" << lines[i+skip_lines+1].chomp
59
- skip_lines += 1
56
+ if (next_line = enum.next).nil?
57
+ raise ParserError, "Invalid syntax on line #{i+1} (Unexpected EOF)"
58
+ end
59
+
60
+ i += 1
61
+ line << -"\n" << next_line.to_s.encode("UTF-8").strip
60
62
  next
61
63
  end
62
64
 
63
- stack[stack.length - 1][key] = begin
65
+ stack[-1][key] = begin
64
66
  begin
65
67
  Integer(val)
66
68
  rescue ArgumentError
@@ -84,7 +86,7 @@ module VDF
84
86
  end
85
87
  end
86
88
 
87
- return object
89
+ return result
88
90
  end
89
91
  end
90
92
  end
data/lib/vdf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VDF
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sapphyrus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-22 00:00:00.000000000 Z
11
+ date: 2019-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler