open-nomad/vendor/github.com/hashicorp/hcl
Seth Hoenig 435c0d9fc8 deps: Switch to Go modules for dependency management
This PR switches the Nomad repository from using govendor to Go modules
for managing dependencies. Aspects of the Nomad workflow remain pretty
much the same. The usual Makefile targets should continue to work as
they always did. The API submodule simply defers to the parent Nomad
version on the repository, keeping the semantics of API versioning that
currently exists.
2020-06-02 14:30:36 -05:00
..
hcl deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
json Update github.com/hashicorp/hcl 2020-02-28 15:40:01 -05:00
v2 deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
.gitignore deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
.travis.yml deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
LICENSE Using godeps to build 2016-02-12 10:02:16 -08:00
Makefile Update hcl to fix json parsing panic 2016-11-01 16:16:22 -07:00
README.md deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
appveyor.yml update vendor/github.com/hashicorp/hcl 2019-04-23 11:56:07 -04:00
decoder.go config parse update hcl with support for decoding bool to string 2019-06-10 13:12:38 -04:00
go.mod update vendor/github.com/hashicorp/hcl 2019-04-23 11:56:07 -04:00
go.sum update vendor/github.com/hashicorp/hcl 2019-04-23 11:56:07 -04:00
hcl.go Using godeps to build 2016-02-12 10:02:16 -08:00
lex.go vendor hcl 2016-06-13 18:15:41 -07:00
parse.go vendor hcl 2016-06-13 18:15:41 -07:00

README.md

HCL

GoDoc Build Status

HCL (HashiCorp Configuration Language) is a configuration language built by HashiCorp. The goal of HCL is to build a structured configuration language that is both human and machine friendly for use with command-line tools, but specifically targeted towards DevOps tools, servers, etc.

NOTE: This is major version 1 of HCL, which is now in maintenence mode only. We strongly recommend that new projects use HCL 2 instead. For more information, see our version selection guide.

HCL is also fully JSON compatible. That is, JSON can be used as a completely valid input to a system expecting HCL. This helps to make systems interoperable with other systems.

HCL is heavily inspired by libucl, nginx configuration, and others similar.

Why?

A common question when viewing HCL is to ask the question: why not JSON, YAML, etc.?

Prior to HCL, the tools we built at HashiCorp used a variety of configuration languages from full programming languages such as Ruby to complete data structure languages such as JSON. What we learned is that some people wanted human-friendly configuration languages and some people wanted machine-friendly languages.

JSON fits a nice balance in this, but is fairly verbose and most importantly doesn't support comments. With YAML, we found that beginners had a really hard time determining what the actual structure was, and ended up guessing more often than not whether to use a hyphen, colon, etc. in order to represent some configuration key.

Full programming languages such as Ruby enable complex behavior a configuration language shouldn't usually allow, and also forces people to learn some set of Ruby.

Because of this, we decided to create our own configuration language that is JSON-compatible. Our configuration language (HCL) is designed to be written and modified by humans. The API for HCL allows JSON as an input so that it is also machine-friendly (machines can generate JSON instead of trying to generate HCL).

Our goal with HCL is not to alienate other configuration languages. It is instead to provide HCL as a specialized language for our tools, and JSON as the interoperability layer.

Syntax

For a complete grammar, please see the parser itself. A high-level overview of the syntax and grammar is listed here.

  • Single line comments start with # or //

  • Multi-line comments are wrapped in /* and */. Nested block comments are not allowed. A multi-line comment (also known as a block comment) terminates at the first */ found.

  • Values are assigned with the syntax key = value (whitespace doesn't matter). The value can be any primitive: a string, number, boolean, object, or list.

  • Strings are double-quoted and can contain any UTF-8 characters. Example: "Hello, World"

  • Multi-line strings start with <<EOF at the end of a line, and end with EOF on its own line (here documents). Any text may be used in place of EOF. Example:

<<FOO
hello
world
FOO
  • Numbers are assumed to be base 10. If you prefix a number with 0x, it is treated as a hexadecimal. If it is prefixed with 0, it is treated as an octal. Numbers can be in scientific notation: "1e10".

  • Boolean values: true, false

  • Arrays can be made by wrapping it in []. Example: ["foo", "bar", 42]. Arrays can contain primitives, other arrays, and objects. As an alternative, lists of objects can be created with repeated blocks, using this structure:

    service {
        key = "value"
    }
    
    service {
        key = "value"
    }
    

Objects and nested objects are created using the structure shown below:

variable "ami" {
    description = "the AMI to use"
}

This would be equivalent to the following json:

{
  "variable": {
      "ami": {
          "description": "the AMI to use"
        }
    }
}

Thanks

Thanks to:

  • @vstakhov - The original libucl parser and syntax that HCL was based off of.

  • @fatih - The rewritten HCL parser in pure Go (no goyacc) and support for a printer.