You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lex.go 494B

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