hcl-checker 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +23 -1
- data/README.md +15 -5
- data/Rakefile +7 -6
- data/assets/lexer.rex +1 -1
- data/assets/parse.y +2 -1
- data/hcl-checker.gemspec +4 -0
- data/lib/hcl/checker/version.rb +1 -1
- data/lib/hcl/checker.rb +8 -1
- data/lib/hcl/lexer.rb +1 -1
- data/lib/hcl/parser.rb +19 -18
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e120cd46c80de3764fa4e5842c9fec7472931b9
|
4
|
+
data.tar.gz: e0a590bf486fd5e9800a43f4c92bb854002fa88e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d28e21092462fae8c51f89e59c6c71144932b95703c00e769713a144e762bcaa618b0af7c4d190598c285906582c3bd3f3ef7f0447c20681368048d69f50a334
|
7
|
+
data.tar.gz: 010365b5ccfafbeaed12fbfdb52fac26dbc381201ef868b17baff5f68c4f07780c4b917bf9bec5c61b6f7c23b9e4fa6b5cd11b143785517c81dcd0e1a78b3e24
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hcl-checker (1.0.
|
4
|
+
hcl-checker (1.0.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.3)
|
10
|
+
filesize (0.1.1)
|
11
|
+
jsobfu (0.4.2)
|
12
|
+
rkelly-remix
|
13
|
+
json (2.0.4)
|
14
|
+
metasm (1.0.3)
|
15
|
+
mini_portile2 (2.3.0)
|
16
|
+
nokogiri (1.8.2)
|
17
|
+
mini_portile2 (~> 2.3.0)
|
18
|
+
racc (1.4.14)
|
10
19
|
rake (10.4.2)
|
20
|
+
rb-readline (0.5.5)
|
21
|
+
rex (2.0.12)
|
22
|
+
filesize (~> 0)
|
23
|
+
jsobfu (~> 0)
|
24
|
+
json (~> 2)
|
25
|
+
metasm (~> 1)
|
26
|
+
nokogiri (~> 1)
|
27
|
+
rb-readline (~> 0)
|
28
|
+
rexical (1.0.5)
|
29
|
+
rkelly-remix (0.0.7)
|
11
30
|
rspec (3.7.0)
|
12
31
|
rspec-core (~> 3.7.0)
|
13
32
|
rspec-expectations (~> 3.7.0)
|
@@ -28,7 +47,10 @@ PLATFORMS
|
|
28
47
|
DEPENDENCIES
|
29
48
|
bundler (~> 1.16)
|
30
49
|
hcl-checker!
|
50
|
+
racc (= 1.4.14)
|
31
51
|
rake (~> 10.0)
|
52
|
+
rex (= 2.0.12)
|
53
|
+
rexical (= 1.0.5)
|
32
54
|
rspec (~> 3.0)
|
33
55
|
|
34
56
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -33,6 +33,7 @@ hcl_string = 'provider "aws" {
|
|
33
33
|
secret_key = "${var.aws_secret_key}"
|
34
34
|
}
|
35
35
|
|
36
|
+
# This is a awesome comment
|
36
37
|
resource "aws_vpc" "default" {
|
37
38
|
cidr_block = "10.0.0.0/16"
|
38
39
|
enable_dns_hostnames = true
|
@@ -57,6 +58,13 @@ You can parse the `hcl_string` into a `Hash` with `parse` method.
|
|
57
58
|
=> {"provider"=>{"aws"=>{"region"=>"${var.aws_region}", "access_key"=>"${var.aws_access_key}", "secret_key"=>"${var.aws_secret_key}"}}, "resource"=>{"aws_vpc"=>{"default"=>{"cidr_block"=>"10.0.0.0/16", "enable_dns_hostnames"=>true, "tags"=>{"Name"=>"Event Store VPC"}}}}}
|
58
59
|
```
|
59
60
|
|
61
|
+
If after a `parse` you got `false` you can check `last_error` with:
|
62
|
+
|
63
|
+
```
|
64
|
+
2.4.2 :063 > HCL::Checker.last_error
|
65
|
+
=> "Parse error at \"eec8b16c-ee89-4ea0-bdcc-d094300a42e8\" , (invalid token: ,)"
|
66
|
+
```
|
67
|
+
|
60
68
|
## Development
|
61
69
|
|
62
70
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
@@ -69,12 +77,14 @@ release a new version, update the version number in `version.rb`, and then run
|
|
69
77
|
git commits and tags, and push the `.gem` file to
|
70
78
|
[rubygems.org](https://rubygems.org).
|
71
79
|
|
72
|
-
###
|
73
|
-
- Built using the `rexical` library (https://github.com/tenderlove/rexical)
|
74
|
-
|
75
|
-
### Parser
|
76
|
-
- Built using the `racc` library (https://github.com/tenderlove/racc)
|
80
|
+
### Building grammar
|
77
81
|
|
82
|
+
```
|
83
|
+
$ bundle exec rake build_grammar
|
84
|
+
Building Lexer....done
|
85
|
+
Building Parser....done
|
86
|
+
```
|
87
|
+
|
78
88
|
## Contributing
|
79
89
|
|
80
90
|
Bug reports and pull requests are welcome on GitHub at
|
data/Rakefile
CHANGED
@@ -7,12 +7,13 @@ RSpec::Core::RakeTask.new do |c|
|
|
7
7
|
c.rspec_opts = options
|
8
8
|
end
|
9
9
|
|
10
|
-
desc "Generate HCL
|
11
|
-
task :
|
10
|
+
desc "Generate Grammar files for HCL"
|
11
|
+
task :build_grammar do
|
12
|
+
print 'Building Lexer'
|
12
13
|
`rex ./assets/lexer.rex -o ./lib/hcl/lexer.rb`
|
14
|
+
print "....done\n"
|
15
|
+
print 'Building Parser'
|
16
|
+
`racc ./assets/parse.y -o ./lib/hcl/parser.rb`
|
17
|
+
print "....done\n\n"
|
13
18
|
end
|
14
19
|
|
15
|
-
desc "Generate HCL Parser"
|
16
|
-
task :parser do
|
17
|
-
`racc ./assets/parse.y -o ./lib/parser.rb`
|
18
|
-
end
|
data/assets/lexer.rex
CHANGED
data/assets/parse.y
CHANGED
@@ -135,7 +135,8 @@ require_relative './lexer'
|
|
135
135
|
|
136
136
|
|
137
137
|
def on_error(error_token_id, error_value, value_stack)
|
138
|
-
|
138
|
+
error_message = value_stack.to_s.split(',').last.gsub(']', '')
|
139
|
+
header = "Parse error at #{error_message} #{error_value} (invalid token: #{error_value})"
|
139
140
|
raise Racc::ParseError, header
|
140
141
|
end
|
141
142
|
|
data/hcl-checker.gemspec
CHANGED
@@ -21,4 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
spec.add_development_dependency 'racc', '1.4.14'
|
25
|
+
spec.add_development_dependency 'rex', '2.0.12'
|
26
|
+
spec.add_development_dependency 'rexical', '1.0.5'
|
27
|
+
|
24
28
|
end
|
data/lib/hcl/checker/version.rb
CHANGED
data/lib/hcl/checker.rb
CHANGED
@@ -4,6 +4,10 @@ require_relative 'parser'
|
|
4
4
|
|
5
5
|
module HCL
|
6
6
|
module Checker
|
7
|
+
class << self
|
8
|
+
attr_accessor :last_error
|
9
|
+
end
|
10
|
+
|
7
11
|
def self.valid?(value)
|
8
12
|
ret = HCLParser.new.parse(value)
|
9
13
|
return true if ret.is_a? Hash
|
@@ -14,8 +18,11 @@ module HCL
|
|
14
18
|
|
15
19
|
def self.parse(value)
|
16
20
|
HCLParser.new.parse(value)
|
21
|
+
rescue Racc::ParseError => e
|
22
|
+
self.last_error = e.message
|
23
|
+
return false
|
17
24
|
rescue
|
18
|
-
|
25
|
+
false
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/hcl/lexer.rb
CHANGED
data/lib/hcl/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# DO NOT MODIFY!!!!
|
3
|
-
# This file is automatically generated by Racc 1.4.
|
3
|
+
# This file is automatically generated by Racc 1.4.14
|
4
4
|
# from Racc grammer file "".
|
5
5
|
#
|
6
6
|
|
@@ -34,7 +34,8 @@ module_eval(<<'...end parse.y/module_eval...', 'parse.y', 115)
|
|
34
34
|
|
35
35
|
|
36
36
|
def on_error(error_token_id, error_value, value_stack)
|
37
|
-
|
37
|
+
error_message = value_stack.to_s.split(',').last.gsub(']', '')
|
38
|
+
header = "Parse error at #{error_message} #{error_value} (invalid token: #{error_value})"
|
38
39
|
raise Racc::ParseError, header
|
39
40
|
end
|
40
41
|
|
@@ -69,20 +70,20 @@ module_eval(<<'...end parse.y/module_eval...', 'parse.y', 115)
|
|
69
70
|
|
70
71
|
racc_action_table = [
|
71
72
|
20, 26, 25, 36, 26, 25, 5, 21, 6, 13,
|
72
|
-
33, 24, 35, 26, 25, 30, 5,
|
73
|
-
5,
|
74
|
-
-8, 10
|
73
|
+
33, 24, 35, 26, 25, 30, 5, 18, 6, 33,
|
74
|
+
5, 28, 6, 12, 16, 34, 17, 5, 13, 6,
|
75
|
+
-9, -8, 10 ]
|
75
76
|
|
76
77
|
racc_action_check = [
|
77
|
-
12, 12, 12, 29, 24, 24,
|
78
|
-
24, 12, 29, 36, 36, 24,
|
79
|
-
13, 27,
|
80
|
-
5, 1
|
78
|
+
12, 12, 12, 29, 24, 24, 0, 12, 0, 12,
|
79
|
+
24, 12, 29, 36, 36, 24, 13, 10, 13, 36,
|
80
|
+
27, 13, 27, 7, 9, 27, 9, 3, 9, 3,
|
81
|
+
6, 5, 1 ]
|
81
82
|
|
82
83
|
racc_action_pointer = [
|
83
|
-
|
84
|
-
|
85
|
-
nil, nil, nil, nil, 1, nil, nil,
|
84
|
+
-1, 32, nil, 20, nil, 23, 22, 15, nil, 17,
|
85
|
+
17, nil, -2, 9, nil, nil, nil, nil, nil, nil,
|
86
|
+
nil, nil, nil, nil, 1, nil, nil, 13, nil, -2,
|
86
87
|
nil, nil, nil, nil, nil, nil, 10, nil ]
|
87
88
|
|
88
89
|
racc_action_default = [
|
@@ -92,18 +93,18 @@ racc_action_default = [
|
|
92
93
|
-21, -22, -25, -26, -6, -20, -24, -23 ]
|
93
94
|
|
94
95
|
racc_goto_table = [
|
95
|
-
11, 3, 14, 31,
|
96
|
-
|
96
|
+
11, 3, 14, 31, 15, 22, 29, 19, 2, 1,
|
97
|
+
23, nil, nil, nil, 27, 37, nil, nil, nil, nil,
|
97
98
|
nil, nil, nil, nil, 11 ]
|
98
99
|
|
99
100
|
racc_goto_check = [
|
100
|
-
4, 3, 5, 12,
|
101
|
-
|
101
|
+
4, 3, 5, 12, 9, 5, 11, 7, 2, 1,
|
102
|
+
8, nil, nil, nil, 3, 12, nil, nil, nil, nil,
|
102
103
|
nil, nil, nil, nil, 4 ]
|
103
104
|
|
104
105
|
racc_goto_pointer = [
|
105
|
-
nil,
|
106
|
-
nil, -
|
106
|
+
nil, 9, 8, 1, -3, -7, nil, -5, -2, -5,
|
107
|
+
nil, -18, -21 ]
|
107
108
|
|
108
109
|
racc_goto_default = [
|
109
110
|
nil, nil, nil, nil, 4, nil, 7, 32, nil, 8,
|
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.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Castellani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,48 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: racc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.14
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.4.14
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rex
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.12
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.12
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rexical
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.5
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.5
|
55
97
|
description: Hashicorp Configuration Language parser and checker for Ruby
|
56
98
|
email:
|
57
99
|
- marcelo.castellani@totvs.com.br
|