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.

token.go 847B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ssh_config
  2. import "fmt"
  3. type token struct {
  4. Position
  5. typ tokenType
  6. val string
  7. }
  8. func (t token) String() string {
  9. switch t.typ {
  10. case tokenEOF:
  11. return "EOF"
  12. }
  13. return fmt.Sprintf("%q", t.val)
  14. }
  15. type tokenType int
  16. const (
  17. eof = -(iota + 1)
  18. )
  19. const (
  20. tokenError tokenType = iota
  21. tokenEOF
  22. tokenEmptyLine
  23. tokenComment
  24. tokenKey
  25. tokenEquals
  26. tokenString
  27. )
  28. func isSpace(r rune) bool {
  29. return r == ' ' || r == '\t'
  30. }
  31. func isKeyStartChar(r rune) bool {
  32. return !(isSpace(r) || r == '\r' || r == '\n' || r == eof)
  33. }
  34. // I'm not sure that this is correct
  35. func isKeyChar(r rune) bool {
  36. // Keys start with the first character that isn't whitespace or [ and end
  37. // with the last non-whitespace character before the equals sign. Keys
  38. // cannot contain a # character."
  39. return !(r == '\r' || r == '\n' || r == eof || r == '=')
  40. }