Involved Source Filesposition.goserialize.go
Package token defines constants representing the lexical tokens of the gcfg
configuration syntax and basic operations on tokens (printing, predicates).
Note that the API for the token package may change to accommodate new
features or implementation changes in gcfg.
Package-Level Type Names (total 8, in which 5 are exported)
/* sort exporteds by: | */
A File is a handle for a file belonging to a FileSet.
A File has a name, size, and line offset table.
// Pos value range for this file is [base...base+size]
infos[]lineInfo
lines and infos are protected by set.mutex
// file name as provided to AddFile
set*FileSet
// file size as provided to AddFile
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.
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.
Base returns the base offset of file f as registered with AddFile.
Line returns the line number for the given file position p;
p must be a Pos value in that file or NoPos.
LineCount returns the number of lines in file f.
Name returns the file name of file f as registered with AddFile.
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.
Pos returns the Pos value for the given file offset;
the offset must be <= f.Size().
f.Pos(f.Offset(p)) == p.
Position returns the Position value for the given file position p;
p must be a Pos value in that file or NoPos.
SetLines sets the line offsets for a file and returns true if successful.
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.
SetLinesForContent sets the line offsets for the given file content.
Size returns the size of file f as registered with AddFile.
info returns the file name, line, and column number for a file offset.
(*T) position(p Pos) (pos Position)
func (*FileSet).AddFile(filename string, base, size int) *File
func (*FileSet).File(p Pos) (f *File)
func (*FileSet).file(p Pos) *File
func github.com/go-git/gcfg/scanner.(*Scanner).Init(file *File, src []byte, err scanner.ErrorHandler, mode scanner.Mode)
func searchFiles(a []*File, x int) int
func github.com/go-git/gcfg.read(c *warnings.Collector, callback func(string, string, string, string, bool) error, fset *FileSet, file *File, src []byte) error
func github.com/go-git/gcfg.readInto(config interface{}, fset *FileSet, file *File, src []byte) error
A FileSet represents a set of source files.
Methods of file sets are synchronized; multiple goroutines
may invoke them concurrently.
// base offset for the next file
// list of files in the order added to the set
// cache of last file looked up
// protects the file set
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.
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.
Base returns the minimum base offset that must be provided to
AddFile when adding the next 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.
Iterate calls f for the files in the file set in the order they were added
until f returns false.
Position converts a Pos in the fileset into a general Position.
Read calls decode to deserialize a file set into s; s must not be nil.
Write calls encode to serialize the file set s.
(*T) file(p Pos) *File
func NewFileSet() *FileSet
func github.com/go-git/gcfg.read(c *warnings.Collector, callback func(string, string, string, string, bool) error, fset *FileSet, file *File, src []byte) error
func github.com/go-git/gcfg.readInto(config interface{}, fset *FileSet, file *File, src []byte) error
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.
IsValid returns true if the position is valid.
T : database/sql/driver.Validator
func (*File).Pos(offset int) Pos
func github.com/go-git/gcfg/scanner.(*Scanner).Scan() (pos Pos, tok Token, lit string)
func (*File).Line(p Pos) int
func (*File).Offset(p Pos) int
func (*File).Position(p Pos) (pos Position)
func (*FileSet).File(p Pos) (f *File)
func (*FileSet).Position(p Pos) (pos Position)
func (*File).position(p Pos) (pos Position)
func (*FileSet).file(p Pos) *File
const NoPos
Position describes an arbitrary source position
including the file, line, and column location.
A Position is valid if the line number is > 0.
// column number, starting at 1 (byte count)
// filename, if any
// line number, starting at 1
// offset, starting at 0
IsValid returns true if the position is valid.
String returns a string in one of several forms:
file:line:column valid position with file name
line:column valid position without file name
file invalid position with file name
- invalid position without file name
*T : database/sql/driver.Validator
T : expvar.Var
T : fmt.Stringer
T : context.stringer
T : runtime.stringer
func (*File).Position(p Pos) (pos Position)
func (*FileSet).Position(p Pos) (pos Position)
func (*File).position(p Pos) (pos Position)
func github.com/go-git/gcfg/scanner.(*ErrorList).Add(pos Position, msg string)
Token is the set of lexical tokens of the gcfg configuration syntax.
IsLiteral returns true for tokens corresponding to identifiers
and basic type literals; it returns false otherwise.
IsOperator returns true for tokens corresponding to operators and
delimiters; it returns false otherwise.
String returns the string corresponding to the token tok.
For operators and delimiters, the string is the actual token character
sequence (e.g., for the token ASSIGN, the string is "="). For all other
tokens the string corresponds to the token constant name (e.g. for the
token IDENT, the string is "IDENT").
T : expvar.Var
T : fmt.Stringer
T : context.stringer
T : runtime.stringer
func github.com/go-git/gcfg/scanner.(*Scanner).Scan() (pos Pos, tok Token, lit string)
const ASSIGN
const COMMENT
const EOF
const EOL
const IDENT
const ILLEGAL
const LBRACK
const RBRACK
const STRING
const literal_beg
const literal_end
const operator_beg
const operator_end
A lineInfo object describes alternative file and line number
information (such as provided via a //line comment in a .go
file) for a given file offset.
FilenamestringLineint
fields are exported to make them accessible to gob
func searchLineInfos(a []lineInfo, x int) int
Package-Level Constants (total 14, in which 10 are exported)
Operators and delimiters
The list of tokens.
The list of tokens.
The list of tokens.
Identifiers and basic type literals
(these tokens stand for classes of literals)
Special tokens
The list of tokens.
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.
The list of tokens.
The list of tokens.
The list of tokens.
The list of tokens.
The list of tokens.
The list of tokens.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.