rhcl 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3ea459cd1905998a2658c09fc35ece76cef0afb1
4
+ data.tar.gz: f708af85594bd2741e6d99c34ce7fe33e706d71a
5
+ SHA512:
6
+ metadata.gz: 9e121c231c8bae306f801637edb414c113cdc7e8be7c1406dbfc5ce15a1059e644779b74e7eca4fd37069cf24b5cde3f707eaa77c17089d6d70e9c4e101f28d7
7
+ data.tar.gz: 8f8dae443ef34f935110716853c29318aaafbfe07b82b772f1531dedd67929fb9cbf6ae01e440ed2ec48d0c4f9684b6e0922a99845873a365a2b9a60cf1f67d9
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script:
5
+ - bundle install
6
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rhcl.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Genki Sugawara
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Rhcl
2
+
3
+ Pure Ruby [HCL](https://github.com/hashicorp/hcl) parser
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/rhcl.png)](http://badge.fury.io/rb/rhcl)
6
+ [![Build Status](https://travis-ci.org/winebarrel/rhcl.svg?branch=master)](https://travis-ci.org/winebarrel/rhcl)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'rhcl'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rhcl
21
+
22
+ ## Usage
23
+
24
+ ### Parse
25
+
26
+ ```ruby
27
+ Rhcl.parse(<<-EOS)
28
+ variable "foo" {
29
+ default = "bar"
30
+ description = "bar"
31
+ }
32
+
33
+ variable "amis" {
34
+ default = {
35
+ east = "foo"
36
+ }
37
+ }
38
+ EOS
39
+ ```
40
+
41
+ ### Dump
42
+
43
+ ```ruby
44
+ Rhcl.dump(
45
+ {"variable"=>
46
+ {"foo"=>{"default"=>"bar", "description"=>"bar"},
47
+ "amis"=>{"default"=>{"east"=>"foo"}}}}
48
+ )
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( http://github.com/winebarrel/rhcl/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ module Rhcl
2
+ def parse(obj)
3
+ Rhcl::Parse.parse(obj)
4
+ end
5
+ module_function :parse
6
+
7
+ def dump(obj)
8
+ Rhcl::Dump.dump(obj)
9
+ end
10
+ module_function :dump
11
+ end
12
+
13
+ require 'deep_merge'
14
+ require 'rhcl/dump'
15
+ require 'rhcl/parse.tab'
16
+ require 'rhcl/version'
@@ -0,0 +1,36 @@
1
+ class Rhcl::Dump
2
+ class << self
3
+ def dump(obj)
4
+ unless obj.kind_of?(Hash)
5
+ raise TypeError, "wrong argument type #{obj.class} (expected Hash)"
6
+ end
7
+
8
+ dump0(obj).sub(/\A\s*\{/, '').sub(/\}\s*\z/, '').strip.gsub(/^\s+$/m, '')
9
+ end
10
+
11
+ private
12
+ def dump0(obj, depth = 0)
13
+ prefix = ' ' * depth
14
+ prefix0 = ' ' * (depth.zero? ? 0 : depth - 1)
15
+
16
+ case obj
17
+ when Array
18
+ '[' +
19
+ obj.map {|i| dump0(i, depth + 1) }.join(', ') +
20
+ "]\n"
21
+ when Hash
22
+ "#{prefix}{\n#{prefix}" +
23
+ obj.map {|k, v|
24
+ k = k.to_s.strip
25
+ k = k.inspect unless k =~ /\A\w+\z/
26
+ k + (v.kind_of?(Hash) ? ' ' : " = ") + dump0(v, depth + 1).strip
27
+ }.join("\n#{prefix}") +
28
+ "\n#{prefix0}}\n"
29
+ when Numeric, TrueClass, FalseClass
30
+ obj.inspect
31
+ else
32
+ obj.to_s.inspect
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,389 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.11
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require 'strscan'
11
+
12
+ module Rhcl
13
+ class Parse < Racc::Parser
14
+
15
+ module_eval(<<'...end parse.y/module_eval...', 'parse.y', 107)
16
+
17
+ def initialize(obj)
18
+ src = obj.is_a?(IO) ? obj.read : obj.to_s
19
+ @ss = StringScanner.new(src)
20
+ end
21
+
22
+ def scan
23
+ tok = nil
24
+
25
+ until @ss.eos?
26
+ if (tok = @ss.scan /\s+/)
27
+ # nothing to do
28
+ elsif (tok = @ss.scan(/#/))
29
+ @ss.scan_until(/\n/)
30
+ elsif (tok = @ss.scan(%r|/|))
31
+ case @ss.getch
32
+ when '/'
33
+ @ss.scan_until(/(\n|\z)/)
34
+ when '*'
35
+ nested = 1
36
+
37
+ until nested.zero?
38
+ case @ss.scan_until(%r{(/\*|\*/|\z)})
39
+ when %r|/\*\z|
40
+ nested += 1
41
+ when %r|\*/\z|
42
+ nested -= 1
43
+ else
44
+ break
45
+ end
46
+ end
47
+ else
48
+ raise "comment expected, got '#{tok}'"
49
+ end
50
+ elsif (tok = @ss.scan(/-?\d+\.\d+/))
51
+ yield [:FLOAT, tok.to_f]
52
+ elsif (tok = @ss.scan(/-?\d+/))
53
+ yield [:INTEGER, tok.to_i]
54
+ elsif (tok = @ss.scan(/,/))
55
+ yield [:COMMA, tok]
56
+ elsif (tok = @ss.scan(/\=/))
57
+ yield [:EQUAL, tok]
58
+ elsif (tok = @ss.scan(/\[/))
59
+ yield [:LEFTBRACKET, tok]
60
+ elsif (tok = @ss.scan(/\]/))
61
+ yield [:RIGHTBRACKET, tok]
62
+ elsif (tok = @ss.scan(/\{/))
63
+ yield [:LEFTBRACE, tok]
64
+ elsif (tok = @ss.scan(/\}/))
65
+ yield [:RIGHTBRACE, tok]
66
+ elsif (tok = @ss.scan(/"/))
67
+ yield [:STRING, (@ss.scan_until(/("|\z)/) || '').sub(/"\z/, '')]
68
+ else
69
+ identifier = (@ss.scan_until(/(\s|\z)/) || '').sub(/\s\z/, '')
70
+ token_type = :IDENTIFIER
71
+
72
+ if ['true', 'false'].include?(identifier)
73
+ identifier = !!(identifier =~ /true/)
74
+ token_type = :BOOL
75
+ end
76
+
77
+ yield [token_type, identifier]
78
+ end
79
+ end
80
+
81
+ yield [false, '$end']
82
+ end
83
+ private :scan
84
+
85
+ def parse
86
+ yyparse self, :scan
87
+ end
88
+
89
+ def self.parse(obj)
90
+ self.new(obj).parse
91
+ end
92
+ ...end parse.y/module_eval...
93
+ ##### State transition tables begin ###
94
+
95
+ racc_action_table = [
96
+ 10, 31, 32, 9, 16, 17, 20, 7, 14, 21,
97
+ 22, 3, nil, 29, 6, 26, nil, 21, 22, 10,
98
+ 3, 13, 29, 6, 6, nil, 21, 22, 30, 3,
99
+ 24, 3, 6, nil, 6 ]
100
+
101
+ racc_action_check = [
102
+ 9, 25, 25, 3, 9, 9, 9, 1, 7, 9,
103
+ 9, 1, nil, 20, 1, 20, nil, 20, 20, 5,
104
+ 0, 5, 32, 0, 5, nil, 32, 32, 23, 23,
105
+ 10, 10, 23, nil, 10 ]
106
+
107
+ racc_action_pointer = [
108
+ 16, 7, nil, -2, nil, 17, nil, 8, nil, -2,
109
+ 27, nil, nil, nil, nil, nil, nil, nil, nil, nil,
110
+ 6, nil, nil, 25, nil, -8, nil, nil, nil, nil,
111
+ nil, nil, 15, nil ]
112
+
113
+ racc_action_default = [
114
+ -23, -23, -1, -13, -10, -23, -14, -23, -2, -23,
115
+ -23, -11, -12, -13, 34, -5, -6, -7, -8, -9,
116
+ -23, -21, -22, -23, -4, -23, -16, -17, -19, -20,
117
+ -3, -15, -23, -18 ]
118
+
119
+ racc_goto_table = [
120
+ 8, 27, 1, 11, 12, 15, 25, 18, 19, nil,
121
+ nil, nil, 23, 33, nil, nil, nil, nil, nil, nil,
122
+ nil, nil, 8 ]
123
+
124
+ racc_goto_check = [
125
+ 2, 9, 1, 3, 6, 4, 8, 3, 5, nil,
126
+ nil, nil, 1, 9, nil, nil, nil, nil, nil, nil,
127
+ nil, nil, 2 ]
128
+
129
+ racc_goto_pointer = [
130
+ nil, 2, -1, -2, -4, -1, -1, nil, -14, -19 ]
131
+
132
+ racc_goto_default = [
133
+ nil, nil, 2, nil, 28, nil, 4, 5, nil, nil ]
134
+
135
+ racc_reduce_table = [
136
+ 0, 0, :racc_error,
137
+ 1, 14, :_reduce_1,
138
+ 2, 14, :_reduce_2,
139
+ 3, 16, :_reduce_3,
140
+ 2, 16, :_reduce_4,
141
+ 3, 15, :_reduce_5,
142
+ 3, 15, :_reduce_6,
143
+ 3, 15, :_reduce_7,
144
+ 3, 15, :_reduce_8,
145
+ 3, 15, :_reduce_9,
146
+ 1, 15, :_reduce_10,
147
+ 2, 19, :_reduce_11,
148
+ 2, 19, :_reduce_12,
149
+ 1, 20, :_reduce_13,
150
+ 1, 20, :_reduce_14,
151
+ 3, 18, :_reduce_15,
152
+ 2, 18, :_reduce_16,
153
+ 1, 21, :_reduce_17,
154
+ 3, 21, :_reduce_18,
155
+ 1, 22, :_reduce_19,
156
+ 1, 22, :_reduce_20,
157
+ 1, 17, :_reduce_21,
158
+ 1, 17, :_reduce_22 ]
159
+
160
+ racc_reduce_n = 23
161
+
162
+ racc_shift_n = 34
163
+
164
+ racc_token_table = {
165
+ false => 0,
166
+ :error => 1,
167
+ :LEFTBRACE => 2,
168
+ :RIGHTBRACE => 3,
169
+ :IDENTIFIER => 4,
170
+ :EQUAL => 5,
171
+ :BOOL => 6,
172
+ :STRING => 7,
173
+ :LEFTBRACKET => 8,
174
+ :RIGHTBRACKET => 9,
175
+ :COMMA => 10,
176
+ :INTEGER => 11,
177
+ :FLOAT => 12 }
178
+
179
+ racc_nt_base = 13
180
+
181
+ racc_use_result_var = false
182
+
183
+ Racc_arg = [
184
+ racc_action_table,
185
+ racc_action_check,
186
+ racc_action_default,
187
+ racc_action_pointer,
188
+ racc_goto_table,
189
+ racc_goto_check,
190
+ racc_goto_default,
191
+ racc_goto_pointer,
192
+ racc_nt_base,
193
+ racc_reduce_table,
194
+ racc_token_table,
195
+ racc_shift_n,
196
+ racc_reduce_n,
197
+ racc_use_result_var ]
198
+
199
+ Racc_token_to_s_table = [
200
+ "$end",
201
+ "error",
202
+ "LEFTBRACE",
203
+ "RIGHTBRACE",
204
+ "IDENTIFIER",
205
+ "EQUAL",
206
+ "BOOL",
207
+ "STRING",
208
+ "LEFTBRACKET",
209
+ "RIGHTBRACKET",
210
+ "COMMA",
211
+ "INTEGER",
212
+ "FLOAT",
213
+ "$start",
214
+ "objectlist",
215
+ "objectitem",
216
+ "object",
217
+ "number",
218
+ "list",
219
+ "block",
220
+ "blockId",
221
+ "listitems",
222
+ "listitem" ]
223
+
224
+ Racc_debug_parser = false
225
+
226
+ ##### State transition tables end #####
227
+
228
+ # reduce 0 omitted
229
+
230
+ module_eval(<<'.,.,', 'parse.y', 5)
231
+ def _reduce_1(val, _values)
232
+ val[0]
233
+
234
+ end
235
+ .,.,
236
+
237
+ module_eval(<<'.,.,', 'parse.y', 9)
238
+ def _reduce_2(val, _values)
239
+ val[0].deep_merge(val[1])
240
+
241
+ end
242
+ .,.,
243
+
244
+ module_eval(<<'.,.,', 'parse.y', 14)
245
+ def _reduce_3(val, _values)
246
+ val[1]
247
+
248
+ end
249
+ .,.,
250
+
251
+ module_eval(<<'.,.,', 'parse.y', 18)
252
+ def _reduce_4(val, _values)
253
+ {}
254
+
255
+ end
256
+ .,.,
257
+
258
+ module_eval(<<'.,.,', 'parse.y', 23)
259
+ def _reduce_5(val, _values)
260
+ {val[0] => val[2]}
261
+
262
+ end
263
+ .,.,
264
+
265
+ module_eval(<<'.,.,', 'parse.y', 27)
266
+ def _reduce_6(val, _values)
267
+ {val[0] => val[2]}
268
+
269
+ end
270
+ .,.,
271
+
272
+ module_eval(<<'.,.,', 'parse.y', 31)
273
+ def _reduce_7(val, _values)
274
+ {val[0] => val[2]}
275
+
276
+ end
277
+ .,.,
278
+
279
+ module_eval(<<'.,.,', 'parse.y', 35)
280
+ def _reduce_8(val, _values)
281
+ {val[0] => val[2]}
282
+
283
+ end
284
+ .,.,
285
+
286
+ module_eval(<<'.,.,', 'parse.y', 39)
287
+ def _reduce_9(val, _values)
288
+ {val[0] => val[2]}
289
+
290
+ end
291
+ .,.,
292
+
293
+ module_eval(<<'.,.,', 'parse.y', 43)
294
+ def _reduce_10(val, _values)
295
+ val[0]
296
+
297
+ end
298
+ .,.,
299
+
300
+ module_eval(<<'.,.,', 'parse.y', 48)
301
+ def _reduce_11(val, _values)
302
+ {val[0] => val[1]}
303
+
304
+ end
305
+ .,.,
306
+
307
+ module_eval(<<'.,.,', 'parse.y', 52)
308
+ def _reduce_12(val, _values)
309
+ {val[0] => val[1]}
310
+
311
+ end
312
+ .,.,
313
+
314
+ module_eval(<<'.,.,', 'parse.y', 58)
315
+ def _reduce_13(val, _values)
316
+ val[0]
317
+
318
+ end
319
+ .,.,
320
+
321
+ module_eval(<<'.,.,', 'parse.y', 62)
322
+ def _reduce_14(val, _values)
323
+ val[0]
324
+
325
+ end
326
+ .,.,
327
+
328
+ module_eval(<<'.,.,', 'parse.y', 67)
329
+ def _reduce_15(val, _values)
330
+ val[1]
331
+
332
+ end
333
+ .,.,
334
+
335
+ module_eval(<<'.,.,', 'parse.y', 71)
336
+ def _reduce_16(val, _values)
337
+ []
338
+
339
+ end
340
+ .,.,
341
+
342
+ module_eval(<<'.,.,', 'parse.y', 76)
343
+ def _reduce_17(val, _values)
344
+ [val[0]]
345
+
346
+ end
347
+ .,.,
348
+
349
+ module_eval(<<'.,.,', 'parse.y', 80)
350
+ def _reduce_18(val, _values)
351
+ val[0] + [val[2]]
352
+
353
+ end
354
+ .,.,
355
+
356
+ module_eval(<<'.,.,', 'parse.y', 85)
357
+ def _reduce_19(val, _values)
358
+ val[0]
359
+
360
+ end
361
+ .,.,
362
+
363
+ module_eval(<<'.,.,', 'parse.y', 89)
364
+ def _reduce_20(val, _values)
365
+ val[0]
366
+
367
+ end
368
+ .,.,
369
+
370
+ module_eval(<<'.,.,', 'parse.y', 94)
371
+ def _reduce_21(val, _values)
372
+ val[0]
373
+
374
+ end
375
+ .,.,
376
+
377
+ module_eval(<<'.,.,', 'parse.y', 98)
378
+ def _reduce_22(val, _values)
379
+ val[0]
380
+
381
+ end
382
+ .,.,
383
+
384
+ def _reduce_none(val, _values)
385
+ val[0]
386
+ end
387
+
388
+ end # class Parse
389
+ end # module Rhcl