kdl 1.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -0
  4. data/.gitmodules +4 -0
  5. data/Gemfile +6 -1
  6. data/README.md +51 -7
  7. data/Rakefile +6 -1
  8. data/bin/kdl +1 -1
  9. data/kdl.gemspec +2 -2
  10. data/lib/kdl/document.rb +58 -2
  11. data/lib/kdl/kdl.tab.rb +303 -228
  12. data/lib/kdl/kdl.yy +57 -49
  13. data/lib/kdl/node.rb +113 -12
  14. data/lib/kdl/parser_common.rb +26 -0
  15. data/lib/kdl/string_dumper.rb +30 -33
  16. data/lib/kdl/tokenizer.rb +350 -113
  17. data/lib/kdl/types/base64.rb +1 -1
  18. data/lib/kdl/types/country/iso3166_countries.rb +1 -1
  19. data/lib/kdl/types/country/iso3166_subdivisions.rb +1 -1
  20. data/lib/kdl/types/country.rb +2 -2
  21. data/lib/kdl/types/currency/iso4217_currencies.rb +1 -1
  22. data/lib/kdl/types/currency.rb +1 -1
  23. data/lib/kdl/types/date_time.rb +3 -3
  24. data/lib/kdl/types/decimal.rb +1 -1
  25. data/lib/kdl/types/duration/iso8601_parser.rb +1 -1
  26. data/lib/kdl/types/duration.rb +1 -1
  27. data/lib/kdl/types/email/parser.rb +2 -2
  28. data/lib/kdl/types/email.rb +1 -1
  29. data/lib/kdl/types/hostname/validator.rb +1 -1
  30. data/lib/kdl/types/hostname.rb +1 -1
  31. data/lib/kdl/types/ip.rb +1 -1
  32. data/lib/kdl/types/irl/parser.rb +1 -1
  33. data/lib/kdl/types/irl.rb +1 -1
  34. data/lib/kdl/types/regex.rb +1 -1
  35. data/lib/kdl/types/url.rb +1 -1
  36. data/lib/kdl/types/url_template.rb +1 -1
  37. data/lib/kdl/types/uuid.rb +1 -1
  38. data/lib/kdl/v1/document.rb +17 -0
  39. data/lib/kdl/v1/kdl.tab.rb +594 -0
  40. data/lib/kdl/v1/kdl.yy +89 -0
  41. data/lib/kdl/v1/node.rb +30 -0
  42. data/lib/kdl/v1/string_dumper.rb +28 -0
  43. data/lib/kdl/v1/tokenizer.rb +296 -0
  44. data/lib/kdl/v1/value.rb +89 -0
  45. data/lib/kdl/v1.rb +11 -0
  46. data/lib/kdl/value.rb +81 -12
  47. data/lib/kdl/version.rb +1 -1
  48. data/lib/kdl.rb +40 -1
  49. metadata +13 -4
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class Currency < Value
3
+ class Currency < Value::Custom
4
4
  # From https://en.wikipedia.org/wiki/ISO_4217#Active_codes
5
5
  CURRENCIES = {
6
6
  'AED' => { numeric_code: 784, minor_unit: 2, name: 'United Arab Emirates dirham' }.freeze,
@@ -2,7 +2,7 @@ require 'kdl/types/currency/iso4217_currencies'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class Currency < Value
5
+ class Currency < Value::Custom
6
6
  attr_reader :numeric_code, :minor_unit, :name
7
7
 
8
8
  def initialize(value, format: nil, type: 'currency')
@@ -2,7 +2,7 @@ require 'time'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class DateTime < Value
5
+ class DateTime < Value::Custom
6
6
  def self.call(value, type = 'date-time')
7
7
  return nil unless value.is_a? ::KDL::Value::String
8
8
 
@@ -12,7 +12,7 @@ module KDL
12
12
  end
13
13
  MAPPING['date-time'] = DateTime
14
14
 
15
- class Time < Value
15
+ class Time < Value::Custom
16
16
  # TODO: this is not a perfect ISO8601 time string
17
17
  REGEX = /^T?((?:2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?(?:Z|[+-]\d\d:\d\d)?)$/
18
18
 
@@ -28,7 +28,7 @@ module KDL
28
28
  end
29
29
  MAPPING['time'] = Time
30
30
 
31
- class Date < Value
31
+ class Date < Value::Custom
32
32
  def self.call(value, type = 'date')
33
33
  return nil unless value.is_a? ::KDL::Value::String
34
34
 
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class Decimal < Value
3
+ class Decimal < Value::Custom
4
4
  def self.call(value, type = 'decimal')
5
5
  return nil unless value.is_a? ::KDL::Value::String
6
6
 
@@ -25,7 +25,7 @@ require 'strscan'
25
25
 
26
26
  module KDL
27
27
  module Types
28
- class Duration < Value
28
+ class Duration < Value::Custom
29
29
  # Parses a string formatted according to ISO 8601 Duration into the hash.
30
30
  #
31
31
  # See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
@@ -2,7 +2,7 @@ require 'kdl/types/duration/iso8601_parser'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class Duration < Value
5
+ class Duration < Value::Custom
6
6
  attr_reader :years, :months, :weeks, :days, :hours, :minutes, :seconds
7
7
 
8
8
  def initialize(parts = {}, format: nil, type: 'duration')
@@ -2,7 +2,7 @@ require_relative '../hostname/validator'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class Email < Value
5
+ class Email < Value::Custom
6
6
  class Parser
7
7
  def initialize(string, idn: false)
8
8
  @string = string
@@ -71,7 +71,7 @@ module KDL
71
71
 
72
72
  class Tokenizer
73
73
  LOCAL_PART_ASCII = %r{[a-zA-Z0-9!#$%&'*+\-/=?^_`{|}~]}.freeze
74
- LOCAL_PART_IDN = /[^\x00-\x1f\s".@]/.freeze
74
+ LOCAL_PART_IDN = /[^\x00-\x1f ".@]/.freeze
75
75
 
76
76
  def initialize(string, idn: false)
77
77
  @string = string
@@ -2,7 +2,7 @@ require_relative './email/parser'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class Email < Value
5
+ class Email < Value::Custom
6
6
  attr_reader :local, :domain
7
7
 
8
8
  def initialize(value, local:, domain:, **kwargs)
@@ -2,7 +2,7 @@ require 'simpleidn'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class Hostname < Value
5
+ class Hostname < Value::Custom
6
6
  class Validator
7
7
  PART_RGX = /^[a-z0-9_][a-z0-9_\-]{0,62}$/i
8
8
 
@@ -2,7 +2,7 @@ require_relative './hostname/validator'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class Hostname < Value
5
+ class Hostname < Value::Custom
6
6
  def self.call(value, type = 'hostname')
7
7
  return nil unless value.is_a? ::KDL::Value::String
8
8
 
data/lib/kdl/types/ip.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class IP < Value
3
+ class IP < Value::Custom
4
4
  def self.call(value, type = ip_type)
5
5
  return nil unless value.is_a? ::KDL::Value::String
6
6
 
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class IRLReference < Value
3
+ class IRLReference < Value::Custom
4
4
  class Parser
5
5
  RGX = /^(?:(?:([a-z][a-z0-9+.\-]+)):\/\/([^@]+@)?([^\/?#]+)?)?(\/?[^?#]*)?(?:\?([^#]*))?(?:#(.*))?$/i.freeze
6
6
  PERCENT_RGX = /%[a-f0-9]{2}/i.freeze
data/lib/kdl/types/irl.rb CHANGED
@@ -2,7 +2,7 @@ require_relative './irl/parser'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class IRLReference < Value
5
+ class IRLReference < Value::Custom
6
6
  attr_reader :unicode_value,
7
7
  :unicode_domain,
8
8
  :unicode_path,
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class Regex < Value
3
+ class Regex < Value::Custom
4
4
  def self.call(value, type = 'regex')
5
5
  return nil unless value.is_a? ::KDL::Value::String
6
6
 
data/lib/kdl/types/url.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class URLReference < Value
3
+ class URLReference < Value::Custom
4
4
  def self.call(value, type = 'url-reference')
5
5
  return nil unless value.is_a? ::KDL::Value::String
6
6
 
@@ -2,7 +2,7 @@ require 'uri'
2
2
 
3
3
  module KDL
4
4
  module Types
5
- class URLTemplate < Value
5
+ class URLTemplate < Value::Custom
6
6
  UNRESERVED = /[a-zA-Z0-9\-._~]/.freeze
7
7
  RESERVED = %r{[:/?#\[\]@!$&'()*+,;=]}.freeze
8
8
 
@@ -1,6 +1,6 @@
1
1
  module KDL
2
2
  module Types
3
- class UUID < Value
3
+ class UUID < Value::Custom
4
4
  RGX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
5
5
 
6
6
  def self.call(value, type = 'uuid')
@@ -0,0 +1,17 @@
1
+ module KDL
2
+ module V1
3
+ class Document < ::KDL::Document
4
+ def version
5
+ 1
6
+ end
7
+
8
+ def to_v1
9
+ self
10
+ end
11
+
12
+ def to_v2
13
+ ::KDL::Document.new(nodes.map(&:to_v2))
14
+ end
15
+ end
16
+ end
17
+ end