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
data/lib/kdl/tokenizer.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bigdecimal'
|
2
4
|
|
3
5
|
module KDL
|
4
6
|
class Tokenizer
|
5
|
-
class Error <
|
7
|
+
class Error < ::KDL::Error
|
6
8
|
def initialize(message, line, column)
|
7
9
|
super("#{message} (#{line}:#{column})")
|
8
10
|
end
|
@@ -40,16 +42,16 @@ module KDL
|
|
40
42
|
'=' => :EQUALS
|
41
43
|
}
|
42
44
|
|
43
|
-
WHITESPACE = ["\u0009", "\
|
44
|
-
"\
|
45
|
-
"\
|
46
|
-
"\
|
47
|
-
"\
|
45
|
+
WHITESPACE = ["\u0009", "\u0020", "\u00A0", "\u1680",
|
46
|
+
"\u2000", "\u2001", "\u2002", "\u2003",
|
47
|
+
"\u2004", "\u2005", "\u2006", "\u2007",
|
48
|
+
"\u2008", "\u2009", "\u200A", "\u202F",
|
49
|
+
"\u205F", "\u3000"]
|
48
50
|
WS = "[#{Regexp.escape(WHITESPACE.join)}]"
|
49
51
|
WS_STAR = /\A#{WS}*\z/
|
50
52
|
WS_PLUS = /\A#{WS}+\z/
|
51
53
|
|
52
|
-
NEWLINES = ["\u000A", "\u0085", "\u000C", "\u2028", "\u2029"]
|
54
|
+
NEWLINES = ["\u000A", "\u0085", "\u000B", "\u000C", "\u2028", "\u2029"]
|
53
55
|
NEWLINES_PATTERN = Regexp.new("(#{NEWLINES.map{Regexp.escape(_1)}.join('|')}|\r\n?)", Regexp::MULTILINE)
|
54
56
|
|
55
57
|
OTHER_NON_IDENTIFIER_CHARS = ("\x0".."\x20").to_a - WHITESPACE
|
@@ -68,13 +70,15 @@ module KDL
|
|
68
70
|
"\uFEFF"
|
69
71
|
]
|
70
72
|
|
73
|
+
VERSION_PATTERN = /\A\/-[#{WHITESPACE.join}]*kdl-version[#{WHITESPACE.join}]+(\d+)[#{WHITESPACE.join}]*[#{NEWLINES.join}]/
|
74
|
+
|
71
75
|
def initialize(str, start = 0)
|
72
76
|
@str = debom(str)
|
73
77
|
@context = nil
|
74
78
|
@rawstring_hashes = nil
|
75
79
|
@start = start
|
76
80
|
@index = start
|
77
|
-
@buffer = ""
|
81
|
+
@buffer = +""
|
78
82
|
@done = false
|
79
83
|
@previous_context = nil
|
80
84
|
@line = 1
|
@@ -84,7 +88,7 @@ module KDL
|
|
84
88
|
end
|
85
89
|
|
86
90
|
def version_directive
|
87
|
-
if m = @str.match(
|
91
|
+
if m = @str.match(VERSION_PATTERN)
|
88
92
|
m[1].to_i
|
89
93
|
end
|
90
94
|
end
|
@@ -121,11 +125,11 @@ module KDL
|
|
121
125
|
if self[@index + 1] == '"' && self[@index + 2] == '"'
|
122
126
|
nl = expect_newline(@index + 3)
|
123
127
|
self.context = :multiline_string
|
124
|
-
@buffer = ''
|
128
|
+
@buffer = +''
|
125
129
|
traverse(3 + nl.length)
|
126
130
|
else
|
127
131
|
self.context = :string
|
128
|
-
@buffer = ''
|
132
|
+
@buffer = +''
|
129
133
|
traverse(1)
|
130
134
|
end
|
131
135
|
when '#'
|
@@ -134,14 +138,14 @@ module KDL
|
|
134
138
|
nl = expect_newline(@index + 4)
|
135
139
|
self.context = :multiline_rawstring
|
136
140
|
@rawstring_hashes = 1
|
137
|
-
@buffer = ''
|
141
|
+
@buffer = +''
|
138
142
|
traverse(4 + nl.length)
|
139
143
|
next
|
140
144
|
else
|
141
145
|
self.context = :rawstring
|
142
146
|
traverse(2)
|
143
147
|
@rawstring_hashes = 1
|
144
|
-
@buffer = ''
|
148
|
+
@buffer = +''
|
145
149
|
next
|
146
150
|
end
|
147
151
|
elsif self[@index + 1] == '#'
|
@@ -156,18 +160,18 @@ module KDL
|
|
156
160
|
nl = expect_newline(i + 3)
|
157
161
|
self.context = :multiline_rawstring
|
158
162
|
traverse(@rawstring_hashes + 3 + nl.length)
|
159
|
-
@buffer = ''
|
163
|
+
@buffer = +''
|
160
164
|
next
|
161
165
|
else
|
162
166
|
self.context = :rawstring
|
163
167
|
traverse(@rawstring_hashes + 1)
|
164
|
-
@buffer = ''
|
168
|
+
@buffer = +''
|
165
169
|
next
|
166
170
|
end
|
167
171
|
end
|
168
172
|
end
|
169
173
|
self.context = :keyword
|
170
|
-
@buffer = c
|
174
|
+
@buffer = +c
|
171
175
|
traverse(1)
|
172
176
|
when '-'
|
173
177
|
n = self[@index + 1]
|
@@ -184,16 +188,16 @@ module KDL
|
|
184
188
|
self.context = :ident
|
185
189
|
traverse(1)
|
186
190
|
end
|
187
|
-
@buffer = c
|
191
|
+
@buffer = +c
|
188
192
|
when /[0-9+]/
|
189
193
|
n = self[@index + 1]
|
190
194
|
if c == '0' && n =~ /[box]/
|
191
195
|
traverse(2)
|
192
|
-
@buffer = ''
|
196
|
+
@buffer = +''
|
193
197
|
self.context = integer_context(n)
|
194
198
|
else
|
195
199
|
self.context = :decimal
|
196
|
-
@buffer = c
|
200
|
+
@buffer = +c
|
197
201
|
traverse(1)
|
198
202
|
end
|
199
203
|
when '\\'
|
@@ -202,20 +206,20 @@ module KDL
|
|
202
206
|
if la[0] == :NEWLINE || la[0] == :EOF || (la[0] == :WS && (lan = t.next_token[0]) == :NEWLINE || lan == :EOF)
|
203
207
|
traverse_to(t.index)
|
204
208
|
@buffer = "#{c}#{la[1].value}"
|
205
|
-
@buffer
|
209
|
+
@buffer << "\n" if lan == :NEWLINE
|
206
210
|
self.context = :whitespace
|
207
211
|
else
|
208
212
|
raise_error "Unexpected '\\' (#{la[0]})"
|
209
213
|
end
|
210
214
|
when '='
|
211
215
|
self.context = :equals
|
212
|
-
@buffer = c
|
216
|
+
@buffer = +c
|
213
217
|
traverse(1)
|
214
218
|
when *SYMBOLS.keys
|
215
|
-
return token(SYMBOLS[c], c).tap { traverse(1) }
|
219
|
+
return token(SYMBOLS[c], -c).tap { traverse(1) }
|
216
220
|
when *NEWLINES, "\r"
|
217
221
|
nl = expect_newline
|
218
|
-
return token(:NEWLINE, nl).tap do
|
222
|
+
return token(:NEWLINE, -nl).tap do
|
219
223
|
traverse(nl.length)
|
220
224
|
end
|
221
225
|
when "/"
|
@@ -230,12 +234,12 @@ module KDL
|
|
230
234
|
return token(:SLASHDASH, '/-').tap { traverse(2) }
|
231
235
|
else
|
232
236
|
self.context = :ident
|
233
|
-
@buffer = c
|
237
|
+
@buffer = +c
|
234
238
|
traverse(1)
|
235
239
|
end
|
236
240
|
when *WHITESPACE
|
237
241
|
self.context = :whitespace
|
238
|
-
@buffer = c
|
242
|
+
@buffer = +c
|
239
243
|
traverse(1)
|
240
244
|
when nil
|
241
245
|
return [false, token(:EOF, :EOF)[1]] if @done
|
@@ -244,14 +248,14 @@ module KDL
|
|
244
248
|
return token(:EOF, :EOF)
|
245
249
|
when INITIAL_IDENTIFIER_CHARS
|
246
250
|
self.context = :ident
|
247
|
-
@buffer = c
|
251
|
+
@buffer = +c
|
248
252
|
traverse(1)
|
249
253
|
when '('
|
250
254
|
@type_context = true
|
251
|
-
return token(:LPAREN, c).tap { traverse(1) }
|
255
|
+
return token(:LPAREN, -c).tap { traverse(1) }
|
252
256
|
when ')'
|
253
257
|
@type_context = false
|
254
|
-
return token(:RPAREN, c).tap { traverse(1) }
|
258
|
+
return token(:RPAREN, -c).tap { traverse(1) }
|
255
259
|
else
|
256
260
|
raise_error "Unexpected character #{c.inspect}"
|
257
261
|
end
|
@@ -259,7 +263,7 @@ module KDL
|
|
259
263
|
case c
|
260
264
|
when IDENTIFIER_CHARS
|
261
265
|
traverse(1)
|
262
|
-
@buffer
|
266
|
+
@buffer << c
|
263
267
|
else
|
264
268
|
case @buffer
|
265
269
|
when 'true', 'false', 'null', 'inf', '-inf', 'nan'
|
@@ -267,14 +271,14 @@ module KDL
|
|
267
271
|
when /\A\.\d/
|
268
272
|
raise_error "Identifier cannot look like an illegal float"
|
269
273
|
else
|
270
|
-
return token(:IDENT,
|
274
|
+
return token(:IDENT, -@buffer)
|
271
275
|
end
|
272
276
|
end
|
273
277
|
when :keyword
|
274
278
|
case c
|
275
279
|
when /[a-z\-]/
|
276
280
|
traverse(1)
|
277
|
-
@buffer
|
281
|
+
@buffer << c
|
278
282
|
else
|
279
283
|
case @buffer
|
280
284
|
when '#true' then return token(:TRUE, true)
|
@@ -289,13 +293,13 @@ module KDL
|
|
289
293
|
when :string
|
290
294
|
case c
|
291
295
|
when '\\'
|
292
|
-
@buffer
|
296
|
+
@buffer << c
|
293
297
|
c2 = self[@index + 1]
|
294
|
-
@buffer
|
298
|
+
@buffer << c2
|
295
299
|
if c2.match?(NEWLINES_PATTERN)
|
296
300
|
i = 2
|
297
301
|
while self[@index + i]&.match?(NEWLINES_PATTERN)
|
298
|
-
@buffer
|
302
|
+
@buffer << self[@index + i]
|
299
303
|
i+=1
|
300
304
|
end
|
301
305
|
traverse(i)
|
@@ -303,31 +307,31 @@ module KDL
|
|
303
307
|
traverse(2)
|
304
308
|
end
|
305
309
|
when '"'
|
306
|
-
return token(:STRING, unescape(@buffer)).tap { traverse(1) }
|
310
|
+
return token(:STRING, -unescape(@buffer)).tap { traverse(1) }
|
307
311
|
when *NEWLINES, "\r"
|
308
312
|
raise_error "Unexpected NEWLINE in string literal"
|
309
313
|
when nil
|
310
314
|
raise_error "Unterminated string literal"
|
311
315
|
else
|
312
|
-
@buffer
|
316
|
+
@buffer << c
|
313
317
|
traverse(1)
|
314
318
|
end
|
315
319
|
when :multiline_string
|
316
320
|
case c
|
317
321
|
when '\\'
|
318
|
-
@buffer
|
319
|
-
@buffer
|
322
|
+
@buffer << c
|
323
|
+
@buffer << self[@index + 1]
|
320
324
|
traverse(2)
|
321
325
|
when '"'
|
322
326
|
if self[@index + 1] == '"' && self[@index + 2] == '"'
|
323
|
-
return token(:STRING, unescape_non_ws(dedent(unescape_ws(@buffer)))).tap { traverse(3) }
|
327
|
+
return token(:STRING, -unescape_non_ws(dedent(unescape_ws(@buffer)))).tap { traverse(3) }
|
324
328
|
end
|
325
|
-
@buffer
|
329
|
+
@buffer << c
|
326
330
|
traverse(1)
|
327
331
|
when nil
|
328
332
|
raise_error "Unterminated multi-line string literal"
|
329
333
|
else
|
330
|
-
@buffer
|
334
|
+
@buffer << c
|
331
335
|
traverse(1)
|
332
336
|
end
|
333
337
|
when :rawstring
|
@@ -338,13 +342,13 @@ module KDL
|
|
338
342
|
h = 0
|
339
343
|
h += 1 while self[@index + 1 + h] == '#' && h < @rawstring_hashes
|
340
344
|
if h == @rawstring_hashes
|
341
|
-
return token(:RAWSTRING,
|
345
|
+
return token(:RAWSTRING, -@buffer).tap { traverse(1 + h) }
|
342
346
|
end
|
343
347
|
when *NEWLINES, "\r"
|
344
348
|
raise_error "Unexpected NEWLINE in rawstring literal"
|
345
349
|
end
|
346
350
|
|
347
|
-
@buffer
|
351
|
+
@buffer << c
|
348
352
|
traverse(1)
|
349
353
|
when :multiline_rawstring
|
350
354
|
raise_error "Unterminated multi-line rawstring literal" if c.nil?
|
@@ -353,17 +357,17 @@ module KDL
|
|
353
357
|
h = 1
|
354
358
|
h += 1 while self[@index + 3 + h] == '#' && h < @rawstring_hashes
|
355
359
|
if h == @rawstring_hashes
|
356
|
-
return token(:RAWSTRING, dedent(@buffer)).tap { traverse(3 + h) }
|
360
|
+
return token(:RAWSTRING, -dedent(@buffer)).tap { traverse(3 + h) }
|
357
361
|
end
|
358
362
|
end
|
359
363
|
|
360
|
-
@buffer
|
364
|
+
@buffer << c
|
361
365
|
traverse(1)
|
362
366
|
when :decimal
|
363
367
|
case c
|
364
368
|
when /[0-9.\-+_eE]/
|
365
369
|
traverse(1)
|
366
|
-
@buffer
|
370
|
+
@buffer << c
|
367
371
|
else
|
368
372
|
return parse_decimal(@buffer)
|
369
373
|
end
|
@@ -371,7 +375,7 @@ module KDL
|
|
371
375
|
case c
|
372
376
|
when /[0-9a-fA-F_]/
|
373
377
|
traverse(1)
|
374
|
-
@buffer
|
378
|
+
@buffer << c
|
375
379
|
else
|
376
380
|
return parse_hexadecimal(@buffer)
|
377
381
|
end
|
@@ -379,7 +383,7 @@ module KDL
|
|
379
383
|
case c
|
380
384
|
when /[0-7_]/
|
381
385
|
traverse(1)
|
382
|
-
@buffer
|
386
|
+
@buffer << c
|
383
387
|
else
|
384
388
|
return parse_octal(@buffer)
|
385
389
|
end
|
@@ -387,7 +391,7 @@ module KDL
|
|
387
391
|
case c
|
388
392
|
when /[01_]/
|
389
393
|
traverse(1)
|
390
|
-
@buffer
|
394
|
+
@buffer << c
|
391
395
|
else
|
392
396
|
return parse_binary(@buffer)
|
393
397
|
end
|
@@ -419,10 +423,10 @@ module KDL
|
|
419
423
|
when :whitespace
|
420
424
|
if WHITESPACE.include?(c)
|
421
425
|
traverse(1)
|
422
|
-
@buffer
|
426
|
+
@buffer << c
|
423
427
|
elsif c == '='
|
424
428
|
self.context = :equals
|
425
|
-
@buffer
|
429
|
+
@buffer << c
|
426
430
|
traverse(1)
|
427
431
|
elsif c == "/" && self[@index + 1] == '*'
|
428
432
|
self.context = :multi_line_comment
|
@@ -433,22 +437,22 @@ module KDL
|
|
433
437
|
la = t.next_token
|
434
438
|
if la[0] == :NEWLINE || la[0] == :EOF || (la[0] == :WS && (lan = t.next_token[0]) == :NEWLINE || lan == :EOF)
|
435
439
|
traverse_to(t.index)
|
436
|
-
@buffer
|
437
|
-
@buffer
|
440
|
+
@buffer << "#{c}#{la[1].value}"
|
441
|
+
@buffer << "\n" if lan == :NEWLINE
|
438
442
|
else
|
439
443
|
raise_error "Unexpected '\\' (#{la[0]})"
|
440
444
|
end
|
441
445
|
else
|
442
|
-
return token(:WS,
|
446
|
+
return token(:WS, -@buffer)
|
443
447
|
end
|
444
448
|
when :equals
|
445
449
|
t = Tokenizer.new(@str, @index)
|
446
450
|
la = t.next_token
|
447
451
|
if la[0] == :WS
|
448
|
-
@buffer
|
452
|
+
@buffer << la[1].value
|
449
453
|
traverse_to(t.index)
|
450
454
|
end
|
451
|
-
return token(:EQUALS,
|
455
|
+
return token(:EQUALS, -@buffer)
|
452
456
|
else
|
453
457
|
# :nocov:
|
454
458
|
raise_error "Unknown context `#{@context}'"
|
@@ -482,8 +486,12 @@ module KDL
|
|
482
486
|
traverse(i - @index)
|
483
487
|
end
|
484
488
|
|
485
|
-
def raise_error(
|
486
|
-
|
489
|
+
def raise_error(error)
|
490
|
+
case error
|
491
|
+
when String then raise Error.new(error, @line, @column)
|
492
|
+
when Error then raise error
|
493
|
+
else raise Error.new(error.message, @line, @column)
|
494
|
+
end
|
487
495
|
end
|
488
496
|
|
489
497
|
def context=(val)
|
@@ -538,11 +546,11 @@ module KDL
|
|
538
546
|
return parse_float(s) if s =~ /[.E]/i
|
539
547
|
|
540
548
|
token(:INTEGER, Integer(munch_underscores(s), 10), format: '%d')
|
541
|
-
rescue
|
549
|
+
rescue => e
|
542
550
|
if s[0] =~ INITIAL_IDENTIFIER_CHARS && s[1..-1].each_char.all? { |c| c =~ IDENTIFIER_CHARS }
|
543
|
-
token(:IDENT, s)
|
551
|
+
token(:IDENT, -s)
|
544
552
|
else
|
545
|
-
|
553
|
+
raise_error(e)
|
546
554
|
end
|
547
555
|
end
|
548
556
|
|
@@ -564,14 +572,20 @@ module KDL
|
|
564
572
|
|
565
573
|
def parse_hexadecimal(s)
|
566
574
|
token(:INTEGER, Integer(munch_underscores(s), 16))
|
575
|
+
rescue ArgumentError => e
|
576
|
+
raise_error(e)
|
567
577
|
end
|
568
578
|
|
569
579
|
def parse_octal(s)
|
570
580
|
token(:INTEGER, Integer(munch_underscores(s), 8))
|
581
|
+
rescue ArgumentError => e
|
582
|
+
raise_error(e)
|
571
583
|
end
|
572
584
|
|
573
585
|
def parse_binary(s)
|
574
586
|
token(:INTEGER, Integer(munch_underscores(s), 2))
|
587
|
+
rescue ArgumentError => e
|
588
|
+
raise_error(e)
|
575
589
|
end
|
576
590
|
|
577
591
|
def munch_underscores(s)
|
@@ -599,8 +613,8 @@ module KDL
|
|
599
613
|
.gsub(rgx) { |m| replace_esc(m) }
|
600
614
|
.gsub(/\\u\{[0-9a-fA-F]{0,6}\}/) do |m|
|
601
615
|
i = Integer(m[3..-2], 16)
|
602
|
-
if i < 0 || i > 0x10FFFF
|
603
|
-
raise_error "Invalid code point #{
|
616
|
+
if i < 0 || i > 0x10FFFF || (0xD800..0xDFFF).include?(i)
|
617
|
+
raise_error "Invalid code point #{m}"
|
604
618
|
end
|
605
619
|
i.chr(Encoding::UTF_8)
|
606
620
|
end
|
@@ -631,9 +645,9 @@ module KDL
|
|
631
645
|
end
|
632
646
|
return "" if lines.empty?
|
633
647
|
raise_error "Invalid multiline string final line" unless indent.match?(WS_STAR)
|
634
|
-
valid = /\A
|
648
|
+
valid = /\A#{Regexp.escape(indent)}(.*)/
|
635
649
|
|
636
|
-
lines.map
|
650
|
+
lines.map do |line|
|
637
651
|
case line
|
638
652
|
when WS_STAR then ""
|
639
653
|
when valid then $1
|
data/lib/kdl/types/base64.rb
CHANGED
data/lib/kdl/types/country.rb
CHANGED
data/lib/kdl/types/currency.rb
CHANGED
data/lib/kdl/types/date_time.rb
CHANGED
data/lib/kdl/types/decimal.rb
CHANGED
data/lib/kdl/types/duration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../hostname/validator'
|
2
4
|
|
3
5
|
module KDL
|
@@ -11,7 +13,7 @@ module KDL
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def parse
|
14
|
-
local = ''
|
16
|
+
local = +''
|
15
17
|
unicode_domain = nil
|
16
18
|
domain = nil
|
17
19
|
context = :start
|
@@ -23,7 +25,7 @@ module KDL
|
|
23
25
|
when :part
|
24
26
|
case context
|
25
27
|
when :start, :after_dot
|
26
|
-
local
|
28
|
+
local << value
|
27
29
|
context = :after_part
|
28
30
|
else
|
29
31
|
raise ArgumentError, "invalid email #{@string} (unexpected part #{value} at #{context})"
|
@@ -31,7 +33,7 @@ module KDL
|
|
31
33
|
when :dot
|
32
34
|
case context
|
33
35
|
when :after_part
|
34
|
-
local
|
36
|
+
local << value
|
35
37
|
context = :after_dot
|
36
38
|
else
|
37
39
|
raise ArgumentError, "invalid email #{@string} (unexpected dot at #{context})"
|
@@ -91,7 +93,7 @@ module KDL
|
|
91
93
|
end
|
92
94
|
end
|
93
95
|
@context = nil
|
94
|
-
@buffer = ''
|
96
|
+
@buffer = +''
|
95
97
|
loop do
|
96
98
|
c = @string[@index]
|
97
99
|
return [:end, nil] if c.nil?
|
@@ -111,7 +113,7 @@ module KDL
|
|
111
113
|
@index += 1
|
112
114
|
when local_part_chars
|
113
115
|
@context = :part
|
114
|
-
@buffer
|
116
|
+
@buffer << c
|
115
117
|
@index += 1
|
116
118
|
else
|
117
119
|
raise ArgumentError, "invalid email #{@string} (unexpected #{c})"
|
@@ -119,7 +121,7 @@ module KDL
|
|
119
121
|
when :part
|
120
122
|
case c
|
121
123
|
when local_part_chars
|
122
|
-
@buffer
|
124
|
+
@buffer << c
|
123
125
|
@index += 1
|
124
126
|
when '.', '@'
|
125
127
|
return [:part, @buffer]
|
@@ -135,7 +137,7 @@ module KDL
|
|
135
137
|
@index += 1
|
136
138
|
return [:part, @buffer]
|
137
139
|
else
|
138
|
-
@buffer
|
140
|
+
@buffer << c
|
139
141
|
@index += 1
|
140
142
|
end
|
141
143
|
end
|
data/lib/kdl/types/email.rb
CHANGED
data/lib/kdl/types/hostname.rb
CHANGED
data/lib/kdl/types/ip.rb
CHANGED
data/lib/kdl/types/irl/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module KDL
|
2
4
|
module Types
|
3
5
|
class IRLReference < Value::Custom
|
@@ -96,13 +98,13 @@ module KDL
|
|
96
98
|
end
|
97
99
|
|
98
100
|
def self.build_uri_string(scheme, auth, domain, path, search, hash)
|
99
|
-
string = ''
|
100
|
-
string
|
101
|
-
string
|
102
|
-
string
|
103
|
-
string
|
104
|
-
string
|
105
|
-
string
|
101
|
+
string = +''
|
102
|
+
string << "#{scheme}://" if scheme
|
103
|
+
string << auth if auth
|
104
|
+
string << domain if domain
|
105
|
+
string << path if path
|
106
|
+
string << "?#{search}" if search
|
107
|
+
string << "##{hash}" if hash
|
106
108
|
string
|
107
109
|
end
|
108
110
|
end
|
data/lib/kdl/types/irl.rb
CHANGED
data/lib/kdl/types/regex.rb
CHANGED