cade852d47
For example, the (Go quoted) input "\"\\00" creates the following stack trace: ``` panic: bytes.Buffer: UnreadRune: previous operation was not a successful ReadRune goroutine 1 [running]: github.com/hashicorp/hcl/hcl/scanner.(*Scanner).unread(0xc420090270) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:112 +0x245 github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanDigits(0xc420090270, 0x0, 0x8, 0x3, 0x5c2005b740) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:557 +0x1ba github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanEscape(0xc420090270, 0xc40000005c) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:520 +0x181 github.com/hashicorp/hcl/hcl/scanner.(*Scanner).scanString(0xc420090270) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:504 +0x2c3 github.com/hashicorp/hcl/hcl/scanner.(*Scanner).Scan(0xc420090270, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) gopath/src/github.com/hashicorp/hcl/hcl/scanner/scanner.go:172 +0x509 github.com/hashicorp/hcl/hcl/parser.(*Parser).scan(0xc42005bd18, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:448 +0xf4 github.com/hashicorp/hcl/hcl/parser.(*Parser).objectKey(0xc42005bd18, 0x530aa8, 0xc42005bd18, 0xc42005bd18, 0x18, 0x50f980) gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:224 +0xca github.com/hashicorp/hcl/hcl/parser.(*Parser).objectItem(0xc42005bd18, 0x0, 0x0, 0x0) gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:150 +0xbf github.com/hashicorp/hcl/hcl/parser.(*Parser).objectList(0xc42005bd18, 0xc42000e000, 0x0, 0x0, 0x0) gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:88 +0x139 github.com/hashicorp/hcl/hcl/parser.(*Parser).Parse(0xc42005bd18, 0xc420090270, 0x200000, 0xc42005bce0) gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:59 +0xf3 github.com/hashicorp/hcl/hcl/parser.Parse(0x7fca1fdd9000, 0x4, 0x200000, 0x8, 0x0, 0x0) gopath/src/github.com/hashicorp/hcl/hcl/parser/parser.go:46 +0x294 github.com/hashicorp/hcl/hcl/printer.Format(0x7fca1fdd9000, 0x4, 0x200000, 0x0, 0xc42005bef0, 0x464307, 0x4, 0xc42005bed0) gopath/src/github.com/hashicorp/hcl/hcl/printer/printer.go:53 +0x5b ``` |
||
---|---|---|
.github | ||
hcl | ||
json | ||
test-fixtures | ||
testhelper | ||
.gitignore | ||
.travis.yml | ||
appveyor.yml | ||
decoder_test.go | ||
decoder.go | ||
hcl_test.go | ||
hcl.go | ||
lex_test.go | ||
lex.go | ||
LICENSE | ||
Makefile | ||
parse.go | ||
README.md |
HCL
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.
HCL is also fully JSON compatible. That is, JSON can be used as completely valid input to a system expecting HCL. This helps makes 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 withEOF
on its own line (here documents). Any text may be used in place ofEOF
. 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: