Documentation ¶
Index ¶
- type File
- func (f *File) Base() int
- func (f *File) ByteOffsetOfRune(runeOffset int) int
- func (f *File) Line(p Pos) int
- func (f *File) LineCount() int
- func (f *File) LineEndOffset(line int) int
- func (f *File) LineOffset(line int) int
- func (f *File) Name() string
- func (f *File) Offset(p Pos) int
- func (f *File) Pos(offset int) Pos
- func (f *File) Position(p Pos) (pos Position)
- func (f *File) SetByteOffsetsForContent(content []byte)
- func (f *File) SetLinesForContent(content []byte)
- func (f *File) Size() int
- type FileSet
- type Pos
- type Position
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
A File is a handle for a file belonging to a FileSet. A File has a name, size, and line offset table.
func (*File) ByteOffsetOfRune ¶
ByteOffsetOfRune returns the byte offset that points to the same position as runeOffset. Assumes SetByteOffsetsForContent has been called.
func (*File) Line ¶
Line returns the line number for the given file position p; p must be a Pos value in that file or NoPos.
func (*File) LineEndOffset ¶
LineEndOffset returns the offset for the newline terminating the given line, or the last character in the file plus 1 if the given line has no terminating newline; line must be a valid line in the file.
func (*File) LineOffset ¶
LineOffset returns the offset for the first character in the given line; line must be a valid line in the file.
func (*File) Offset ¶
Offset returns the offset for the given file position p; p must be a valid Pos value in that file. f.Offset(f.Pos(offset)) == offset.
func (*File) Pos ¶
Pos returns the Pos value for the given file offset; the offset must be <= f.Size(). f.Pos(f.Offset(p)) == p.
func (*File) Position ¶
Position returns the Position value for the given file position p; p must be a Pos value in that file or NoPos.
func (*File) SetByteOffsetsForContent ¶
func (*File) SetLinesForContent ¶
SetLinesForContent sets the line offsets for the given file content.
type FileSet ¶
type FileSet struct {
// contains filtered or unexported fields
}
A FileSet represents a set of source files. Methods of file sets are synchronized; multiple goroutines may invoke them concurrently.
func (*FileSet) AddFile ¶
AddFile adds a new file with a given filename, base offset, and file size to the file set s and returns the file. Multiple files may have the same name. The base offset must not be smaller than the FileSet's Base(), and size must not be negative. As a special case, if a negative base is provided, the current value of the FileSet's Base() is used instead.
Adding the file will set the file set's Base() value to base + size + 1 as the minimum base value for the next file. The following relationship exists between a Pos value p for a given file offset offs:
int(p) = base + offs
with offs in the range [0, size] and thus p in the range [base, base+size]. For convenience, File.Pos may be used to create file-specific position values from a file offset.
func (*FileSet) Base ¶
Base returns the minimum base offset that must be provided to AddFile when adding the next file.
func (*FileSet) File ¶
File returns the file that contains the position p. If no such file is found (for instance for p == NoPos), the result is nil.
type Pos ¶
type Pos int
Pos is a compact encoding of a source position within a file set. It can be converted into a Position for a more convenient, but much larger, representation.
The Pos value for a given file is a number in the range [base, base+size], where base and size are specified when adding the file to the file set via AddFile.
To create the Pos value for a specific source offset, first add the respective file to the current file set (via FileSet.AddFile) and then call File.Pos(offset) for that file. Given a Pos value p for a specific file set fset, the corresponding Position value is obtained by calling fset.Position(p).
Pos values can be compared directly with the usual comparison operators: If two Pos values p and q are in the same file, comparing p and q is equivalent to comparing the respective source file offsets. If p and q are in different files, p < q is true if the file implied by p was added to the respective file set before the file implied by q.
const NoPos Pos = 0
The zero value for Pos is NoPos; there is no file and line information associated with it, and NoPos().IsValid() is false. NoPos is always smaller than any other Pos value. The corresponding Position value for NoPos is the zero value for Position.
type Position ¶
type Position struct { Filename string // filename, if any Offset int // offset, starting at 0 Line int // line number, starting at 1 Column int // column number, starting at 1 (character count) }
Position describes an arbitrary source position including the file, line, and column location. A Position is valid if the line number is > 0.