hcl/lex.go

39 lines
494 B
Go
Raw Normal View History

2014-07-31 20:56:51 +00:00
package hcl
import (
"unicode"
"unicode/utf8"
2014-07-31 20:56:51 +00:00
)
2014-08-01 19:54:53 +00:00
type lexModeValue byte
2014-07-31 20:56:51 +00:00
2014-08-01 19:54:53 +00:00
const (
lexModeUnknown lexModeValue = iota
lexModeHcl
lexModeJson
)
2014-07-31 20:56:51 +00:00
2014-08-01 19:54:53 +00:00
// lexMode returns whether we're going to be parsing in JSON
// mode or HCL mode.
func lexMode(v []byte) lexModeValue {
var (
r rune
w int
offset int
)
for {
r, w = utf8.DecodeRune(v[offset:])
offset += w
2014-08-01 19:54:53 +00:00
if unicode.IsSpace(r) {
2014-07-31 20:56:51 +00:00
continue
}
2014-08-01 19:54:53 +00:00
if r == '{' {
return lexModeJson
2014-07-31 20:56:51 +00:00
}
break
2014-07-31 20:56:51 +00:00
}
2014-09-15 16:40:47 +00:00
return lexModeHcl
2014-07-31 20:56:51 +00:00
}