kdl 1.0.0.rc1 → 1.0.0.rc2
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 +1 -1
- data/README.md +16 -2
- data/kdl.gemspec +2 -1
- data/lib/kdl/kdl.tab.rb +155 -141
- data/lib/kdl/kdl.yy +26 -19
- data/lib/kdl/node.rb +17 -0
- data/lib/kdl/tokenizer.rb +2 -1
- data/lib/kdl/types/base64.rb +15 -0
- data/lib/kdl/types/country/iso3166_countries.rb +512 -0
- data/lib/kdl/types/country/iso3166_subdivisions.rb +3927 -0
- data/lib/kdl/types/country.rb +69 -0
- data/lib/kdl/types/currency/iso4217_currencies.rb +189 -0
- data/lib/kdl/types/currency.rb +26 -0
- data/lib/kdl/types/date_time.rb +41 -0
- data/lib/kdl/types/decimal.rb +13 -0
- data/lib/kdl/types/duration/iso8601_parser.rb +147 -0
- data/lib/kdl/types/duration.rb +28 -0
- data/lib/kdl/types/email/parser.rb +151 -0
- data/lib/kdl/types/email.rb +43 -0
- data/lib/kdl/types/hostname/validator.rb +51 -0
- data/lib/kdl/types/hostname.rb +32 -0
- data/lib/kdl/types/ip.rb +32 -0
- data/lib/kdl/types/irl/parser.rb +123 -0
- data/lib/kdl/types/irl.rb +46 -0
- data/lib/kdl/types/regex.rb +13 -0
- data/lib/kdl/types/url.rb +30 -0
- data/lib/kdl/types/url_template.rb +328 -0
- data/lib/kdl/types/uuid.rb +17 -0
- data/lib/kdl/types.rb +22 -0
- data/lib/kdl/value.rb +13 -2
- data/lib/kdl/version.rb +1 -1
- data/lib/kdl.rb +3 -2
- metadata +39 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad96fca4491347ec286e3a6ccdaa2c48027ac6e51e4541ea4583d858885192c
|
4
|
+
data.tar.gz: '0863341cc116e0d95b663be4cf7becd89173773d20db4e80a0575f224f9590f1'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1371e648e0b27a19664fd58c4d6b8cfa136727b20235fd845735d1b6ac4eb1eea8b978634fc58c86e15af8d2ee2641e0afbf7b798d678fb19dd607123d734d7c
|
7
|
+
data.tar.gz: 54d709fda2686dec0dd3d3fa9b11fd3e90c23651d12fb94136efd37b5f67b2fe533a0c540fdbea0597708ee7d14fd609b1d2ad9d6cc4e1fb297438ad9f641c22
|
data/.github/workflows/ruby.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# KDL
|
2
2
|
|
3
|
-
[![Actions Status](https://github.com/
|
3
|
+
[![Actions Status](https://github.com/danini-the-panini/kdl-rb/workflows/Ruby/badge.svg)](https://github.com/danini-the-panini/kdl-rb/actions)
|
4
4
|
|
5
5
|
This is a Ruby implementation of the [KDL Document Language](https://kdl.dev)
|
6
6
|
|
@@ -28,6 +28,20 @@ require 'kdl'
|
|
28
28
|
KDL.parse_document(a_string) #=> KDL::Document
|
29
29
|
```
|
30
30
|
|
31
|
+
You can optionally provide your own type annotation handlers:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
KDL.parse_document(a_string, type_parsers: {
|
35
|
+
'foo' => -> (value, type) {
|
36
|
+
Foo.new(value.value, type: type)
|
37
|
+
}
|
38
|
+
})
|
39
|
+
```
|
40
|
+
|
41
|
+
The `foo` proc will be called with instances of Value or Node with the type annotation `(foo)`.
|
42
|
+
|
43
|
+
Parsers are expected to have a `call` method that takes the Value or Node, and the type annotation itself, as arguments, and is expected to return either an instance of Value or Node (depending on the input type) or `nil` to return the original value as is. Take a look at [the built in parsers](lib/kdl/types) as a reference.
|
44
|
+
|
31
45
|
## Development
|
32
46
|
|
33
47
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -36,7 +50,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
36
50
|
|
37
51
|
## Contributing
|
38
52
|
|
39
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/danini-the-panini/kdl-rb.
|
40
54
|
|
41
55
|
|
42
56
|
## License
|
data/kdl.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = %q{Ruby implementation of the KDL Document Language Spec}
|
11
11
|
spec.homepage = "https://kdl.dev"
|
12
12
|
spec.license = "MIT"
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = "https://github.com/danini-the-panini/kdl-rb"
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
27
|
spec.add_development_dependency 'racc', '~> 1.5'
|
28
|
+
spec.add_dependency 'simpleidn', '~> 0.2.1'
|
28
29
|
end
|
data/lib/kdl/kdl.tab.rb
CHANGED
@@ -8,8 +8,14 @@ require 'racc/parser.rb'
|
|
8
8
|
module KDL
|
9
9
|
class Parser < Racc::Parser
|
10
10
|
|
11
|
-
module_eval(<<'...end kdl.yy/module_eval...', 'kdl.yy',
|
12
|
-
|
11
|
+
module_eval(<<'...end kdl.yy/module_eval...', 'kdl.yy', 69)
|
12
|
+
|
13
|
+
def parse(str, options = {})
|
14
|
+
if options.fetch(:parse_types, true)
|
15
|
+
@type_parsers = ::KDL::Types::MAPPING.merge(options.fetch(:type_parsers, {}))
|
16
|
+
else
|
17
|
+
@type_parsers = {}
|
18
|
+
end
|
13
19
|
@tokenizer = ::KDL::Tokenizer.new(str)
|
14
20
|
do_parse
|
15
21
|
end
|
@@ -23,82 +29,82 @@ module_eval(<<'...end kdl.yy/module_eval...', 'kdl.yy', 68)
|
|
23
29
|
##### State transition tables begin ###
|
24
30
|
|
25
31
|
racc_action_table = [
|
26
|
-
-2, 10,
|
27
|
-
6, 7,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
nil, nil,
|
34
|
-
|
35
|
-
8,
|
32
|
+
-2, 10, 19, 20, 21, 19, 20, 21, 6, 7,
|
33
|
+
6, 7, 45, 25, 18, 38, 8, 18, 8, 17,
|
34
|
+
58, 32, 17, 19, 47, 48, 52, 53, 56, 57,
|
35
|
+
55, 45, 38, -43, 62, 18, 19, 20, 21, 38,
|
36
|
+
43, -29, -30, 19, 20, 21, 64, 74, 18, 19,
|
37
|
+
20, 21, nil, 17, 75, 18, 19, 20, 21, nil,
|
38
|
+
17, 18, 19, 47, 48, 52, 53, 56, 57, 55,
|
39
|
+
nil, nil, 58, nil, 18, 66, 67, 52, 53, 56,
|
40
|
+
57, 55, 30, 7, nil, nil, 18, 6, 7, 35,
|
41
|
+
8, 32, 6, 7, 35, 8, 6, 7, nil, 35,
|
36
42
|
8, 6, 7, nil, 8, 6, 7, 6, 7, 8,
|
37
|
-
6, 7, nil, 8, nil, 8, nil, nil, 8,
|
38
|
-
|
43
|
+
6, 7, nil, 8, nil, 8, nil, nil, 8, 66,
|
44
|
+
67, 52, 53, 56, 57, 55, 19, 20, 21 ]
|
39
45
|
|
40
46
|
racc_action_check = [
|
41
47
|
3, 1, 2, 2, 2, 5, 5, 5, 0, 0,
|
42
|
-
3, 3,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
nil, nil,
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
3, 3, 45, 10, 2, 17, 0, 5, 3, 2,
|
49
|
+
31, 45, 5, 30, 30, 30, 30, 30, 30, 30,
|
50
|
+
30, 30, 32, 30, 39, 30, 68, 68, 68, 43,
|
51
|
+
30, 47, 48, 69, 69, 69, 49, 68, 68, 37,
|
52
|
+
37, 37, nil, 68, 69, 69, 14, 14, 14, nil,
|
53
|
+
69, 37, 63, 63, 63, 63, 63, 63, 63, 63,
|
54
|
+
nil, nil, 63, nil, 63, 64, 64, 64, 64, 64,
|
55
|
+
64, 64, 15, 15, nil, nil, 64, 28, 28, 15,
|
56
|
+
15, 15, 29, 29, 28, 28, 33, 33, nil, 29,
|
57
|
+
29, 35, 35, nil, 33, 58, 58, 60, 60, 35,
|
58
|
+
70, 70, nil, 58, nil, 60, nil, nil, 70, 51,
|
59
|
+
51, 51, 51, 51, 51, 51, 18, 18, 18 ]
|
54
60
|
|
55
61
|
racc_action_pointer = [
|
56
62
|
-2, 1, 0, 0, nil, 3, nil, nil, nil, nil,
|
57
|
-
13, nil, nil, 72, nil,
|
58
|
-
nil, nil, nil, nil, nil, nil, 77, 82,
|
59
|
-
22, 86, nil, 91, nil,
|
60
|
-
nil, nil, 29, nil, 2, nil, 25, 26, 30,
|
61
|
-
116, nil, nil, nil, nil, nil, nil, 95, nil,
|
62
|
-
nil, nil, 60, 72, nil, nil, nil, 34, 41,
|
63
|
-
nil, nil, nil, nil, nil ]
|
63
|
+
13, nil, nil, nil, 54, 72, nil, 5, 124, nil,
|
64
|
+
nil, nil, nil, nil, nil, nil, nil, nil, 77, 82,
|
65
|
+
21, 8, 22, 86, nil, 91, nil, 47, nil, 19,
|
66
|
+
nil, nil, nil, 29, nil, 2, nil, 25, 26, 30,
|
67
|
+
nil, 116, nil, nil, nil, nil, nil, nil, 95, nil,
|
68
|
+
97, nil, nil, 60, 72, nil, nil, nil, 34, 41,
|
69
|
+
100, nil, nil, nil, nil, nil ]
|
64
70
|
|
65
71
|
racc_action_default = [
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-29, -
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
72
|
+
-51, -52, -1, -50, -3, -52, -44, -45, -46, -47,
|
73
|
+
-52, -6, -7, -8, -52, -51, -13, -51, -52, -28,
|
74
|
+
-29, -30, -48, -4, -5, 76, -9, -10, -52, -52,
|
75
|
+
-44, -52, -51, -23, -24, -25, -42, -52, -43, -52,
|
76
|
+
-11, -12, -14, -51, -16, -52, -22, -34, -35, -52,
|
77
|
+
-32, -52, -36, -37, -38, -39, -40, -41, -51, -21,
|
78
|
+
-26, -18, -27, -52, -52, -33, -34, -35, -52, -52,
|
79
|
+
-50, -15, -17, -31, -20, -19 ]
|
74
80
|
|
75
81
|
racc_goto_table = [
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
nil, nil,
|
80
|
-
|
81
|
-
nil, nil, nil, nil,
|
82
|
-
|
82
|
+
22, 23, 24, 2, 3, 4, 39, 51, 5, 42,
|
83
|
+
37, 44, 27, 1, 26, 28, 29, 65, 49, nil,
|
84
|
+
nil, nil, nil, nil, nil, 40, 41, nil, nil, nil,
|
85
|
+
22, nil, nil, 61, nil, nil, 63, nil, nil, 60,
|
86
|
+
51, 51, 71, 73, 72, nil, nil, nil, nil, nil,
|
87
|
+
nil, 49, nil, nil, nil, nil, nil, 22, nil, nil,
|
88
|
+
nil, 69, 70, 4, 23, 24, 68, 22 ]
|
83
89
|
|
84
90
|
racc_goto_check = [
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
nil, nil, 6, nil, nil, nil, nil, 3,
|
89
|
-
|
90
|
-
nil, nil, nil, nil,
|
91
|
-
2, 3, 4, 6, 7, 5,
|
91
|
+
21, 6, 7, 2, 3, 4, 14, 9, 5, 15,
|
92
|
+
16, 17, 11, 1, 8, 12, 13, 19, 14, nil,
|
93
|
+
nil, nil, nil, nil, nil, 11, 11, nil, nil, nil,
|
94
|
+
21, nil, nil, 6, nil, nil, 16, nil, nil, 3,
|
95
|
+
9, 9, 15, 15, 17, nil, nil, nil, nil, nil,
|
96
|
+
nil, 14, nil, nil, nil, nil, nil, 21, nil, nil,
|
97
|
+
nil, 2, 3, 4, 6, 7, 5, 21 ]
|
92
98
|
|
93
99
|
racc_goto_pointer = [
|
94
|
-
nil,
|
95
|
-
|
96
|
-
-3 ]
|
100
|
+
nil, 13, 3, 4, 5, 8, -4, -3, 0, -23,
|
101
|
+
nil, -3, 0, 1, -12, -21, -7, -19, nil, -34,
|
102
|
+
nil, -3 ]
|
97
103
|
|
98
104
|
racc_goto_default = [
|
99
|
-
nil, nil, nil,
|
100
|
-
|
101
|
-
9 ]
|
105
|
+
nil, nil, nil, 33, 36, nil, 11, 12, 13, 14,
|
106
|
+
15, nil, 59, 46, 16, nil, 31, nil, 34, 50,
|
107
|
+
54, 9 ]
|
102
108
|
|
103
109
|
racc_reduce_table = [
|
104
110
|
0, 0, :racc_error,
|
@@ -109,53 +115,54 @@ racc_reduce_table = [
|
|
109
115
|
2, 22, :_reduce_5,
|
110
116
|
2, 22, :_reduce_6,
|
111
117
|
2, 22, :_reduce_7,
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
1, 26, :_reduce_8,
|
119
|
+
2, 26, :_reduce_9,
|
120
|
+
2, 28, :_reduce_10,
|
121
|
+
3, 28, :_reduce_11,
|
122
|
+
3, 28, :_reduce_12,
|
123
|
+
1, 30, :_reduce_13,
|
124
|
+
3, 30, :_reduce_14,
|
125
|
+
5, 30, :_reduce_15,
|
126
|
+
3, 30, :_reduce_16,
|
127
|
+
5, 30, :_reduce_17,
|
121
128
|
3, 27, :_reduce_none,
|
122
|
-
4,
|
123
|
-
4,
|
124
|
-
2,
|
125
|
-
2,
|
126
|
-
1,
|
127
|
-
1,
|
128
|
-
1,
|
129
|
-
2,
|
130
|
-
3,
|
131
|
-
1,
|
132
|
-
1,
|
133
|
-
1,
|
134
|
-
3,
|
135
|
-
1, 34, :_reduce_none,
|
136
|
-
2, 34, :_reduce_32,
|
137
|
-
1, 38, :_reduce_33,
|
138
|
-
1, 38, :_reduce_34,
|
139
|
-
1, 38, :_reduce_35,
|
140
|
-
1, 38, :_reduce_36,
|
141
|
-
1, 38, :_reduce_37,
|
142
|
-
1, 38, :_reduce_38,
|
143
|
-
1, 39, :_reduce_39,
|
144
|
-
1, 39, :_reduce_40,
|
145
|
-
1, 35, :_reduce_none,
|
129
|
+
4, 32, :_reduce_19,
|
130
|
+
4, 32, :_reduce_20,
|
131
|
+
2, 33, :_reduce_none,
|
132
|
+
2, 33, :_reduce_none,
|
133
|
+
1, 31, :_reduce_none,
|
134
|
+
1, 31, :_reduce_none,
|
135
|
+
1, 38, :_reduce_none,
|
136
|
+
2, 38, :_reduce_none,
|
137
|
+
3, 29, :_reduce_27,
|
138
|
+
1, 34, :_reduce_28,
|
139
|
+
1, 34, :_reduce_29,
|
140
|
+
1, 34, :_reduce_30,
|
141
|
+
3, 37, :_reduce_31,
|
146
142
|
1, 35, :_reduce_none,
|
147
|
-
|
148
|
-
1,
|
149
|
-
1,
|
143
|
+
2, 35, :_reduce_33,
|
144
|
+
1, 39, :_reduce_34,
|
145
|
+
1, 39, :_reduce_35,
|
146
|
+
1, 39, :_reduce_36,
|
147
|
+
1, 39, :_reduce_37,
|
148
|
+
1, 39, :_reduce_38,
|
149
|
+
1, 39, :_reduce_39,
|
150
|
+
1, 40, :_reduce_40,
|
151
|
+
1, 40, :_reduce_41,
|
152
|
+
1, 36, :_reduce_none,
|
153
|
+
1, 36, :_reduce_none,
|
154
|
+
1, 41, :_reduce_none,
|
155
|
+
1, 41, :_reduce_none,
|
156
|
+
1, 41, :_reduce_none,
|
150
157
|
1, 23, :_reduce_none,
|
151
158
|
2, 23, :_reduce_none,
|
152
159
|
1, 25, :_reduce_none,
|
153
160
|
1, 25, :_reduce_none,
|
154
|
-
0, 24, :
|
161
|
+
0, 24, :_reduce_51 ]
|
155
162
|
|
156
|
-
racc_reduce_n =
|
163
|
+
racc_reduce_n = 52
|
157
164
|
|
158
|
-
racc_shift_n =
|
165
|
+
racc_shift_n = 76
|
159
166
|
|
160
167
|
racc_token_table = {
|
161
168
|
false => 0,
|
@@ -228,12 +235,13 @@ Racc_token_to_s_table = [
|
|
228
235
|
"linespace_star",
|
229
236
|
"node",
|
230
237
|
"empty_node",
|
238
|
+
"untyped_node",
|
239
|
+
"type",
|
231
240
|
"node_decl",
|
232
241
|
"node_term",
|
233
242
|
"node_children",
|
234
243
|
"empty_children",
|
235
244
|
"identifier",
|
236
|
-
"type",
|
237
245
|
"value",
|
238
246
|
"ws_star",
|
239
247
|
"property",
|
@@ -292,13 +300,13 @@ module_eval(<<'.,.,', 'kdl.yy', 20)
|
|
292
300
|
|
293
301
|
module_eval(<<'.,.,', 'kdl.yy', 21)
|
294
302
|
def _reduce_8(val, _values)
|
295
|
-
val[0]
|
303
|
+
val[0]
|
296
304
|
end
|
297
305
|
.,.,
|
298
306
|
|
299
307
|
module_eval(<<'.,.,', 'kdl.yy', 22)
|
300
308
|
def _reduce_9(val, _values)
|
301
|
-
val[0]
|
309
|
+
val[1].as_type(val[0], @type_parsers.fetch(val[0], nil))
|
302
310
|
end
|
303
311
|
.,.,
|
304
312
|
|
@@ -310,56 +318,60 @@ module_eval(<<'.,.,', 'kdl.yy', 23)
|
|
310
318
|
|
311
319
|
module_eval(<<'.,.,', 'kdl.yy', 24)
|
312
320
|
def _reduce_11(val, _values)
|
313
|
-
|
321
|
+
val[0].tap { |x| x.children = val[1] }
|
314
322
|
end
|
315
323
|
.,.,
|
316
324
|
|
317
325
|
module_eval(<<'.,.,', 'kdl.yy', 25)
|
318
326
|
def _reduce_12(val, _values)
|
319
|
-
|
327
|
+
val[0].tap { |x| x.children = nil }
|
320
328
|
end
|
321
329
|
.,.,
|
322
330
|
|
323
331
|
module_eval(<<'.,.,', 'kdl.yy', 26)
|
324
332
|
def _reduce_13(val, _values)
|
325
|
-
val[0]
|
333
|
+
KDL::Node.new(val[0])
|
326
334
|
end
|
327
335
|
.,.,
|
328
336
|
|
329
337
|
module_eval(<<'.,.,', 'kdl.yy', 27)
|
330
338
|
def _reduce_14(val, _values)
|
331
|
-
val[0]
|
339
|
+
val[0].tap { |x| x.arguments << val[2] }
|
332
340
|
end
|
333
341
|
.,.,
|
334
342
|
|
335
343
|
module_eval(<<'.,.,', 'kdl.yy', 28)
|
336
344
|
def _reduce_15(val, _values)
|
337
|
-
val[0]
|
345
|
+
val[0]
|
338
346
|
end
|
339
347
|
.,.,
|
340
348
|
|
341
349
|
module_eval(<<'.,.,', 'kdl.yy', 29)
|
342
350
|
def _reduce_16(val, _values)
|
351
|
+
val[0].tap { |x| x.properties[val[2][0]] = val[2][1] }
|
352
|
+
end
|
353
|
+
.,.,
|
354
|
+
|
355
|
+
module_eval(<<'.,.,', 'kdl.yy', 30)
|
356
|
+
def _reduce_17(val, _values)
|
343
357
|
val[0]
|
344
358
|
end
|
345
359
|
.,.,
|
346
360
|
|
347
|
-
# reduce
|
361
|
+
# reduce 18 omitted
|
348
362
|
|
349
|
-
module_eval(<<'.,.,', 'kdl.yy',
|
350
|
-
def
|
363
|
+
module_eval(<<'.,.,', 'kdl.yy', 32)
|
364
|
+
def _reduce_19(val, _values)
|
351
365
|
val[2]
|
352
366
|
end
|
353
367
|
.,.,
|
354
368
|
|
355
|
-
module_eval(<<'.,.,', 'kdl.yy',
|
356
|
-
def
|
369
|
+
module_eval(<<'.,.,', 'kdl.yy', 33)
|
370
|
+
def _reduce_20(val, _values)
|
357
371
|
[]
|
358
372
|
end
|
359
373
|
.,.,
|
360
374
|
|
361
|
-
# reduce 20 omitted
|
362
|
-
|
363
375
|
# reduce 21 omitted
|
364
376
|
|
365
377
|
# reduce 22 omitted
|
@@ -370,15 +382,11 @@ module_eval(<<'.,.,', 'kdl.yy', 32)
|
|
370
382
|
|
371
383
|
# reduce 25 omitted
|
372
384
|
|
373
|
-
|
374
|
-
def _reduce_26(val, _values)
|
375
|
-
val[1]
|
376
|
-
end
|
377
|
-
.,.,
|
385
|
+
# reduce 26 omitted
|
378
386
|
|
379
|
-
module_eval(<<'.,.,', 'kdl.yy',
|
387
|
+
module_eval(<<'.,.,', 'kdl.yy', 39)
|
380
388
|
def _reduce_27(val, _values)
|
381
|
-
val[
|
389
|
+
val[1]
|
382
390
|
end
|
383
391
|
.,.,
|
384
392
|
|
@@ -394,23 +402,23 @@ module_eval(<<'.,.,', 'kdl.yy', 42)
|
|
394
402
|
end
|
395
403
|
.,.,
|
396
404
|
|
397
|
-
module_eval(<<'.,.,', 'kdl.yy',
|
405
|
+
module_eval(<<'.,.,', 'kdl.yy', 43)
|
398
406
|
def _reduce_30(val, _values)
|
399
|
-
|
407
|
+
val[0].value
|
400
408
|
end
|
401
409
|
.,.,
|
402
410
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
def _reduce_32(val, _values)
|
407
|
-
val[1].as_type(val[0])
|
411
|
+
module_eval(<<'.,.,', 'kdl.yy', 45)
|
412
|
+
def _reduce_31(val, _values)
|
413
|
+
[val[0], val[2]]
|
408
414
|
end
|
409
415
|
.,.,
|
410
416
|
|
411
|
-
|
417
|
+
# reduce 32 omitted
|
418
|
+
|
419
|
+
module_eval(<<'.,.,', 'kdl.yy', 48)
|
412
420
|
def _reduce_33(val, _values)
|
413
|
-
|
421
|
+
val[1].as_type(val[0], @type_parsers.fetch(val[0], nil))
|
414
422
|
end
|
415
423
|
.,.,
|
416
424
|
|
@@ -422,41 +430,45 @@ module_eval(<<'.,.,', 'kdl.yy', 50)
|
|
422
430
|
|
423
431
|
module_eval(<<'.,.,', 'kdl.yy', 51)
|
424
432
|
def _reduce_35(val, _values)
|
425
|
-
KDL::Value::
|
433
|
+
KDL::Value::String.new(val[0].value)
|
426
434
|
end
|
427
435
|
.,.,
|
428
436
|
|
429
437
|
module_eval(<<'.,.,', 'kdl.yy', 52)
|
430
438
|
def _reduce_36(val, _values)
|
431
|
-
KDL::Value::
|
439
|
+
KDL::Value::Int.new(val[0].value)
|
432
440
|
end
|
433
441
|
.,.,
|
434
442
|
|
435
443
|
module_eval(<<'.,.,', 'kdl.yy', 53)
|
436
444
|
def _reduce_37(val, _values)
|
437
|
-
KDL::Value::
|
445
|
+
KDL::Value::Float.new(val[0].value, format: val[0].meta[:format])
|
438
446
|
end
|
439
447
|
.,.,
|
440
448
|
|
441
449
|
module_eval(<<'.,.,', 'kdl.yy', 54)
|
442
450
|
def _reduce_38(val, _values)
|
443
|
-
KDL::Value::
|
451
|
+
KDL::Value::Boolean.new(val[0])
|
444
452
|
end
|
445
453
|
.,.,
|
446
454
|
|
447
|
-
module_eval(<<'.,.,', 'kdl.yy',
|
455
|
+
module_eval(<<'.,.,', 'kdl.yy', 55)
|
448
456
|
def _reduce_39(val, _values)
|
449
|
-
|
457
|
+
KDL::Value::Null
|
450
458
|
end
|
451
459
|
.,.,
|
452
460
|
|
453
461
|
module_eval(<<'.,.,', 'kdl.yy', 57)
|
454
462
|
def _reduce_40(val, _values)
|
455
|
-
|
463
|
+
true
|
456
464
|
end
|
457
465
|
.,.,
|
458
466
|
|
459
|
-
|
467
|
+
module_eval(<<'.,.,', 'kdl.yy', 58)
|
468
|
+
def _reduce_41(val, _values)
|
469
|
+
false
|
470
|
+
end
|
471
|
+
.,.,
|
460
472
|
|
461
473
|
# reduce 42 omitted
|
462
474
|
|
@@ -474,8 +486,10 @@ module_eval(<<'.,.,', 'kdl.yy', 57)
|
|
474
486
|
|
475
487
|
# reduce 49 omitted
|
476
488
|
|
477
|
-
|
478
|
-
|
489
|
+
# reduce 50 omitted
|
490
|
+
|
491
|
+
module_eval(<<'.,.,', 'kdl.yy', 65)
|
492
|
+
def _reduce_51(val, _values)
|
479
493
|
nil
|
480
494
|
end
|
481
495
|
.,.,
|
data/lib/kdl/kdl.yy
CHANGED
@@ -14,23 +14,24 @@ rule
|
|
14
14
|
document : nodes { KDL::Document.new(val[0]) }
|
15
15
|
| linespaces { KDL::Document.new([])}
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
node
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
17
|
+
nodes : none { [] }
|
18
|
+
| linespace_star node { [val[1]] }
|
19
|
+
| linespace_star empty_node { [] }
|
20
|
+
| nodes node { [*val[0], val[1]] }
|
21
|
+
| nodes empty_node { val[0] }
|
22
|
+
node : untyped_node { val[0] }
|
23
|
+
| type untyped_node { val[1].as_type(val[0], @type_parsers.fetch(val[0], nil)) }
|
24
|
+
untyped_node : node_decl node_term { val[0].tap { |x| x.children = nil } }
|
25
|
+
| node_decl node_children node_term { val[0].tap { |x| x.children = val[1] } }
|
26
|
+
| node_decl empty_children node_term { val[0].tap { |x| x.children = nil } }
|
27
|
+
node_decl : identifier { KDL::Node.new(val[0]) }
|
28
|
+
| node_decl WS value { val[0].tap { |x| x.arguments << val[2] } }
|
29
|
+
| node_decl WS SLASHDASH ws_star value { val[0] }
|
30
|
+
| node_decl WS property { val[0].tap { |x| x.properties[val[2][0]] = val[2][1] } }
|
31
|
+
| node_decl WS SLASHDASH ws_star property { val[0] }
|
32
|
+
empty_node : SLASHDASH ws_star node
|
33
|
+
node_children : ws_star LBRACE nodes RBRACE { val[2] }
|
34
|
+
| ws_star LBRACE linespace_star RBRACE { [] }
|
34
35
|
empty_children: SLASHDASH node_children
|
35
36
|
| WS empty_children
|
36
37
|
node_term: linespaces | semicolon_term
|
@@ -45,7 +46,7 @@ rule
|
|
45
46
|
property: identifier EQUALS value { [val[0], val[2]] }
|
46
47
|
|
47
48
|
value : untyped_value
|
48
|
-
| type untyped_value { val[1].as_type(val[0]) }
|
49
|
+
| type untyped_value { val[1].as_type(val[0], @type_parsers.fetch(val[0], nil)) }
|
49
50
|
|
50
51
|
untyped_value : STRING { KDL::Value::String.new(val[0].value) }
|
51
52
|
| RAWSTRING { KDL::Value::String.new(val[0].value) }
|
@@ -65,7 +66,13 @@ rule
|
|
65
66
|
none: { nil }
|
66
67
|
|
67
68
|
---- inner
|
68
|
-
|
69
|
+
|
70
|
+
def parse(str, options = {})
|
71
|
+
if options.fetch(:parse_types, true)
|
72
|
+
@type_parsers = ::KDL::Types::MAPPING.merge(options.fetch(:type_parsers, {}))
|
73
|
+
else
|
74
|
+
@type_parsers = {}
|
75
|
+
end
|
69
76
|
@tokenizer = ::KDL::Tokenizer.new(str)
|
70
77
|
do_parse
|
71
78
|
end
|
data/lib/kdl/node.rb
CHANGED
@@ -38,6 +38,23 @@ module KDL
|
|
38
38
|
children == other.children
|
39
39
|
end
|
40
40
|
|
41
|
+
def as_type(type, parser = nil)
|
42
|
+
if parser.nil?
|
43
|
+
@type = type
|
44
|
+
self
|
45
|
+
else
|
46
|
+
result = parser.call(self, type)
|
47
|
+
|
48
|
+
return self.as_type(type) if result.nil?
|
49
|
+
|
50
|
+
unless result.is_a?(::KDL::Node)
|
51
|
+
raise ArgumentError, "expected parser to return an instance of ::KDL::Node, got `#{result.class}'"
|
52
|
+
end
|
53
|
+
|
54
|
+
result
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
41
58
|
private
|
42
59
|
|
43
60
|
def id_to_s(id)
|