kdl 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -1
- data/README.md +17 -1
- data/lib/kdl/document.rb +2 -0
- data/lib/kdl/error.rb +24 -0
- data/lib/kdl/kdl.tab.rb +128 -129
- data/lib/kdl/kdl.yy +7 -7
- data/lib/kdl/node.rb +7 -5
- data/lib/kdl/parser_common.rb +3 -1
- data/lib/kdl/string_dumper.rb +2 -0
- data/lib/kdl/tokenizer.rb +79 -65
- data/lib/kdl/types/base64.rb +2 -0
- data/lib/kdl/types/country/iso3166_countries.rb +2 -0
- data/lib/kdl/types/country/iso3166_subdivisions.rb +2 -0
- data/lib/kdl/types/country.rb +2 -0
- data/lib/kdl/types/currency/iso4217_currencies.rb +2 -0
- data/lib/kdl/types/currency.rb +2 -0
- data/lib/kdl/types/date_time.rb +2 -0
- data/lib/kdl/types/decimal.rb +2 -0
- data/lib/kdl/types/duration/iso8601_parser.rb +2 -0
- data/lib/kdl/types/duration.rb +2 -0
- data/lib/kdl/types/email/parser.rb +9 -7
- data/lib/kdl/types/email.rb +2 -0
- data/lib/kdl/types/hostname/validator.rb +2 -0
- data/lib/kdl/types/hostname.rb +2 -0
- data/lib/kdl/types/ip.rb +2 -0
- data/lib/kdl/types/irl/parser.rb +9 -7
- data/lib/kdl/types/irl.rb +2 -0
- data/lib/kdl/types/regex.rb +2 -0
- data/lib/kdl/types/url.rb +2 -0
- data/lib/kdl/types/url_template.rb +5 -3
- data/lib/kdl/types/uuid.rb +2 -0
- data/lib/kdl/types.rb +2 -0
- data/lib/kdl/v1/document.rb +2 -0
- data/lib/kdl/v1/node.rb +2 -0
- data/lib/kdl/v1/string_dumper.rb +2 -0
- data/lib/kdl/v1/tokenizer.rb +33 -31
- data/lib/kdl/v1/value.rb +2 -0
- data/lib/kdl/v1.rb +2 -0
- data/lib/kdl/value.rb +6 -3
- data/lib/kdl/version.rb +3 -1
- data/lib/kdl.rb +9 -2
- metadata +4 -6
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module KDL
|
@@ -39,7 +41,7 @@ module KDL
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def next_token
|
42
|
-
buffer = ''
|
44
|
+
buffer = +''
|
43
45
|
context = nil
|
44
46
|
expansion_type = nil
|
45
47
|
loop do
|
@@ -49,7 +51,7 @@ module KDL
|
|
49
51
|
case c
|
50
52
|
when '{'
|
51
53
|
context = :expansion
|
52
|
-
buffer = ''
|
54
|
+
buffer = +''
|
53
55
|
n = @string[@index + 1]
|
54
56
|
expansion_type = case n
|
55
57
|
when '+' then ReservedExpansion
|
@@ -64,7 +66,7 @@ module KDL
|
|
64
66
|
@index += (expansion_type == StringExpansion ? 1 : 2)
|
65
67
|
when nil then return nil
|
66
68
|
else
|
67
|
-
buffer = c
|
69
|
+
buffer = +c
|
68
70
|
@index += 1
|
69
71
|
context = :literal
|
70
72
|
end
|
data/lib/kdl/types/uuid.rb
CHANGED
data/lib/kdl/types.rb
CHANGED
data/lib/kdl/v1/document.rb
CHANGED
data/lib/kdl/v1/node.rb
CHANGED
data/lib/kdl/v1/string_dumper.rb
CHANGED
data/lib/kdl/v1/tokenizer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module KDL
|
2
4
|
module V1
|
3
5
|
class Tokenizer < KDL::Tokenizer
|
@@ -17,14 +19,14 @@ module KDL
|
|
17
19
|
case c
|
18
20
|
when '"'
|
19
21
|
self.context = :string
|
20
|
-
@buffer = ''
|
22
|
+
@buffer = +''
|
21
23
|
traverse(1)
|
22
24
|
when 'r'
|
23
25
|
if @str[@index + 1] == '"'
|
24
26
|
self.context = :rawstring
|
25
27
|
traverse(2)
|
26
28
|
@rawstring_hashes = 0
|
27
|
-
@buffer = ''
|
29
|
+
@buffer = +''
|
28
30
|
next
|
29
31
|
elsif @str[@index + 1] == '#'
|
30
32
|
i = @index + 1
|
@@ -36,12 +38,12 @@ module KDL
|
|
36
38
|
if @str[i] == '"'
|
37
39
|
self.context = :rawstring
|
38
40
|
@index = i + 1
|
39
|
-
@buffer = ''
|
41
|
+
@buffer = +''
|
40
42
|
next
|
41
43
|
end
|
42
44
|
end
|
43
45
|
self.context = :ident
|
44
|
-
@buffer = c
|
46
|
+
@buffer = +c
|
45
47
|
traverse(1)
|
46
48
|
when '-'
|
47
49
|
n = self[@index + 1]
|
@@ -58,16 +60,16 @@ module KDL
|
|
58
60
|
self.context = :ident
|
59
61
|
traverse(1)
|
60
62
|
end
|
61
|
-
@buffer = c
|
63
|
+
@buffer = +c
|
62
64
|
when /[0-9+]/
|
63
65
|
n = self[@index + 1]
|
64
66
|
if c == '0' && n =~ /[box]/
|
65
67
|
traverse(2)
|
66
|
-
@buffer = ''
|
68
|
+
@buffer = +''
|
67
69
|
self.context = integer_context(n)
|
68
70
|
else
|
69
71
|
self.context = :decimal
|
70
|
-
@buffer = c
|
72
|
+
@buffer = +c
|
71
73
|
traverse(1)
|
72
74
|
end
|
73
75
|
when '\\'
|
@@ -76,16 +78,16 @@ module KDL
|
|
76
78
|
if la[0] == :NEWLINE || la[0] == :EOF || (la[0] == :WS && (lan = t.next_token[0]) == :NEWLINE || lan == :EOF)
|
77
79
|
traverse_to(t.index)
|
78
80
|
@buffer = "#{c}#{la[1].value}"
|
79
|
-
@buffer
|
81
|
+
@buffer << "\n" if lan == :NEWLINE
|
80
82
|
self.context = :whitespace
|
81
83
|
else
|
82
84
|
raise_error "Unexpected '\\' (#{la[0]})"
|
83
85
|
end
|
84
86
|
when *SYMBOLS.keys
|
85
|
-
return token(SYMBOLS[c], c).tap { traverse(1) }
|
87
|
+
return token(SYMBOLS[c], -c).tap { traverse(1) }
|
86
88
|
when *NEWLINES, "\r"
|
87
89
|
nl = expect_newline
|
88
|
-
return token(:NEWLINE, nl).tap do
|
90
|
+
return token(:NEWLINE, -nl).tap do
|
89
91
|
traverse(nl.length)
|
90
92
|
end
|
91
93
|
when "/"
|
@@ -100,12 +102,12 @@ module KDL
|
|
100
102
|
return token(:SLASHDASH, '/-').tap { traverse(2) }
|
101
103
|
else
|
102
104
|
self.context = :ident
|
103
|
-
@buffer = c
|
105
|
+
@buffer = +c
|
104
106
|
traverse(1)
|
105
107
|
end
|
106
108
|
when *WHITESPACE
|
107
109
|
self.context = :whitespace
|
108
|
-
@buffer = c
|
110
|
+
@buffer = +c
|
109
111
|
traverse(1)
|
110
112
|
when nil
|
111
113
|
return [false, token(:EOF, :EOF)[1]] if @done
|
@@ -114,14 +116,14 @@ module KDL
|
|
114
116
|
return token(:EOF, :EOF)
|
115
117
|
when INITIAL_IDENTIFIER_CHARS
|
116
118
|
self.context = :ident
|
117
|
-
@buffer = c
|
119
|
+
@buffer = +c
|
118
120
|
traverse(1)
|
119
121
|
when '('
|
120
122
|
@type_context = true
|
121
|
-
return token(:LPAREN, c).tap { traverse(1) }
|
123
|
+
return token(:LPAREN, -c).tap { traverse(1) }
|
122
124
|
when ')'
|
123
125
|
@type_context = false
|
124
|
-
return token(:RPAREN, c).tap { traverse(1) }
|
126
|
+
return token(:RPAREN, -c).tap { traverse(1) }
|
125
127
|
else
|
126
128
|
raise_error "Unexpected character #{c.inspect}"
|
127
129
|
end
|
@@ -129,13 +131,13 @@ module KDL
|
|
129
131
|
case c
|
130
132
|
when IDENTIFIER_CHARS
|
131
133
|
traverse(1)
|
132
|
-
@buffer
|
134
|
+
@buffer << c
|
133
135
|
else
|
134
136
|
case @buffer
|
135
137
|
when 'true' then return token(:TRUE, true)
|
136
138
|
when 'false' then return token(:FALSE, false)
|
137
139
|
when 'null' then return token(:NULL, nil)
|
138
|
-
else return token(:IDENT,
|
140
|
+
else return token(:IDENT, -@buffer)
|
139
141
|
end
|
140
142
|
end
|
141
143
|
when :string
|
@@ -149,16 +151,16 @@ module KDL
|
|
149
151
|
end
|
150
152
|
traverse(i)
|
151
153
|
else
|
152
|
-
@buffer
|
153
|
-
@buffer
|
154
|
+
@buffer << c
|
155
|
+
@buffer << c2
|
154
156
|
traverse(2)
|
155
157
|
end
|
156
158
|
when '"'
|
157
|
-
return token(:STRING, unescape(@buffer)).tap { traverse(1) }
|
159
|
+
return token(:STRING, -unescape(@buffer)).tap { traverse(1) }
|
158
160
|
when nil
|
159
161
|
raise_error "Unterminated string literal"
|
160
162
|
else
|
161
|
-
@buffer
|
163
|
+
@buffer << c
|
162
164
|
traverse(1)
|
163
165
|
end
|
164
166
|
when :rawstring
|
@@ -168,17 +170,17 @@ module KDL
|
|
168
170
|
h = 0
|
169
171
|
h += 1 while self[@index + 1 + h] == '#' && h < @rawstring_hashes
|
170
172
|
if h == @rawstring_hashes
|
171
|
-
return token(:RAWSTRING,
|
173
|
+
return token(:RAWSTRING, -@buffer).tap { traverse(1 + h) }
|
172
174
|
end
|
173
175
|
end
|
174
176
|
|
175
|
-
@buffer
|
177
|
+
@buffer << c
|
176
178
|
traverse(1)
|
177
179
|
when :decimal
|
178
180
|
case c
|
179
181
|
when /[0-9.\-+_eE]/
|
180
182
|
traverse(1)
|
181
|
-
@buffer
|
183
|
+
@buffer << c
|
182
184
|
else
|
183
185
|
return parse_decimal(@buffer)
|
184
186
|
end
|
@@ -186,7 +188,7 @@ module KDL
|
|
186
188
|
case c
|
187
189
|
when /[0-9a-fA-F_]/
|
188
190
|
traverse(1)
|
189
|
-
@buffer
|
191
|
+
@buffer << c
|
190
192
|
else
|
191
193
|
return parse_hexadecimal(@buffer)
|
192
194
|
end
|
@@ -194,7 +196,7 @@ module KDL
|
|
194
196
|
case c
|
195
197
|
when /[0-7_]/
|
196
198
|
traverse(1)
|
197
|
-
@buffer
|
199
|
+
@buffer << c
|
198
200
|
else
|
199
201
|
return parse_octal(@buffer)
|
200
202
|
end
|
@@ -202,7 +204,7 @@ module KDL
|
|
202
204
|
case c
|
203
205
|
when /[01_]/
|
204
206
|
traverse(1)
|
205
|
-
@buffer
|
207
|
+
@buffer << c
|
206
208
|
else
|
207
209
|
return parse_binary(@buffer)
|
208
210
|
end
|
@@ -234,7 +236,7 @@ module KDL
|
|
234
236
|
when :whitespace
|
235
237
|
if WHITESPACE.include?(c)
|
236
238
|
traverse(1)
|
237
|
-
@buffer
|
239
|
+
@buffer << c
|
238
240
|
elsif c == "/" && self[@index + 1] == '*'
|
239
241
|
self.context = :multi_line_comment
|
240
242
|
@comment_nesting = 1
|
@@ -244,13 +246,13 @@ module KDL
|
|
244
246
|
la = t.next_token
|
245
247
|
if la[0] == :NEWLINE || la[0] == :EOF || (la[0] == :WS && (lan = t.next_token[0]) == :NEWLINE || lan == :EOF)
|
246
248
|
traverse_to(t.index)
|
247
|
-
@buffer
|
248
|
-
@buffer
|
249
|
+
@buffer << "#{c}#{la[1].value}"
|
250
|
+
@buffer << "\n" if lan == :NEWLINE
|
249
251
|
else
|
250
252
|
raise_error "Unexpected '\\' (#{la[0]})"
|
251
253
|
end
|
252
254
|
else
|
253
|
-
return token(:WS,
|
255
|
+
return token(:WS, -@buffer)
|
254
256
|
end
|
255
257
|
else
|
256
258
|
# :nocov:
|
data/lib/kdl/v1/value.rb
CHANGED
data/lib/kdl/v1.rb
CHANGED
data/lib/kdl/value.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module KDL
|
2
4
|
class Value
|
3
5
|
attr_reader :value, :format, :type
|
@@ -84,9 +86,10 @@ module KDL
|
|
84
86
|
return super.upcase unless value.is_a?(BigDecimal)
|
85
87
|
|
86
88
|
sign, digits, _, exponent = value.split
|
87
|
-
s =
|
88
|
-
s
|
89
|
-
s
|
89
|
+
s = +''
|
90
|
+
s << '-' if sign.negative?
|
91
|
+
s << "#{digits[0]}.#{digits[1..-1]}"
|
92
|
+
s << "E#{exponent.negative? ? '' : '+'}#{exponent - 1}"
|
90
93
|
s
|
91
94
|
end
|
92
95
|
|
data/lib/kdl/version.rb
CHANGED
data/lib/kdl.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "kdl/version"
|
4
|
+
require "kdl/error"
|
2
5
|
require "kdl/tokenizer"
|
3
6
|
require "kdl/document"
|
4
7
|
require "kdl/value"
|
@@ -26,8 +29,10 @@ module KDL
|
|
26
29
|
Parser.new(output_module: output_module(output_version || 2), **options).parse(input)
|
27
30
|
when 1
|
28
31
|
V1::Parser.new.parse(input, output_module: output_module(output_version || 1), **options)
|
29
|
-
|
32
|
+
when nil
|
30
33
|
auto_parse(input, output_version:, **options)
|
34
|
+
else
|
35
|
+
raise UnsupportedVersionError.new("Unsupported version '#{version}'", version)
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
@@ -37,7 +42,9 @@ module KDL
|
|
37
42
|
|
38
43
|
def self.auto_parse(input, output_version: default_output_version, **options)
|
39
44
|
parse(input, version: 2, output_version: output_version || 2, **options)
|
40
|
-
rescue => e
|
45
|
+
rescue VersionMismatchError => e
|
46
|
+
parse(input, version: e.version, output_version: output_version || e.version, **options)
|
47
|
+
rescue Tokenizer::Error, Racc::ParseError => e
|
41
48
|
parse(input, version: 1, output_version: output_version || 1, **options) rescue raise e
|
42
49
|
end
|
43
50
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kdl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danielle Smith
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: racc
|
@@ -89,6 +88,7 @@ files:
|
|
89
88
|
- kdl.gemspec
|
90
89
|
- lib/kdl.rb
|
91
90
|
- lib/kdl/document.rb
|
91
|
+
- lib/kdl/error.rb
|
92
92
|
- lib/kdl/kdl.tab.rb
|
93
93
|
- lib/kdl/kdl.yy
|
94
94
|
- lib/kdl/node.rb
|
@@ -134,7 +134,6 @@ metadata:
|
|
134
134
|
homepage_uri: https://kdl.dev
|
135
135
|
source_code_uri: https://github.com/danini-the-panini/kdl-rb
|
136
136
|
changelog_uri: https://github.com/danini-the-panini/kdl-rb/releases
|
137
|
-
post_install_message:
|
138
137
|
rdoc_options: []
|
139
138
|
require_paths:
|
140
139
|
- lib
|
@@ -149,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
148
|
- !ruby/object:Gem::Version
|
150
149
|
version: '0'
|
151
150
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
153
|
-
signing_key:
|
151
|
+
rubygems_version: 3.6.2
|
154
152
|
specification_version: 4
|
155
153
|
summary: KDL Document Language
|
156
154
|
test_files: []
|