Documentation ¶
Overview ¶
Package ftoken is a faster subset of the stdlib go/token package.
Index ¶
- type File
- func (f *File) AddLine(offset int)
- func (f *File) AddLineInfo(offset int, filename string, line int)
- func (f *File) Base() int
- func (f *File) Line(p token.Pos) int
- func (f *File) LineCount() int
- func (f *File) Lines() []int
- func (f *File) MergeLine(line int)
- func (f *File) Name() string
- func (f *File) Offset(p token.Pos) int
- func (f *File) Pos(offset int) token.Pos
- func (f *File) Position(p token.Pos) (pos token.Position)
- func (f *File) PositionFor(p token.Pos, adjusted bool) (pos token.Position)
- func (f *File) SetLines(lines []int) bool
- func (f *File) SetLinesForContent(content []byte)
- func (f *File) Size() int
- type FileSet
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) AddLine ¶
AddLine adds the line offset for a new line. The line offset must be larger than the offset for the previous line and smaller than the file size; otherwise the line offset is ignored.
func (*File) AddLineInfo ¶
AddLineInfo adds alternative file and line number information for a given file offset. The offset must be larger than the offset for the previously added alternative line info and smaller than the file size; otherwise the information is ignored.
AddLineInfo is typically used to register alternative position information for //line filename:line comments in source files.
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) MergeLine ¶
MergeLine merges a line with the following line. It is akin to replacing the newline character at the end of the line with a space (to not change the remaining offsets). To obtain the line number, consult e.g. Position.Line. MergeLine will panic if given an invalid line number.
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. Calling f.Position(p) is equivalent to calling f.PositionFor(p, true).
func (*File) PositionFor ¶
PositionFor returns the Position value for the given file position p. If adjusted is set, the position may be adjusted by position-altering //line comments; otherwise those comments are ignored. p must be a Pos value in f or NoPos.
func (*File) SetLines ¶
SetLines sets the line offsets for a file and reports whether it succeeded. The line offsets are the offsets of the first character of each line; for instance for the content "ab\nc\n" the line offsets are {0, 3}. An empty file has an empty line offset table. Each line offset must be larger than the offset for the previous line and smaller than the file size; otherwise SetLines fails and returns false. Callers must not mutate the provided slice after SetLines returns.
func (*File) SetLinesForContent ¶
SetLinesForContent sets the line offsets for the given file content. It ignores position-altering //line comments.
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.