position.go 474 B

123456789101112131415161718192021
  1. package token
  2. import "fmt"
  3. // IllegalPosition is a position that is not valid.
  4. var IllegalPosition = Position{}
  5. // Position represents a rune position in the source code.
  6. type Position struct {
  7. Filename string
  8. Line int
  9. Column int
  10. }
  11. // String returns a string representation of the position.
  12. func (p Position) String() string {
  13. if len(p.Filename) == 0 {
  14. return fmt.Sprint(p.Line, ":", p.Column)
  15. }
  16. return fmt.Sprint(p.Filename, " ", p.Line, ":", p.Column)
  17. }