kdl 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -1
  3. data/README.md +17 -1
  4. data/lib/kdl/document.rb +2 -0
  5. data/lib/kdl/error.rb +24 -0
  6. data/lib/kdl/kdl.tab.rb +128 -129
  7. data/lib/kdl/kdl.yy +7 -7
  8. data/lib/kdl/node.rb +7 -5
  9. data/lib/kdl/parser_common.rb +3 -1
  10. data/lib/kdl/string_dumper.rb +2 -0
  11. data/lib/kdl/tokenizer.rb +79 -65
  12. data/lib/kdl/types/base64.rb +2 -0
  13. data/lib/kdl/types/country/iso3166_countries.rb +2 -0
  14. data/lib/kdl/types/country/iso3166_subdivisions.rb +2 -0
  15. data/lib/kdl/types/country.rb +2 -0
  16. data/lib/kdl/types/currency/iso4217_currencies.rb +2 -0
  17. data/lib/kdl/types/currency.rb +2 -0
  18. data/lib/kdl/types/date_time.rb +2 -0
  19. data/lib/kdl/types/decimal.rb +2 -0
  20. data/lib/kdl/types/duration/iso8601_parser.rb +2 -0
  21. data/lib/kdl/types/duration.rb +2 -0
  22. data/lib/kdl/types/email/parser.rb +9 -7
  23. data/lib/kdl/types/email.rb +2 -0
  24. data/lib/kdl/types/hostname/validator.rb +2 -0
  25. data/lib/kdl/types/hostname.rb +2 -0
  26. data/lib/kdl/types/ip.rb +2 -0
  27. data/lib/kdl/types/irl/parser.rb +9 -7
  28. data/lib/kdl/types/irl.rb +2 -0
  29. data/lib/kdl/types/regex.rb +2 -0
  30. data/lib/kdl/types/url.rb +2 -0
  31. data/lib/kdl/types/url_template.rb +5 -3
  32. data/lib/kdl/types/uuid.rb +2 -0
  33. data/lib/kdl/types.rb +2 -0
  34. data/lib/kdl/v1/document.rb +2 -0
  35. data/lib/kdl/v1/node.rb +2 -0
  36. data/lib/kdl/v1/string_dumper.rb +2 -0
  37. data/lib/kdl/v1/tokenizer.rb +33 -31
  38. data/lib/kdl/v1/value.rb +2 -0
  39. data/lib/kdl/v1.rb +2 -0
  40. data/lib/kdl/value.rb +6 -3
  41. data/lib/kdl/version.rb +3 -1
  42. data/lib/kdl.rb +9 -2
  43. metadata +4 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f41fc74596026506785cc654df47d91fcd5d0f067e8438cb5a55576076368ca5
4
- data.tar.gz: 0a32c65029c336f01a39cdab2e5259fe366ac5439b96b408da9f31b6d44ddf9d
3
+ metadata.gz: 323bc0f1637f5dea4aaa671d7582c87118d8a7500557fbbec5907d34082d0914
4
+ data.tar.gz: abd85e1a66342b328ad9da3946a14565ee300a0f5e77c5c5418cbc931cf8fe38
5
5
  SHA512:
6
- metadata.gz: 7d67ae26465031d210157ac38393084f6aa65863022934981054d5b6806c0e92b11344002ae12e77fecb4c0017fbd38dda03bf0c6cf60c93a917e98f427bf2c5
7
- data.tar.gz: 0ade99c140539aa3e1c167019967985cd4bf91df1283a975ca7d6f12c9ab6f86fb1c657bc31592eff0df7d71a3e003010eb77d91df69601de4ea7d1cd13eba1f
6
+ metadata.gz: 9fafe1a9343387a093c324f84cccd47378a635c950f9892b9456d23f2c75fe2341ebb68ea09e0043b0672430fc0c799fb13263447ddb4586539cd5f306357c4b
7
+ data.tar.gz: 3cf0863f0e7751890f394f7f5d759adf980ca7b4fec872c40a1b75f71a08e380681bc8ed93e917567bbab337281b4c03a1a8f34760bd9fa66aefd67187a59a0e
@@ -15,9 +15,10 @@ on:
15
15
 
16
16
  jobs:
17
17
  test:
18
+ continue-on-error: ${{ matrix.ruby == 'head' }}
18
19
  strategy:
19
20
  matrix:
20
- ruby: [3.1, 3.2, 3.3, head]
21
+ ruby: [3.1, 3.2, 3.3, 3.4, head]
21
22
 
22
23
  runs-on: ubuntu-latest
23
24
 
data/README.md CHANGED
@@ -66,12 +66,20 @@ The resulting document will also serialize back to the same version it was parse
66
66
  KDL.parse(a_string, output_version: 2)
67
67
  ```
68
68
 
69
- This allows you to to convert document between versions:
69
+ This allows you to to convert documents between versions:
70
70
 
71
71
  ```ruby
72
72
  KDL.parse('foo "bar" true', version: 1, output_version: 2).to_s #=> 'foo bar #true'
73
73
  ```
74
74
 
75
+ You can also convert an already parsed document between versions with `to_v1` and `to_v2`:
76
+
77
+ ```ruby
78
+ doc = KDL.parse('foo "bar" true', version: 1)
79
+ doc.version #=> 1
80
+ doc.to_v2.to_s #=> 'foo bar #true'
81
+ ```
82
+
75
83
  You can also set the default version globally:
76
84
 
77
85
  ```ruby
@@ -79,6 +87,14 @@ KDL.default_version = 2
79
87
  KDL.default_output_version = 2
80
88
  ```
81
89
 
90
+ You can still force automatic version detection with `auto_parse`:
91
+
92
+ ```ruby
93
+ KDL.default_version = 2
94
+ KDL.parse('foo "bar" true') #=> Error
95
+ KDL.auto_parse('foo "bar" true') #=> KDL::V1::Document
96
+ ```
97
+
82
98
  Version directives are also respected:
83
99
 
84
100
  ```ruby
data/lib/kdl/document.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KDL
2
4
  class Document
3
5
  include Enumerable
data/lib/kdl/error.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDL
4
+ class Error < StandardError; end
5
+
6
+ class VersionMismatchError < Error
7
+ attr_reader :version, :parser_version
8
+
9
+ def initialize(message, version = nil, parser_version = nil)
10
+ super(message)
11
+ @version = version
12
+ @parser_version = parser_version
13
+ end
14
+ end
15
+
16
+ class UnsupportedVersionError < Error
17
+ attr_reader :version
18
+
19
+ def initialize(message, version = nil)
20
+ super(message)
21
+ @version = version
22
+ end
23
+ end
24
+ end
data/lib/kdl/kdl.tab.rb CHANGED
@@ -29,98 +29,100 @@ module_eval(<<'...end kdl.yy/module_eval...', 'kdl.yy', 78)
29
29
  ##### State transition tables begin ###
30
30
 
31
31
  racc_action_table = [
32
- 20, 21, 22, 20, 21, 22, 20, 21, 22, 9,
33
- 38, 38, 19, -64, 5, 6, 26, 18, 19, 18,
34
- 18, 38, 7, 18, 56, 57, 58, 62, 63, 66,
35
- 67, 65, 38, 38, 38, -64, 19, 20, 21, 22,
36
- 68, 18, 18, -59, 38, 5, 6, -40, 86, 19,
37
- 20, 21, 22, 7, 18, -41, 20, 21, 22, -42,
38
- 38, 88, 19, 76, 43, 6, 38, 18, 19, 18,
39
- 89, 38, 7, 56, 57, 58, 62, 63, 66, 67,
40
- 65, 43, 6, 93, 94, 19, 20, 21, 22, 7,
41
- 78, 79, 80, 62, 63, 66, 67, 65, 38, 38,
42
- 38, 38, 19, 5, 6, 5, 6, 18, 18, 18,
43
- 18, 7, 30, 7, 5, 6, 5, 6, 43, 6,
44
- 5, 6, 7, nil, 7, nil, 7, nil, 7, 5,
45
- 6, 5, 6, 43, 6, 43, 6, 7, nil, 7,
46
- 30, 7, 30, 7, 78, 79, 80, 62, 63, 66,
47
- 67, 65 ]
32
+ 20, 21, 22, 9, 33, 26, 20, 21, 22, 33,
33
+ 33, 33, 19, 18, 5, 6, 33, 18, 19, 18,
34
+ 18, 33, 7, 18, 48, 49, 50, 54, 55, 58,
35
+ 59, 57, 33, 33, -63, -63, 19, 20, 21, 22,
36
+ 71, 18, 18, -39, -40, 5, 6, -41, 85, 19,
37
+ 20, 21, 22, 7, 18, 73, 20, 21, 22, 33,
38
+ 33, 87, 19, 83, 5, 6, 33, 18, 19, 18,
39
+ 91, 92, 7, 48, 49, 50, 54, 55, 58, 59,
40
+ 57, 70, 6, nil, 33, 19, -54, -54, nil, 7,
41
+ 75, 76, 77, 54, 55, 58, 59, 57, 33, 33,
42
+ nil, nil, 19, 5, 6, 5, 6, 18, 18, 5,
43
+ 6, 7, 30, 7, 5, 6, nil, 7, 5, 6,
44
+ 5, 6, 7, 70, 6, nil, 7, nil, 7, 5,
45
+ 6, 7, 70, 6, 70, 6, nil, 7, nil, 30,
46
+ 7, 30, 7, 75, 76, 77, 54, 55, 58, 59,
47
+ 57, 20, 21, 22, 20, 21, 22 ]
48
48
 
49
49
  racc_action_check = [
50
- 2, 2, 2, 14, 14, 14, 3, 3, 3, 1,
51
- 32, 15, 2, 15, 3, 3, 9, 2, 3, 32,
52
- 15, 19, 3, 3, 34, 34, 34, 34, 34, 34,
53
- 34, 34, 34, 33, 43, 33, 34, 81, 81, 81,
54
- 35, 34, 33, 43, 38, 81, 81, 56, 81, 81,
55
- 82, 82, 82, 81, 81, 57, 17, 17, 17, 58,
56
- 47, 82, 82, 59, 17, 17, 72, 82, 17, 47,
57
- 83, 89, 17, 53, 53, 53, 53, 53, 53, 53,
58
- 53, 53, 53, 90, 91, 53, 44, 44, 44, 53,
59
- 76, 76, 76, 76, 76, 76, 76, 76, 48, 49,
60
- 50, 73, 76, 0, 0, 12, 12, 48, 49, 50,
61
- 73, 0, 12, 12, 28, 28, 30, 30, 36, 36,
62
- 42, 42, 28, nil, 30, nil, 36, nil, 42, 46,
63
- 46, 68, 68, 85, 85, 87, 87, 46, nil, 68,
64
- 85, 85, 87, 87, 61, 61, 61, 61, 61, 61,
65
- 61, 61 ]
50
+ 2, 2, 2, 1, 40, 9, 3, 3, 3, 15,
51
+ 46, 62, 2, 40, 3, 3, 19, 2, 3, 46,
52
+ 62, 33, 3, 3, 32, 32, 32, 32, 32, 32,
53
+ 32, 32, 32, 41, 32, 41, 32, 80, 80, 80,
54
+ 45, 32, 41, 48, 49, 80, 80, 50, 80, 80,
55
+ 81, 81, 81, 80, 80, 51, 17, 17, 17, 61,
56
+ 64, 81, 81, 78, 17, 17, 83, 81, 17, 64,
57
+ 89, 90, 17, 43, 43, 43, 43, 43, 43, 43,
58
+ 43, 43, 43, nil, 70, 43, 70, 70, nil, 43,
59
+ 73, 73, 73, 73, 73, 73, 73, 73, 65, 79,
60
+ nil, nil, 73, 0, 0, 12, 12, 65, 79, 28,
61
+ 28, 0, 12, 12, 30, 30, nil, 28, 35, 35,
62
+ 39, 39, 30, 63, 63, nil, 35, nil, 39, 71,
63
+ 71, 63, 84, 84, 86, 86, nil, 71, nil, 84,
64
+ 84, 86, 86, 53, 53, 53, 53, 53, 53, 53,
65
+ 53, 14, 14, 14, 36, 36, 36 ]
66
66
 
67
67
  racc_action_pointer = [
68
- 93, 9, -2, 4, nil, nil, nil, nil, nil, 16,
69
- nil, nil, 95, nil, 1, 1, nil, 54, nil, 11,
70
- nil, nil, nil, nil, nil, nil, nil, nil, 104, nil,
71
- 106, nil, 0, 23, 22, 28, 108, nil, 34, nil,
72
- nil, nil, 110, 24, 84, nil, 119, 50, 88, 89,
73
- 90, nil, nil, 71, nil, nil, 31, 39, 43, 47,
74
- nil, 142, nil, nil, nil, nil, nil, nil, 121, nil,
75
- nil, nil, 56, 91, nil, nil, 88, nil, nil, nil,
76
- nil, 35, 48, 55, nil, 123, nil, 125, nil, 61,
77
- 70, 71, nil, nil, nil ]
68
+ 93, 3, -2, 4, nil, nil, nil, nil, nil, 5,
69
+ nil, nil, 95, nil, 149, -1, nil, 54, nil, 6,
70
+ nil, nil, nil, nil, nil, nil, nil, nil, 99, nil,
71
+ 104, nil, 22, 11, nil, 108, 152, nil, nil, 110,
72
+ -6, 23, nil, 71, nil, 28, 0, nil, 27, 28,
73
+ 31, 39, nil, 141, nil, nil, nil, nil, nil, nil,
74
+ nil, 49, 1, 113, 50, 88, nil, nil, nil, nil,
75
+ 74, 119, nil, 88, nil, nil, nil, nil, 48, 89,
76
+ 35, 48, nil, 56, 122, nil, 124, nil, nil, 57,
77
+ 58, nil, nil ]
78
78
 
79
79
  racc_action_default = [
80
- -64, -65, -1, -2, -3, -59, -60, -61, -62, -65,
81
- -6, -7, -65, -9, -65, -11, -17, -65, -36, -64,
82
- -40, -41, -42, -4, -5, -63, 95, -8, -32, -33,
83
- -34, -10, -12, -13, -22, -65, -64, -30, -55, -57,
84
- -23, -37, -38, -55, -65, -58, -35, -15, -65, -14,
85
- -58, -31, -18, -64, -20, -29, -46, -47, -48, -65,
86
- -44, -65, -49, -50, -51, -52, -53, -54, -64, -28,
87
- -37, -56, -64, -16, -19, -21, -65, -45, -46, -47,
88
- -48, -65, -65, -65, -43, -64, -25, -64, -24, -64,
89
- -65, -65, -39, -27, -26 ]
80
+ -63, -64, -1, -2, -3, -58, -59, -60, -61, -64,
81
+ -6, -7, -64, -9, -64, -11, -17, -64, -36, -63,
82
+ -39, -40, -41, -4, -5, -62, 93, -8, -32, -33,
83
+ -34, -10, -22, -54, -23, -37, -64, -56, -57, -35,
84
+ -12, -13, -18, -63, -20, -64, -57, -30, -45, -46,
85
+ -47, -64, -43, -64, -48, -49, -50, -51, -52, -53,
86
+ -55, -63, -15, -63, -64, -14, -31, -19, -21, -28,
87
+ -58, -63, -29, -64, -44, -45, -46, -47, -64, -16,
88
+ -64, -64, -42, -63, -63, -25, -63, -24, -38, -64,
89
+ -64, -27, -26 ]
90
90
 
91
91
  racc_goto_table = [
92
- 17, 17, 44, 23, 24, 25, 2, 61, 52, 4,
93
- 85, 87, 1, 31, 51, 55, 77, 40, 34, 54,
94
- 41, nil, 45, 3, 59, nil, 61, 74, 51, 55,
95
- 25, 55, 53, 32, 72, 33, 50, nil, 75, 70,
96
- 42, 71, nil, 59, 25, nil, 71, nil, 25, 61,
97
- 84, 49, 47, 46, 51, 83, 70, nil, nil, 42,
98
- nil, nil, nil, nil, nil, nil, nil, nil, 90, 73,
99
- 91, nil, 92, nil, 82, 45, 42, 4, nil, 17,
100
- 17, 23, 24, 25, nil, nil, nil, nil, 45, nil,
101
- 45, 81, 45 ]
92
+ 17, 17, 2, 23, 24, 3, 25, 36, 41, 53,
93
+ 42, 4, 1, 44, 51, 31, 62, 34, 61, 74,
94
+ 53, 67, 35, 66, 68, 51, nil, 40, 72, nil,
95
+ 43, 25, 84, 86, nil, 39, 65, nil, 25, 32,
96
+ nil, 79, 25, nil, 66, nil, 72, nil, 35, 78,
97
+ 53, 82, nil, nil, nil, nil, 46, 60, nil, nil,
98
+ nil, 66, nil, nil, 64, 46, nil, nil, 35, nil,
99
+ 64, 88, 89, 81, 90, nil, 80, nil, 17, 17,
100
+ 23, 24, 4, 25, nil, nil, 64, nil, 64, 64,
101
+ nil, nil, nil, nil, 60, nil, nil, nil, nil, nil,
102
+ nil, nil, nil, 64 ]
102
103
 
103
104
  racc_goto_check = [
104
- 17, 17, 19, 5, 6, 24, 2, 10, 16, 4,
105
- 7, 7, 1, 9, 20, 20, 22, 5, 15, 18,
106
- 15, nil, 15, 3, 14, nil, 10, 16, 20, 20,
107
- 24, 20, 17, 12, 14, 13, 15, nil, 18, 15,
108
- 3, 15, nil, 14, 24, nil, 15, nil, 24, 10,
109
- 16, 12, 13, 3, 20, 19, 15, nil, nil, 3,
110
- nil, nil, nil, nil, nil, nil, nil, nil, 19, 13,
111
- 19, nil, 19, nil, 2, 15, 3, 4, nil, 17,
112
- 17, 5, 6, 24, nil, nil, nil, nil, 15, nil,
113
- 15, 3, 15 ]
105
+ 17, 17, 2, 5, 6, 3, 24, 19, 14, 10,
106
+ 16, 4, 1, 18, 15, 9, 14, 5, 15, 22,
107
+ 10, 16, 3, 20, 18, 15, nil, 13, 20, nil,
108
+ 17, 24, 7, 7, nil, 3, 13, nil, 24, 12,
109
+ nil, 14, 24, nil, 20, nil, 20, nil, 3, 19,
110
+ 10, 16, nil, nil, nil, nil, 12, 12, nil, nil,
111
+ nil, 20, nil, nil, 12, 12, nil, nil, 3, nil,
112
+ 12, 19, 19, 2, 19, nil, 3, nil, 17, 17,
113
+ 5, 6, 4, 24, nil, nil, 12, nil, 12, 12,
114
+ nil, nil, nil, nil, 12, nil, nil, nil, nil, nil,
115
+ nil, nil, nil, 12 ]
114
116
 
115
117
  racc_goto_pointer = [
116
- nil, 12, 6, 23, 9, 0, 1, -71, nil, -1,
117
- -27, nil, 18, 20, -10, 3, -26, -2, -15, -17,
118
- -19, nil, -45, nil, 2 ]
118
+ nil, 12, 2, 5, 11, 0, 1, -48, nil, 1,
119
+ -23, nil, 24, -5, -24, -18, -22, -2, -19, -12,
120
+ -18, nil, -34, nil, 3 ]
119
121
 
120
122
  racc_goto_default = [
121
- nil, nil, nil, 28, 39, 10, 11, 12, 27, 13,
122
- 14, 15, 69, nil, 16, 48, nil, 36, nil, 35,
123
- 37, 29, 60, 64, 8 ]
123
+ nil, nil, nil, 28, 37, 10, 11, 12, 27, 13,
124
+ 14, 15, 38, 69, nil, 16, nil, 63, nil, 45,
125
+ 47, 29, 52, 56, 8 ]
124
126
 
125
127
  racc_reduce_table = [
126
128
  0, 0, :racc_error,
@@ -135,11 +137,11 @@ racc_reduce_table = [
135
137
  1, 27, :_reduce_9,
136
138
  2, 27, :_reduce_10,
137
139
  1, 29, :_reduce_11,
138
- 2, 29, :_reduce_12,
139
- 2, 29, :_reduce_13,
140
- 3, 29, :_reduce_14,
141
- 3, 29, :_reduce_15,
142
- 4, 29, :_reduce_16,
140
+ 3, 29, :_reduce_12,
141
+ 3, 29, :_reduce_13,
142
+ 4, 29, :_reduce_14,
143
+ 4, 29, :_reduce_15,
144
+ 5, 29, :_reduce_16,
143
145
  1, 31, :_reduce_17,
144
146
  3, 31, :_reduce_18,
145
147
  4, 31, :_reduce_19,
@@ -147,39 +149,38 @@ racc_reduce_table = [
147
149
  4, 31, :_reduce_21,
148
150
  2, 31, :_reduce_22,
149
151
  2, 26, :_reduce_none,
150
- 4, 32, :_reduce_24,
151
- 4, 32, :_reduce_25,
152
- 6, 32, :_reduce_26,
153
- 6, 32, :_reduce_27,
152
+ 4, 33, :_reduce_24,
153
+ 4, 33, :_reduce_25,
154
+ 6, 33, :_reduce_26,
155
+ 6, 33, :_reduce_27,
154
156
  2, 40, :_reduce_none,
155
157
  2, 40, :_reduce_none,
156
- 1, 33, :_reduce_none,
157
- 2, 33, :_reduce_none,
158
+ 1, 34, :_reduce_none,
159
+ 2, 34, :_reduce_none,
158
160
  1, 28, :_reduce_none,
159
161
  1, 28, :_reduce_none,
160
162
  1, 41, :_reduce_none,
161
163
  2, 41, :_reduce_none,
162
164
  1, 37, :_reduce_none,
163
165
  2, 37, :_reduce_none,
164
- 2, 37, :_reduce_none,
165
- 6, 30, :_reduce_39,
166
- 1, 34, :_reduce_40,
167
- 1, 34, :_reduce_41,
168
- 1, 34, :_reduce_42,
169
- 3, 38, :_reduce_43,
166
+ 6, 30, :_reduce_38,
167
+ 1, 35, :_reduce_39,
168
+ 1, 35, :_reduce_40,
169
+ 1, 35, :_reduce_41,
170
+ 3, 38, :_reduce_42,
170
171
  1, 36, :_reduce_none,
171
- 2, 36, :_reduce_45,
172
+ 2, 36, :_reduce_44,
173
+ 1, 42, :_reduce_45,
172
174
  1, 42, :_reduce_46,
173
175
  1, 42, :_reduce_47,
174
176
  1, 42, :_reduce_48,
175
177
  1, 42, :_reduce_49,
176
178
  1, 42, :_reduce_50,
177
179
  1, 42, :_reduce_51,
178
- 1, 42, :_reduce_52,
180
+ 1, 43, :_reduce_52,
179
181
  1, 43, :_reduce_53,
180
- 1, 43, :_reduce_54,
181
- 1, 35, :_reduce_none,
182
- 2, 35, :_reduce_none,
182
+ 1, 32, :_reduce_none,
183
+ 2, 32, :_reduce_none,
183
184
  1, 39, :_reduce_none,
184
185
  1, 39, :_reduce_none,
185
186
  1, 44, :_reduce_none,
@@ -187,11 +188,11 @@ racc_reduce_table = [
187
188
  1, 44, :_reduce_none,
188
189
  1, 23, :_reduce_none,
189
190
  2, 23, :_reduce_none,
190
- 0, 24, :_reduce_64 ]
191
+ 0, 24, :_reduce_63 ]
191
192
 
192
- racc_reduce_n = 65
193
+ racc_reduce_n = 64
193
194
 
194
- racc_shift_n = 95
195
+ racc_shift_n = 93
195
196
 
196
197
  racc_token_table = {
197
198
  false => 0,
@@ -269,10 +270,10 @@ Racc_token_to_s_table = [
269
270
  "untyped_node",
270
271
  "type",
271
272
  "node_decl",
273
+ "ws_plus",
272
274
  "node_children",
273
275
  "empty_childrens",
274
276
  "identifier",
275
- "ws_plus",
276
277
  "value",
277
278
  "slashdash",
278
279
  "property",
@@ -358,7 +359,7 @@ module_eval(<<'.,.,', 'kdl.yy', 23)
358
359
 
359
360
  module_eval(<<'.,.,', 'kdl.yy', 24)
360
361
  def _reduce_12(val, _values)
361
- val[0].tap { |x| x.children = val[1] }
362
+ val[0].tap { |x| x.children = val[2] }
362
363
  end
363
364
  .,.,
364
365
 
@@ -370,19 +371,19 @@ module_eval(<<'.,.,', 'kdl.yy', 25)
370
371
 
371
372
  module_eval(<<'.,.,', 'kdl.yy', 26)
372
373
  def _reduce_14(val, _values)
373
- val[0].tap { |x| x.children = val[2] }
374
+ val[0].tap { |x| x.children = val[3] }
374
375
  end
375
376
  .,.,
376
377
 
377
378
  module_eval(<<'.,.,', 'kdl.yy', 27)
378
379
  def _reduce_15(val, _values)
379
- val[0].tap { |x| x.children = val[1] }
380
+ val[0].tap { |x| x.children = val[2] }
380
381
  end
381
382
  .,.,
382
383
 
383
384
  module_eval(<<'.,.,', 'kdl.yy', 28)
384
385
  def _reduce_16(val, _values)
385
- val[0].tap { |x| x.children = val[2] }
386
+ val[0].tap { |x| x.children = val[3] }
386
387
  end
387
388
  .,.,
388
389
 
@@ -468,100 +469,100 @@ module_eval(<<'.,.,', 'kdl.yy', 39)
468
469
 
469
470
  # reduce 37 omitted
470
471
 
471
- # reduce 38 omitted
472
-
473
472
  module_eval(<<'.,.,', 'kdl.yy', 47)
474
- def _reduce_39(val, _values)
473
+ def _reduce_38(val, _values)
475
474
  val[2]
476
475
  end
477
476
  .,.,
478
477
 
479
478
  module_eval(<<'.,.,', 'kdl.yy', 49)
480
- def _reduce_40(val, _values)
479
+ def _reduce_39(val, _values)
481
480
  val[0].value
482
481
  end
483
482
  .,.,
484
483
 
485
484
  module_eval(<<'.,.,', 'kdl.yy', 50)
486
- def _reduce_41(val, _values)
485
+ def _reduce_40(val, _values)
487
486
  val[0].value
488
487
  end
489
488
  .,.,
490
489
 
491
490
  module_eval(<<'.,.,', 'kdl.yy', 51)
492
- def _reduce_42(val, _values)
491
+ def _reduce_41(val, _values)
493
492
  val[0].value
494
493
  end
495
494
  .,.,
496
495
 
497
496
  module_eval(<<'.,.,', 'kdl.yy', 53)
498
- def _reduce_43(val, _values)
497
+ def _reduce_42(val, _values)
499
498
  [val[0], val[2]]
500
499
  end
501
500
  .,.,
502
501
 
503
- # reduce 44 omitted
502
+ # reduce 43 omitted
504
503
 
505
504
  module_eval(<<'.,.,', 'kdl.yy', 56)
506
- def _reduce_45(val, _values)
505
+ def _reduce_44(val, _values)
507
506
  val[1].as_type(val[0], @type_parsers.fetch(val[0], nil))
508
507
  end
509
508
  .,.,
510
509
 
511
510
  module_eval(<<'.,.,', 'kdl.yy', 58)
512
- def _reduce_46(val, _values)
511
+ def _reduce_45(val, _values)
513
512
  @output_module::Value::String.new(val[0].value)
514
513
  end
515
514
  .,.,
516
515
 
517
516
  module_eval(<<'.,.,', 'kdl.yy', 59)
518
- def _reduce_47(val, _values)
517
+ def _reduce_46(val, _values)
519
518
  @output_module::Value::String.new(val[0].value)
520
519
  end
521
520
  .,.,
522
521
 
523
522
  module_eval(<<'.,.,', 'kdl.yy', 60)
524
- def _reduce_48(val, _values)
523
+ def _reduce_47(val, _values)
525
524
  @output_module::Value::String.new(val[0].value)
526
525
  end
527
526
  .,.,
528
527
 
529
528
  module_eval(<<'.,.,', 'kdl.yy', 61)
530
- def _reduce_49(val, _values)
529
+ def _reduce_48(val, _values)
531
530
  @output_module::Value::Int.new(val[0].value)
532
531
  end
533
532
  .,.,
534
533
 
535
534
  module_eval(<<'.,.,', 'kdl.yy', 62)
536
- def _reduce_50(val, _values)
535
+ def _reduce_49(val, _values)
537
536
  @output_module::Value::Float.new(val[0].value, format: val[0].meta[:format])
538
537
  end
539
538
  .,.,
540
539
 
541
540
  module_eval(<<'.,.,', 'kdl.yy', 63)
542
- def _reduce_51(val, _values)
541
+ def _reduce_50(val, _values)
543
542
  @output_module::Value::Boolean.new(val[0])
544
543
  end
545
544
  .,.,
546
545
 
547
546
  module_eval(<<'.,.,', 'kdl.yy', 64)
548
- def _reduce_52(val, _values)
547
+ def _reduce_51(val, _values)
549
548
  @output_module::Value::Null
550
549
  end
551
550
  .,.,
552
551
 
553
552
  module_eval(<<'.,.,', 'kdl.yy', 66)
554
- def _reduce_53(val, _values)
553
+ def _reduce_52(val, _values)
555
554
  true
556
555
  end
557
556
  .,.,
558
557
 
559
558
  module_eval(<<'.,.,', 'kdl.yy', 67)
560
- def _reduce_54(val, _values)
559
+ def _reduce_53(val, _values)
561
560
  false
562
561
  end
563
562
  .,.,
564
563
 
564
+ # reduce 54 omitted
565
+
565
566
  # reduce 55 omitted
566
567
 
567
568
  # reduce 56 omitted
@@ -578,10 +579,8 @@ module_eval(<<'.,.,', 'kdl.yy', 67)
578
579
 
579
580
  # reduce 62 omitted
580
581
 
581
- # reduce 63 omitted
582
-
583
582
  module_eval(<<'.,.,', 'kdl.yy', 74)
584
- def _reduce_64(val, _values)
583
+ def _reduce_63(val, _values)
585
584
  nil
586
585
  end
587
586
  .,.,
data/lib/kdl/kdl.yy CHANGED
@@ -21,12 +21,12 @@ rule
21
21
  node : unterm_node node_term { val[0] }
22
22
  unterm_node : untyped_node { val[0] }
23
23
  | type untyped_node { val[1].as_type(val[0], @type_parsers.fetch(val[0], nil)) }
24
- untyped_node : node_decl { val[0].tap { |x| x.children = [] } }
25
- | node_decl node_children { val[0].tap { |x| x.children = val[1] } }
26
- | node_decl empty_childrens { val[0].tap { |x| x.children = [] } }
27
- | node_decl empty_childrens node_children { val[0].tap { |x| x.children = val[2] } }
28
- | node_decl node_children empty_childrens { val[0].tap { |x| x.children = val[1] } }
29
- | node_decl empty_childrens node_children empty_childrens { val[0].tap { |x| x.children = val[2] } }
24
+ untyped_node : node_decl { val[0].tap { |x| x.children = [] } }
25
+ | node_decl ws_plus node_children { val[0].tap { |x| x.children = val[2] } }
26
+ | node_decl ws_plus empty_childrens { val[0].tap { |x| x.children = [] } }
27
+ | node_decl ws_plus empty_childrens node_children { val[0].tap { |x| x.children = val[3] } }
28
+ | node_decl ws_plus node_children empty_childrens { val[0].tap { |x| x.children = val[2] } }
29
+ | node_decl ws_plus empty_childrens node_children empty_childrens { val[0].tap { |x| x.children = val[3] } }
30
30
  node_decl : identifier { @output_module::Node.new(val[0]) }
31
31
  | node_decl ws_plus value { val[0].tap { |x| x.arguments << val[2] } }
32
32
  | node_decl ws_plus slashdash value { val[0] }
@@ -43,7 +43,7 @@ rule
43
43
  empty_childrens: empty_children | empty_childrens empty_children
44
44
  node_term: linespaces | semicolon_term
45
45
  semicolon_term: SEMICOLON | SEMICOLON linespaces
46
- slashdash: SLASHDASH | slashdash ws_plus | slashdash linespaces
46
+ slashdash: SLASHDASH | slashdash linespaces
47
47
 
48
48
  type : LPAREN ws_star identifier ws_star RPAREN ws_star { val[2] }
49
49
 
data/lib/kdl/node.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KDL
2
4
  class Node
3
5
  class Custom < Node
@@ -92,15 +94,15 @@ module KDL
92
94
  indent = ' ' * level
93
95
  s = "#{indent}#{type ? "(#{id_to_s type, m })" : ''}#{id_to_s name, m}"
94
96
  unless arguments.empty?
95
- s += " #{arguments.map(&m).join(' ')}"
97
+ s << " #{arguments.map(&m).join(' ')}"
96
98
  end
97
99
  unless properties.empty?
98
- s += " #{properties.map { |k, v| "#{id_to_s k, m}=#{v.public_send(m)}" }.join(' ')}"
100
+ s << " #{properties.map { |k, v| "#{id_to_s k, m}=#{v.public_send(m)}" }.join(' ')}"
99
101
  end
100
102
  unless children.empty?
101
- s += " {\n"
102
- s += children.map { |c| "#{c.public_send(m, level + 1)}" }.join("\n")
103
- s += "\n#{indent}}"
103
+ s << " {\n"
104
+ s << children.map { |c| "#{c.public_send(m, level + 1)}" }.join("\n")
105
+ s << "\n#{indent}}"
104
106
  end
105
107
  s
106
108
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KDL
2
4
  module ParserCommon
3
5
 
@@ -19,7 +21,7 @@ module KDL
19
21
  def check_version
20
22
  return unless doc_version = @tokenizer.version_directive
21
23
  if doc_version != parser_version
22
- raise ParseError, "Version mismatch, document specified v#{doc_version}, but this is a v#{parser_version} parser"
24
+ raise VersionMismatchError.new("Version mismatch, document specified v#{doc_version}, but this is a v#{parser_version} parser", doc_version, parser_version)
23
25
  end
24
26
  end
25
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KDL
2
4
  module StringDumper
3
5
  def call(string)