Skip to content
An general-purpose HCL (Hashicorp Configuration Language) parser written in Crystal.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec
src
.editorconfig
.gitignore
.travis.yml
LICENSE
Makefile
README.md
shard.yml

README.md

hcl.cr

A general-purpose HCL parser written in Crystal. Does not make any domain assumptions. Supports the standard HCL types, including blocks and lists. Does not support functions.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      hcl:
        github: maxfierke/hcl.cr
  2. Run shards install

Usage

require "hcl"

SRC_TEXT = <<-HEREDOC
# An AMI
variable "ami" {
  description = "the AMI to use"
}

/* A multi
  line comment. */
resource "aws_instance" "web" {
  ami               = "${var.ami}"
  count             = 2
  source_dest_check = false
  another_boolean = "true"
  something_i_want_default = null

  connection {
    user = "root"
  }
}
HEREDOC

parser = HCL::Parser.new(SRC_TEXT) # Parser object. Is also an Iterator of tokens.

tokens = parser.parse # Returns an Array(HCL::Token)
values = parser.value # Returns the HCL structure as Crystal data types
string = parser.string # Returns string reconstruction of HCL configuration

TODO: Write usage instructions here

Development

TODO: Write development instructions here

TODO

  • Add support for maps
  • Add support for functions
  • Add support for square-bracket attribute & index access on maps & lists
  • Add support for arithmetic and logic operators
  • Add support for conditional expressions
  • Parse interpolations
  • Add support for heredocs
  • More validations
  • Investigate directives

Contributing

  1. Fork it (https://github.com/maxfierke/hcl.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

You can’t perform that action at this time.