| 1 |
package hcl |
| 2 |
|
| 3 |
import ( |
| 4 |
"unicode" |
| 5 |
"unicode/utf8" |
| 6 |
) |
| 7 |
|
| 8 |
type lexModeValue byte |
| 9 |
|
| 10 |
const ( |
| 11 |
lexModeUnknown lexModeValue = iota |
| 12 |
lexModeHcl |
| 13 |
lexModeJson |
| 14 |
) |
| 15 |
|
| 16 |
// lexMode returns whether we're going to be parsing in JSON |
| 17 |
// mode or HCL mode. |
| 18 |
func lexMode(v []byte) lexModeValue { |
| 19 |
var ( |
| 20 |
r rune |
| 21 |
w int |
| 22 |
offset int |
| 23 |
) |
| 24 |
|
| 25 |
for { |
| 26 |
r, w = utf8.DecodeRune(v[offset:]) |
| 27 |
offset += w |
| 28 |
if unicode.IsSpace(r) { |
| 29 |
continue |
| 30 |
} |
| 31 |
if r == '{' { |
| 32 |
return lexModeJson |
| 33 |
} |
| 34 |
break |
| 35 |
} |
| 36 |
|
| 37 |
return lexModeHcl |
| 38 |
} |