hcl-checker 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hcl-checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Castellani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,36 +119,16 @@ files:
119
119
  - lib/hcl/checker/version.rb
120
120
  - lib/hcl/lexer.rb
121
121
  - lib/hcl/parser.rb
122
- - lib/hcl1/checker.rb
123
- - lib/hcl1/checker/version.rb
124
- - lib/hcl1/lexer.rb
125
- - lib/hcl1/parser.rb
126
122
  homepage: https://github.com/mfcastellani/hcl-checker
127
123
  licenses:
128
124
  - MIT
129
125
  metadata: {}
130
126
  post_install_message: |2
131
127
 
132
- Hello, I am updating this Gem to support version 2.0 of the HCL.
133
-
134
- In the meantime, it is important that you know that there will be a
135
- compatibility break with the current version, for Gem to support both
136
- versions.
137
-
138
- Therefore, instead of using just HCL::Checker you must tell which
139
- version you are using, like this:
140
-
141
- HCL1::Checker
142
-
143
- Or
144
-
145
- HCL2::Checker
146
-
147
- At the moment both HCL::Checker and HCL1::Checker will work, but with
148
- the release of support for version 2 the HCL::Checker syntax will no
149
- longer work.
150
-
151
- So, update your code.
128
+ Hello, me again. After several contacts of users of this gem requesting that
129
+ the module name be kept only as HCL, instead of HCL1 and HCL2, I went back and
130
+ kept it. Sorry for those who eventually switched from HCL to HCL1. And thanks to
131
+ everyone who got in touch justifying why my change would be bad for all users.
152
132
 
153
133
  Thank you :)
154
134
  rdoc_options: []
@@ -158,14 +138,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
138
  requirements:
159
139
  - - ">="
160
140
  - !ruby/object:Gem::Version
161
- version: '0'
141
+ version: 2.5.0
162
142
  required_rubygems_version: !ruby/object:Gem::Requirement
163
143
  requirements:
164
144
  - - ">="
165
145
  - !ruby/object:Gem::Version
166
146
  version: '0'
167
147
  requirements: []
168
- rubygems_version: 3.1.2
148
+ rubygems_version: 3.0.8
169
149
  signing_key:
170
150
  specification_version: 4
171
151
  summary: Hashicorp Configuration Language parser for Ruby
@@ -1,21 +0,0 @@
1
- require 'hcl/checker/version'
2
- require_relative 'lexer'
3
- require_relative 'parser'
4
-
5
- module HCL1
6
- module Checker
7
- def self.valid?(value)
8
- ret = HCLParser.new.parse(value)
9
- return true if ret.is_a? Hash
10
- false
11
- rescue
12
- false
13
- end
14
-
15
- def self.parse(value)
16
- HCLParser.new.parse(value)
17
- rescue Racc::ParseError => e
18
- return e.message
19
- end
20
- end
21
- end
@@ -1,5 +0,0 @@
1
- module HCL1
2
- module Checker
3
- VERSION = '1.4.0'
4
- end
5
- end
@@ -1,175 +0,0 @@
1
- #--
2
- # DO NOT MODIFY!!!!
3
- # This file is automatically generated by rex 1.0.7
4
- # from lexical definition file "./assets/lexer.rex".
5
- #++
6
-
7
-
8
- class HCLLexer
9
- require 'strscan'
10
-
11
- class ScanError < StandardError ; end
12
-
13
- attr_reader :lineno
14
- attr_reader :filename
15
- attr_accessor :state
16
-
17
- def scan_setup(str)
18
- @ss = StringScanner.new(str)
19
- @lineno = 1
20
- @state = nil
21
- end
22
-
23
- def action
24
- yield
25
- end
26
-
27
- def scan_str(str)
28
- scan_setup(str)
29
- do_parse
30
- end
31
- alias :scan :scan_str
32
-
33
- def load_file( filename )
34
- @filename = filename
35
- File.open(filename, "r") do |f|
36
- scan_setup(f.read)
37
- end
38
- end
39
-
40
- def scan_file( filename )
41
- load_file(filename)
42
- do_parse
43
- end
44
-
45
-
46
- def next_token
47
- return if @ss.eos?
48
-
49
- # skips empty actions
50
- until token = _next_token or @ss.eos?; end
51
- token
52
- end
53
-
54
- def _next_token
55
- text = @ss.peek(1)
56
- @lineno += 1 if text == "\n"
57
- token = case @state
58
- when nil
59
- case
60
- when (text = @ss.scan(/\s+/))
61
- ;
62
-
63
- when (text = @ss.scan(/\#.*|\/\/.*$/))
64
- ;
65
-
66
- when (text = @ss.scan(/\n|\r/))
67
- ;
68
-
69
- when (text = @ss.scan(/\/\*/))
70
- action { consume_comment(text) }
71
-
72
- when (text = @ss.scan(/true|false/))
73
- action { [:BOOL, to_boolean(text)]}
74
-
75
- when (text = @ss.scan(/\-?\d+\.\d+/))
76
- action { [:FLOAT, text.to_f] }
77
-
78
- when (text = @ss.scan(/-?\d+/))
79
- action { [:NUMBER, text.to_i] }
80
-
81
- when (text = @ss.scan(/\"/))
82
- action { [:STRING, consume_string(text)] }
83
-
84
- when (text = @ss.scan(/\<<\-?/))
85
- action { [:STRING, consume_heredoc] }
86
-
87
- when (text = @ss.scan(/\{/))
88
- action { [:LEFTBRACE, text]}
89
-
90
- when (text = @ss.scan(/\}/))
91
- action { [:RIGHTBRACE, text]}
92
-
93
- when (text = @ss.scan(/\[/))
94
- action { [:LEFTBRACKET, text]}
95
-
96
- when (text = @ss.scan(/\]/))
97
- action { [:RIGHTBRACKET, text]}
98
-
99
- when (text = @ss.scan(/\,/))
100
- action { [:COMMA, text]}
101
-
102
- when (text = @ss.scan(/[a-zA-Z_][a-zA-Z0-9_\-\.]*/))
103
- action { [:IDENTIFIER, text]}
104
-
105
- when (text = @ss.scan(/\=/))
106
- action { [:EQUAL, text]}
107
-
108
- when (text = @ss.scan(/\-/))
109
- action { [:MINUS, text]}
110
-
111
-
112
- else
113
- text = @ss.string[@ss.pos .. -1]
114
- raise ScanError, "can not match: '" + text + "'"
115
- end # if
116
-
117
- else
118
- raise ScanError, "undefined state: '" + state.to_s + "'"
119
- end # case state
120
- token
121
- end # def _next_token
122
-
123
- def lex(input)
124
- scan_setup(input)
125
- tokens = []
126
- while token = next_token
127
- tokens << token
128
- end
129
- tokens
130
- end
131
- def to_boolean(input)
132
- input =
133
- if input =~ /true/
134
- true
135
- elsif input =~ /false/
136
- false
137
- end
138
- return input
139
- end
140
- def consume_comment(input)
141
- nested = 1
142
- until nested.zero?
143
- case(text = @ss.scan_until(%r{/\*|\*/|\z}) )
144
- when %r{/\*\z}
145
- nested =+ 1
146
- when %r{\*/\z}
147
- nested -= 1
148
- else
149
- break
150
- end
151
- end
152
- end
153
- def consume_string(input)
154
- result = ''
155
- nested = 0
156
- begin
157
- case(text = @ss.scan_until(%r{\"|\$\{|\}|\\}))
158
- when %r{\$\{\z}
159
- nested += 1
160
- when %r{\}\z}
161
- nested -= 1 if nested > 0
162
- when %r{\\\z}
163
- result += text.chop + @ss.getch
164
- next
165
- end
166
- result += text.to_s
167
- end until nested == 0 && text =~ %r{\"\z}
168
- result.chop
169
- end
170
- def consume_heredoc
171
- token = Regexp.new @ss.scan_until(%r{\n})
172
- document = @ss.scan_until(token)
173
- document.chop
174
- end
175
- end # class
@@ -1,456 +0,0 @@
1
- #
2
- # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.14
4
- # from Racc grammer file "".
5
- #
6
-
7
- require 'racc/parser.rb'
8
-
9
- require_relative './lexer'
10
-
11
- class HCLParser < Racc::Parser
12
-
13
- module_eval(<<'...end parse.y/module_eval...', 'parse.y', 123)
14
- #//
15
- #// HCL is unclear on what one should do when duplicate
16
- #// keys are encountered.
17
- #//
18
- #// from decoder.go: if we're at the root or we're directly within
19
- #// a list, decode to hashes, otherwise lists
20
- #//
21
- #// from object.go: there is a flattened list structure
22
- #//
23
- def flatten_objectlist(list)
24
- (list || {}).each_with_object({}) do |a, h|
25
- h[a.first] =
26
- case a.last
27
- when Hash
28
- deep_merge(h[a.first] || {}, a.last)
29
- else
30
- h[a.first] = a.last
31
- end
32
- end
33
- end
34
-
35
-
36
- def on_error(error_token_id, error_value, value_stack)
37
- error_message = value_stack.to_s.split(',').last.gsub(']', '')
38
- header = "Parse error at #{error_message} #{error_value} (invalid token: #{error_value})"
39
- raise Racc::ParseError, header
40
- end
41
-
42
-
43
- def parse(input)
44
- @lexer = HCLLexer.new.lex(input)
45
- do_parse
46
- return @result
47
- end
48
-
49
-
50
- def next_token
51
- @lexer.shift
52
- end
53
-
54
- def deep_merge(hash1, hash2)
55
- hash2.keys.each do |key|
56
- value1 = hash1[key]
57
- value2 = hash2[key]
58
-
59
- if value1.is_a?(Hash) && value2.is_a?(Hash)
60
- hash1[key] = deep_merge(value1, value2)
61
- else
62
- hash1[key] = value2
63
- end
64
- end
65
-
66
- hash1
67
- end
68
- ...end parse.y/module_eval...
69
- ##### State transition tables begin ###
70
-
71
- racc_action_table = [
72
- 22, 28, 27, 10, 28, 27, 5, 23, 6, 14,
73
- 35, 26, 14, 12, 26, 32, 28, 27, 40, 5,
74
- -10, 6, 35, 5, 14, 6, 26, 39, 30, 5,
75
- -11, 6, 13, 17, 38, 18, 19, 14, 20 ]
76
-
77
- racc_action_check = [
78
- 13, 13, 13, 1, 26, 26, 0, 13, 0, 13,
79
- 26, 13, 26, 4, 26, 26, 40, 40, 31, 3,
80
- 5, 3, 40, 14, 40, 14, 40, 31, 14, 29,
81
- 6, 29, 7, 9, 29, 9, 10, 9, 11 ]
82
-
83
- racc_action_pointer = [
84
- -1, 3, nil, 12, 8, 12, 22, 24, nil, 26,
85
- 36, 33, nil, -2, 16, nil, nil, nil, nil, nil,
86
- nil, nil, nil, nil, nil, nil, 1, nil, nil, 22,
87
- nil, 13, nil, nil, nil, nil, nil, nil, nil, nil,
88
- 13, nil ]
89
-
90
- racc_action_default = [
91
- -2, -33, -1, -3, -5, -20, -21, -33, -17, -33,
92
- -33, -7, -4, -33, -33, -18, -19, -20, -21, 42,
93
- -6, -12, -13, -14, -15, -16, -33, -31, -32, -33,
94
- -9, -33, -23, -24, -27, -28, -29, -30, -8, -22,
95
- -26, -25 ]
96
-
97
- racc_goto_table = [
98
- 11, 3, 33, 15, 1, 2, 21, 24, 25, 16,
99
- 31, nil, nil, nil, nil, 29, 41, nil, nil, nil,
100
- nil, nil, nil, nil, nil, nil, 11 ]
101
-
102
- racc_goto_check = [
103
- 4, 3, 12, 5, 1, 2, 7, 5, 8, 9,
104
- 11, nil, nil, nil, nil, 3, 12, nil, nil, nil,
105
- nil, nil, nil, nil, nil, nil, 4 ]
106
-
107
- racc_goto_pointer = [
108
- nil, 4, 5, 1, -3, -6, nil, -7, -5, 0,
109
- nil, -16, -24 ]
110
-
111
- racc_goto_default = [
112
- nil, nil, nil, nil, 4, 37, 7, 34, 36, 8,
113
- 9, nil, nil ]
114
-
115
- racc_reduce_table = [
116
- 0, 0, :racc_error,
117
- 1, 19, :_reduce_1,
118
- 0, 20, :_reduce_2,
119
- 1, 20, :_reduce_none,
120
- 2, 21, :_reduce_4,
121
- 1, 21, :_reduce_5,
122
- 3, 21, :_reduce_6,
123
- 2, 21, :_reduce_7,
124
- 3, 23, :_reduce_8,
125
- 2, 23, :_reduce_9,
126
- 1, 24, :_reduce_10,
127
- 1, 24, :_reduce_11,
128
- 3, 22, :_reduce_12,
129
- 3, 22, :_reduce_13,
130
- 3, 22, :_reduce_14,
131
- 3, 22, :_reduce_15,
132
- 3, 22, :_reduce_16,
133
- 1, 22, :_reduce_17,
134
- 2, 27, :_reduce_18,
135
- 2, 27, :_reduce_19,
136
- 1, 28, :_reduce_20,
137
- 1, 28, :_reduce_21,
138
- 3, 26, :_reduce_22,
139
- 2, 26, :_reduce_23,
140
- 1, 29, :_reduce_24,
141
- 3, 29, :_reduce_25,
142
- 2, 29, :_reduce_26,
143
- 1, 30, :_reduce_27,
144
- 1, 30, :_reduce_28,
145
- 1, 30, :_reduce_29,
146
- 1, 30, :_reduce_30,
147
- 1, 25, :_reduce_31,
148
- 1, 25, :_reduce_32 ]
149
-
150
- racc_reduce_n = 33
151
-
152
- racc_shift_n = 42
153
-
154
- racc_token_table = {
155
- false => 0,
156
- :error => 1,
157
- :BOOL => 2,
158
- :FLOAT => 3,
159
- :NUMBER => 4,
160
- :COMMA => 5,
161
- :COMMAEND => 6,
162
- :IDENTIFIER => 7,
163
- :EQUAL => 8,
164
- :STRING => 9,
165
- :MINUS => 10,
166
- :LEFTBRACE => 11,
167
- :RIGHTBRACE => 12,
168
- :LEFTBRACKET => 13,
169
- :RIGHTBRACKET => 14,
170
- :PERIOD => 15,
171
- :EPLUS => 16,
172
- :EMINUS => 17 }
173
-
174
- racc_nt_base = 18
175
-
176
- racc_use_result_var = true
177
-
178
- Racc_arg = [
179
- racc_action_table,
180
- racc_action_check,
181
- racc_action_default,
182
- racc_action_pointer,
183
- racc_goto_table,
184
- racc_goto_check,
185
- racc_goto_default,
186
- racc_goto_pointer,
187
- racc_nt_base,
188
- racc_reduce_table,
189
- racc_token_table,
190
- racc_shift_n,
191
- racc_reduce_n,
192
- racc_use_result_var ]
193
-
194
- Racc_token_to_s_table = [
195
- "$end",
196
- "error",
197
- "BOOL",
198
- "FLOAT",
199
- "NUMBER",
200
- "COMMA",
201
- "COMMAEND",
202
- "IDENTIFIER",
203
- "EQUAL",
204
- "STRING",
205
- "MINUS",
206
- "LEFTBRACE",
207
- "RIGHTBRACE",
208
- "LEFTBRACKET",
209
- "RIGHTBRACKET",
210
- "PERIOD",
211
- "EPLUS",
212
- "EMINUS",
213
- "$start",
214
- "target",
215
- "top",
216
- "objectlist",
217
- "objectitem",
218
- "object",
219
- "objectkey",
220
- "number",
221
- "list",
222
- "block",
223
- "block_id",
224
- "listitems",
225
- "listitem" ]
226
-
227
- Racc_debug_parser = false
228
-
229
- ##### State transition tables end #####
230
-
231
- # reduce 0 omitted
232
-
233
- module_eval(<<'.,.,', 'parse.y', 19)
234
- def _reduce_1(val, _values, result)
235
- @result = flatten_objectlist(val[0])
236
- result
237
- end
238
- .,.,
239
-
240
- module_eval(<<'.,.,', 'parse.y', 22)
241
- def _reduce_2(val, _values, result)
242
- result = val[0]
243
- result
244
- end
245
- .,.,
246
-
247
- # reduce 3 omitted
248
-
249
- module_eval(<<'.,.,', 'parse.y', 29)
250
- def _reduce_4(val, _values, result)
251
- result = [val[0]]
252
- result
253
- end
254
- .,.,
255
-
256
- module_eval(<<'.,.,', 'parse.y', 31)
257
- def _reduce_5(val, _values, result)
258
- result = [val[0]]
259
- result
260
- end
261
- .,.,
262
-
263
- module_eval(<<'.,.,', 'parse.y', 33)
264
- def _reduce_6(val, _values, result)
265
- result = val[0] << val[1]
266
- result
267
- end
268
- .,.,
269
-
270
- module_eval(<<'.,.,', 'parse.y', 35)
271
- def _reduce_7(val, _values, result)
272
- result = val[0] << val[1]
273
- result
274
- end
275
- .,.,
276
-
277
- module_eval(<<'.,.,', 'parse.y', 40)
278
- def _reduce_8(val, _values, result)
279
- result = flatten_objectlist(val[1])
280
- result
281
- end
282
- .,.,
283
-
284
- module_eval(<<'.,.,', 'parse.y', 42)
285
- def _reduce_9(val, _values, result)
286
- return
287
- result
288
- end
289
- .,.,
290
-
291
- module_eval(<<'.,.,', 'parse.y', 47)
292
- def _reduce_10(val, _values, result)
293
- result = val[0]
294
- result
295
- end
296
- .,.,
297
-
298
- module_eval(<<'.,.,', 'parse.y', 49)
299
- def _reduce_11(val, _values, result)
300
- result = val[0]
301
- result
302
- end
303
- .,.,
304
-
305
- module_eval(<<'.,.,', 'parse.y', 54)
306
- def _reduce_12(val, _values, result)
307
- result = val[0], val[2]
308
- result
309
- end
310
- .,.,
311
-
312
- module_eval(<<'.,.,', 'parse.y', 56)
313
- def _reduce_13(val, _values, result)
314
- result = val[0], val[2]
315
- result
316
- end
317
- .,.,
318
-
319
- module_eval(<<'.,.,', 'parse.y', 58)
320
- def _reduce_14(val, _values, result)
321
- result = val[0], val[2]
322
- result
323
- end
324
- .,.,
325
-
326
- module_eval(<<'.,.,', 'parse.y', 60)
327
- def _reduce_15(val, _values, result)
328
- result = val[0], val[2]
329
- result
330
- end
331
- .,.,
332
-
333
- module_eval(<<'.,.,', 'parse.y', 62)
334
- def _reduce_16(val, _values, result)
335
- result = val[0], val[2]
336
- result
337
- end
338
- .,.,
339
-
340
- module_eval(<<'.,.,', 'parse.y', 64)
341
- def _reduce_17(val, _values, result)
342
- result = val[0]
343
- result
344
- end
345
- .,.,
346
-
347
- module_eval(<<'.,.,', 'parse.y', 69)
348
- def _reduce_18(val, _values, result)
349
- result = val[0], val[1]
350
- result
351
- end
352
- .,.,
353
-
354
- module_eval(<<'.,.,', 'parse.y', 71)
355
- def _reduce_19(val, _values, result)
356
- result = val[0], {val[1][0] => val[1][1]}
357
- result
358
- end
359
- .,.,
360
-
361
- module_eval(<<'.,.,', 'parse.y', 76)
362
- def _reduce_20(val, _values, result)
363
- result = val[0]
364
- result
365
- end
366
- .,.,
367
-
368
- module_eval(<<'.,.,', 'parse.y', 78)
369
- def _reduce_21(val, _values, result)
370
- result = val[0]
371
- result
372
- end
373
- .,.,
374
-
375
- module_eval(<<'.,.,', 'parse.y', 83)
376
- def _reduce_22(val, _values, result)
377
- result = val[1]
378
- result
379
- end
380
- .,.,
381
-
382
- module_eval(<<'.,.,', 'parse.y', 85)
383
- def _reduce_23(val, _values, result)
384
- return
385
- result
386
- end
387
- .,.,
388
-
389
- module_eval(<<'.,.,', 'parse.y', 90)
390
- def _reduce_24(val, _values, result)
391
- result = [val[0]]
392
- result
393
- end
394
- .,.,
395
-
396
- module_eval(<<'.,.,', 'parse.y', 92)
397
- def _reduce_25(val, _values, result)
398
- result = val[0] << val[2]
399
- result
400
- end
401
- .,.,
402
-
403
- module_eval(<<'.,.,', 'parse.y', 94)
404
- def _reduce_26(val, _values, result)
405
- result = val[0]
406
- result
407
- end
408
- .,.,
409
-
410
- module_eval(<<'.,.,', 'parse.y', 99)
411
- def _reduce_27(val, _values, result)
412
- result = val[0]
413
- result
414
- end
415
- .,.,
416
-
417
- module_eval(<<'.,.,', 'parse.y', 101)
418
- def _reduce_28(val, _values, result)
419
- result = val[0]
420
- result
421
- end
422
- .,.,
423
-
424
- module_eval(<<'.,.,', 'parse.y', 103)
425
- def _reduce_29(val, _values, result)
426
- result = val[0]
427
- result
428
- end
429
- .,.,
430
-
431
- module_eval(<<'.,.,', 'parse.y', 105)
432
- def _reduce_30(val, _values, result)
433
- result = val[0]
434
- result
435
- end
436
- .,.,
437
-
438
- module_eval(<<'.,.,', 'parse.y', 110)
439
- def _reduce_31(val, _values, result)
440
- result = val[0]
441
- result
442
- end
443
- .,.,
444
-
445
- module_eval(<<'.,.,', 'parse.y', 112)
446
- def _reduce_32(val, _values, result)
447
- result = val[0]
448
- result
449
- end
450
- .,.,
451
-
452
- def _reduce_none(val, _values, result)
453
- val[0]
454
- end
455
-
456
- end # class HCLParser