Support multiline string literals in HCL
This allows multiline strings to be parsed in order to make HIL interpolations nicer in Terraform: ``` my_complex_thing = "${merge(var.list1, var.list2, var.list3)}" ```
This commit is contained in:
parent
364df43084
commit
a55c206bd0
@ -79,6 +79,12 @@ func TestDecode_interface(t *testing.T) {
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"multiline_literal.hcl",
|
||||
false,
|
||||
map[string]interface{}{"multiline_literal": testhelper.Unix2dos(`hello
|
||||
world`)},
|
||||
},
|
||||
{
|
||||
"multiline_no_marker.hcl",
|
||||
true,
|
||||
|
@ -469,7 +469,7 @@ func (s *Scanner) scanString() {
|
||||
// read character after quote
|
||||
ch := s.next()
|
||||
|
||||
if ch == '\n' || ch < 0 || ch == eof {
|
||||
if ch < 0 || ch == eof {
|
||||
s.err("literal not terminated")
|
||||
return
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/hashicorp/hcl/hcl/token"
|
||||
)
|
||||
|
||||
var f100 = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
var f100 = strings.Repeat("f", 100)
|
||||
|
||||
type tokenPair struct {
|
||||
tok token.Type
|
||||
@ -494,7 +494,7 @@ func TestError(t *testing.T) {
|
||||
|
||||
testError(t, `"`, "1:2", "literal not terminated", token.STRING)
|
||||
testError(t, `"abc`, "1:5", "literal not terminated", token.STRING)
|
||||
testError(t, `"abc`+"\n", "1:5", "literal not terminated", token.STRING)
|
||||
testError(t, `"abc`+"\n", "2:1", "literal not terminated", token.STRING)
|
||||
testError(t, `/*/`, "1:4", "comment not terminated", token.COMMENT)
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,6 @@ func Unquote(s string) (t string, err error) {
|
||||
if quote != '"' {
|
||||
return "", ErrSyntax
|
||||
}
|
||||
if contains(s, '\n') {
|
||||
return "", ErrSyntax
|
||||
}
|
||||
|
||||
// Is it trivial? Avoid allocation.
|
||||
if !contains(s, '\\') && !contains(s, quote) && !contains(s, '$') {
|
||||
|
@ -65,8 +65,6 @@ var misquoted = []string{
|
||||
"`\"",
|
||||
`"\'"`,
|
||||
`'\"'`,
|
||||
"\"\n\"",
|
||||
"\"\\n\n\"",
|
||||
"'\n'",
|
||||
`"${"`,
|
||||
`"${foo{}"`,
|
||||
|
2
test-fixtures/multiline_literal.hcl
Normal file
2
test-fixtures/multiline_literal.hcl
Normal file
@ -0,0 +1,2 @@
|
||||
multiline_literal = "hello
|
||||
world"
|
Loading…
Reference in New Issue
Block a user