本站源代码
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.

50 lines
847B

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1