hcl2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0df7e8338b4dd244c4c83cd4e5c9a0600df1f7908c9de811763b3a38f9a58dae
4
+ data.tar.gz: 4c8b5fe3465611f87ab47ad598255149b025427d85a30de99fe8576792ecd136
5
+ SHA512:
6
+ metadata.gz: dd9fe4b85ec40fd015a9319f009f2441c5a61d59ee229d14efcf5d55364929de1752d40c30734eaacbc06208c6ec8390880000ecc42f9d0b8b8f8ce73d5ca667
7
+ data.tar.gz: 397a4abd58a662638c096d229069ead3450e68b3cd901d38260bf0328fb0c86728ef1dfb64427724f5b9ee65d58219f0dd3c3c23ad3fe08b389e81cb77e86546
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ Version 0.1.0
2
+
3
+ # Changelog
4
+
5
+ All notable changes to this project will be documented in this file.
6
+
7
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
+
10
+ ## [Unreleased]
11
+
12
+ ## [0.1.0] - 2021-06-05
13
+
14
+ - Initial release
15
+ - Add support for parsing `.terraform.lock.hcl` files.
16
+
17
+ [Unreleased]: https://github.com/xlgmokha/hcl2/compare/v0.1.0...HEAD
18
+ [0.1.0]: https://github.com/xlgmokha/hcl2/compare/ab9eeb30e53ad95d9d1d3a8e538cb9d9a8a478b8...v0.1.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 mo khan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # HCL2
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'hcl2'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hcl2
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `./bin/setup` to install dependencies.
22
+ Then, run `./bin/test` to run the tests.
23
+
24
+ ## License
25
+
26
+ The gem is available as open source under the terms of the [MIT License][mit].
27
+
28
+ [mit]: https://opensource.org/licenses/MIT
data/exe/hcl2 ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "hcl2"
data/hcl2.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hcl2/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hcl2"
7
+ spec.version = Hcl2::VERSION
8
+ spec.authors = ["mo khan"]
9
+ spec.email = ["mo@mokhan.ca"]
10
+
11
+ spec.summary = "A HCL v2 parser."
12
+ spec.description = "A HCL v2 parser."
13
+ spec.homepage = "https://github.com/xlgmokha/hcl2"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/xlgmokha/hcl2"
19
+ spec.metadata["changelog_uri"] = "https://github.com/xlgmokha/hcl2/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ Dir.glob("exe/*") +
23
+ Dir.glob("lib/**/**/*.{rb}") +
24
+ Dir.glob("*.{md,gemspec,txt}")
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.add_dependency "parslet", "~> 2.0"
30
+ end
data/lib/hcl2.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ require_relative "hcl2/parser"
5
+ require_relative "hcl2/version"
6
+
7
+ module Hcl2
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hcl2
4
+ class Parser < ::Parslet::Parser
5
+ rule(:alpha) { match["a-zA-Z"] }
6
+ rule(:assign) { str("=") }
7
+ rule(:colon) { str(":") }
8
+ rule(:comma) { str(",") }
9
+ rule(:comment) { (str("#") | str("//")) >> ((str("\n") >> str("\r").maybe).absent? >> any).repeat >> eol }
10
+ rule(:crlf) { match('[\r\n]') }
11
+ rule(:digit) { match('\d') }
12
+ rule(:dot) { str(".") }
13
+ rule(:eol) { whitespace? >> crlf.repeat }
14
+ rule(:greater_than_or_equal_to) { str(">=") }
15
+ rule(:hyphen) { str("-") }
16
+ rule(:lbracket) { str("[") }
17
+ rule(:lcurly) { str("{") }
18
+ rule(:major) { number }
19
+ rule(:major_minor) { (number >> dot >> number) }
20
+ rule(:major_minor_patch) { number >> dot >> number >> dot >> number }
21
+ rule(:multiline_comment) { str("/*") >> (str("*/").absent? >> any).repeat >> str("*/") }
22
+ rule(:number) { digit.repeat }
23
+ rule(:plus) { str("+") }
24
+ rule(:pre_release) { hyphen >> (alpha | digit).repeat }
25
+ rule(:pre_release?) { pre_release.maybe }
26
+ rule(:quote) { str('"') }
27
+ rule(:rbracket) { str("]") }
28
+ rule(:rcurly) { str("}") }
29
+ rule(:slash) { str("/") }
30
+ rule(:space) { match('\s') }
31
+ rule(:tilda_wacka) { str("~>") }
32
+ rule(:version) { number >> dot >> number >> dot >> number >> pre_release? }
33
+ rule(:whitespace) { (multiline_comment | comment | space).repeat }
34
+ rule(:whitespace?) { whitespace.maybe }
35
+
36
+ rule(:pessimistic_version_constraint) do
37
+ tilda_wacka >> whitespace >> (
38
+ major_minor_patch |
39
+ major_minor |
40
+ major
41
+ )
42
+ end
43
+
44
+ rule(:greater_than_or_equal_to_version) do
45
+ greater_than_or_equal_to >> whitespace >> (
46
+ major_minor_patch |
47
+ major_minor |
48
+ major
49
+ )
50
+ end
51
+
52
+ rule(:version_constraint) do
53
+ pessimistic_version_constraint | greater_than_or_equal_to_version
54
+ end
55
+
56
+ rule :version_assignment do
57
+ str("version") >> whitespace >> assign >> whitespace >> quote >> version.as(:version) >> quote
58
+ end
59
+
60
+ rule :constraint_assignment do
61
+ str("constraints") >> whitespace >> assign >> whitespace >> quote >> version_constraint.as(:constraints) >> quote
62
+ end
63
+
64
+ rule :string do
65
+ quote >> (
66
+ digit | dot | alpha | str("~> ") | slash | colon | assign | plus
67
+ ).repeat(1).as(:value) >> quote
68
+ end
69
+
70
+ rule :array_item do
71
+ whitespace? >> string >> comma.maybe >> eol
72
+ end
73
+
74
+ rule :empty_array do
75
+ lbracket >> eol >> eol >> rbracket
76
+ end
77
+
78
+ rule :array do
79
+ lbracket >> eol >> array_item.repeat >> whitespace >> rbracket
80
+ end
81
+
82
+ rule :argument_value do
83
+ (empty_array | array.as(:values) | string) >> eol
84
+ end
85
+
86
+ rule :argument do
87
+ whitespace >> alpha.repeat(1).as(:name) >> whitespace >> assign >> whitespace >> argument_value
88
+ end
89
+
90
+ rule :block_body do
91
+ lcurly >> crlf >> argument.repeat.as(:arguments) >> rcurly
92
+ end
93
+
94
+ rule :identifier do
95
+ whitespace >> quote >> (alpha | dot | slash).repeat(1).as(:name) >> quote >> whitespace
96
+ end
97
+
98
+ rule :block do
99
+ alpha.repeat(1).as(:type) >> identifier >> block_body
100
+ end
101
+
102
+ rule :blocks do
103
+ whitespace? >> (block >> eol.maybe).repeat(1).as(:blocks)
104
+ end
105
+
106
+ root(:blocks)
107
+ end
108
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hcl2
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hcl2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mo khan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: A HCL v2 parser.
28
+ email:
29
+ - mo@mokhan.ca
30
+ executables:
31
+ - hcl2
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - exe/hcl2
39
+ - hcl2.gemspec
40
+ - lib/hcl2.rb
41
+ - lib/hcl2/parser.rb
42
+ - lib/hcl2/version.rb
43
+ homepage: https://github.com/xlgmokha/hcl2
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/xlgmokha/hcl2
48
+ source_code_uri: https://github.com/xlgmokha/hcl2
49
+ changelog_uri: https://github.com/xlgmokha/hcl2/blob/main/CHANGELOG.md
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.6.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.2.19
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: A HCL v2 parser.
69
+ test_files: []