This repository has been archived on 2024-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
arf/file/location.go

54 lines
1.4 KiB
Go
Raw Normal View History

package file
2022-08-17 23:31:01 -06:00
import "fmt"
// Location represents a specific point in a file. It is used for error
// reporting.
type Location struct {
file *File
row int
column int
width int
}
2022-08-17 22:42:47 -06:00
// File returns the file the location is in
func (location Location) File () (file *File) {
return location.file
}
// Row returns the row the location is positioned at in the file, starting at
// zero.
func (location Location) Row () (row int) {
return location.row
}
// Column returns the column the location is positioned at in the file, starting
// at zero.
func (location Location) Column () (column int) {
return location.column
}
// Width returns the amount of runes spanned by the location, starting at row
// and column.
func (location Location) Width () (width int) {
return location.width
}
2022-08-17 23:31:01 -06:00
2022-08-18 00:04:49 -06:00
// SetWidth sets the location's width
func (location *Location) SetWidth (width int) {
location.width = width
}
2022-08-17 23:31:01 -06:00
// Describe generates a description of the location for debug purposes
func (location Location) Describe () (description string) {
return fmt.Sprint (
"in ", location.file.Path(),
2022-10-13 14:11:12 -06:00
" row ", location.row + 1,
" column ", location.column + 1,
2022-08-17 23:31:01 -06:00
" width ", location.width)
}
// TODO: add extend method that extends that takes in another location, and
// returns a new location that spans the two. then, use it in the parser to
// properly locate an entire tree node.