hcl_parser 0.1.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.md +16 -0
- data/lib/hcl_parser/loader.rb +70 -0
- data/lib/hcl_parser/version.rb +1 -1
- metadata +4 -4
- data/Gemfile.lock +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68e7a4474d1b96b0da7990388f077728a3c11ae198dae2a6f6863cc8c9abc0c
|
4
|
+
data.tar.gz: 37a31807784ddf3d81472d9834da1b41a9eb337bdbebfd2e273e41deac457986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f1870f3f238bdb0074ff6718945697a44bfe5390231b684598202fe4b47633af565fa5e025e6813c63600af248066d84a0e209163a6184193e66a95e668bca8
|
7
|
+
data.tar.gz: 97c932c7b10ed1afd4eee68afb94b3cf193c766efe9016606d40463456f0c93fe133ac5e2320d7e889d0f5f5d8493ac2d9b8ac85d1bd33f2a00d5cce307cdb6a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
|
+
|
6
|
+
## [0.2.2] - 2022-08-26
|
7
|
+
- [#5](https://github.com/boltops-tools/hcl_parser/pull/5) handle single line variable
|
8
|
+
|
9
|
+
## [0.2.1] - 2021-11-28
|
10
|
+
- [#2](https://github.com/boltops-tools/hcl_parser/pull/2) improve complex type parser: handle any
|
11
|
+
|
12
|
+
## [0.2.0] - 2021-11-25
|
13
|
+
- [#1](https://github.com/boltops-tools/hcl_parser/pull/1) Complex types
|
14
|
+
|
15
|
+
## [0.1.0]
|
16
|
+
* Initial release
|
data/lib/hcl_parser/loader.rb
CHANGED
@@ -17,6 +17,76 @@ module HclParser
|
|
17
17
|
def code
|
18
18
|
return @code if @code
|
19
19
|
@code = fix_quotes(@raw)
|
20
|
+
@code = rewrite_complex_types(@code)
|
21
|
+
end
|
22
|
+
|
23
|
+
def rewrite_complex_types(raw)
|
24
|
+
lines = raw.split("\n")
|
25
|
+
results = []
|
26
|
+
|
27
|
+
variable_start_found = false
|
28
|
+
variable_start_index = nil
|
29
|
+
variable_end_index = nil
|
30
|
+
rewrite_lines = false
|
31
|
+
|
32
|
+
lines.each_with_index do |l,i|
|
33
|
+
# We dont rewrite lines until the next line/iteration
|
34
|
+
# This is actually the next iteration since we set rewrite_lines = true previously
|
35
|
+
# in rewrite_lines = complex_type_lines?(lookahead_lines)
|
36
|
+
if rewrite_lines
|
37
|
+
if complex_type_line?(l)
|
38
|
+
# Doesnt matter what the default value is as long as there is one
|
39
|
+
# Doing this in case the default value spans multiple lines
|
40
|
+
results << ' default = "any"'
|
41
|
+
elsif simple_default_assignment?(l)
|
42
|
+
results << l
|
43
|
+
else
|
44
|
+
results << "# #{l}"
|
45
|
+
end
|
46
|
+
else
|
47
|
+
results << l
|
48
|
+
end
|
49
|
+
# End of logic in the next iteration
|
50
|
+
|
51
|
+
# Start of logic in the current iteration
|
52
|
+
variable_start_found = l.match(/^variable /)
|
53
|
+
if variable_start_found
|
54
|
+
variable_start_index = i
|
55
|
+
variable_end_index = variable_end_index(lines, variable_start_index)
|
56
|
+
lookahead_lines = lines[variable_start_index..variable_end_index]
|
57
|
+
rewrite_lines = complex_type_lines?(lookahead_lines)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Disable rewriting before reaching the end of the variable definition so: i + 1
|
61
|
+
if variable_end_index == i + 1
|
62
|
+
variable_start_index = nil
|
63
|
+
variable_end_index = nil
|
64
|
+
rewrite_lines = false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
results.join("\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
def simple_default_assignment?(line)
|
72
|
+
line.match(/default\s*=\s*("|'|null)/)
|
73
|
+
end
|
74
|
+
|
75
|
+
def complex_type_lines?(lines)
|
76
|
+
!!lines.find do |l|
|
77
|
+
complex_type_line?(l)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def complex_type_line?(l)
|
82
|
+
l.match(/object\(/) || l.match(/=\s*"any/)
|
83
|
+
end
|
84
|
+
|
85
|
+
def variable_end_index(lines, variable_start_index)
|
86
|
+
lines.each_with_index do |l,i|
|
87
|
+
next unless i >= variable_start_index
|
88
|
+
return i if l.match(/^}/) || l.match(/{\s*}/)
|
89
|
+
end
|
20
90
|
end
|
21
91
|
|
22
92
|
def empty?
|
data/lib/hcl_parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hcl_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rhcl
|
@@ -47,8 +47,8 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
|
+
- CHANGELOG.md
|
50
51
|
- Gemfile
|
51
|
-
- Gemfile.lock
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.3.21
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: HCL Variables Parser
|
data/Gemfile.lock
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
hcl_parser (0.1.0)
|
5
|
-
rhcl
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
deep_merge (1.2.1)
|
11
|
-
diff-lcs (1.3)
|
12
|
-
rake (12.3.3)
|
13
|
-
rhcl (0.1.0)
|
14
|
-
deep_merge
|
15
|
-
rspec (3.9.0)
|
16
|
-
rspec-core (~> 3.9.0)
|
17
|
-
rspec-expectations (~> 3.9.0)
|
18
|
-
rspec-mocks (~> 3.9.0)
|
19
|
-
rspec-core (3.9.2)
|
20
|
-
rspec-support (~> 3.9.3)
|
21
|
-
rspec-expectations (3.9.2)
|
22
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.9.0)
|
24
|
-
rspec-mocks (3.9.1)
|
25
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.9.0)
|
27
|
-
rspec-support (3.9.3)
|
28
|
-
|
29
|
-
PLATFORMS
|
30
|
-
ruby
|
31
|
-
|
32
|
-
DEPENDENCIES
|
33
|
-
hcl_parser!
|
34
|
-
rake (~> 12.0)
|
35
|
-
rspec (~> 3.0)
|
36
|
-
|
37
|
-
BUNDLED WITH
|
38
|
-
2.1.4
|