2
0

token.go 763 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package parser
  2. import "fmt"
  3. // tokenType is the type of the token value returned by the lexer.
  4. type tokenType int
  5. const (
  6. Eof tokenType = iota
  7. Comment
  8. OpenBracket
  9. CloseBracket
  10. OpenSquareBracket
  11. CloseSquareBracket
  12. Comma
  13. Equal
  14. String
  15. Literal
  16. Value
  17. Timestamp
  18. )
  19. var tokenTypes = []string{
  20. Eof: "EOF",
  21. Comment: "Comment",
  22. OpenBracket: "OpenBracket",
  23. CloseBracket: "CloseBracket",
  24. Comma: "Comma",
  25. Equal: "Equal",
  26. String: "String",
  27. Literal: "Literal",
  28. Value: "Value",
  29. Timestamp: "Timestamp",
  30. }
  31. func (tt tokenType) String() string {
  32. return tokenTypes[tt]
  33. }
  34. type token struct {
  35. Type tokenType
  36. Value string
  37. }
  38. func (t token) String() string {
  39. return fmt.Sprintf("%s:%s", t.Type, t.Value)
  40. }