type File(struct)
A File is a handle for a file belonging to a FileSet.
A File has a name, size, and line offset table.
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.
AddLineColumnInfo adds alternative file, line, and column 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.
AddLineColumnInfo is typically used to register alternative position
information for line directives such as //line filename:line:column.
AddLineInfo is like AddLineColumnInfo with a column = 1 argument.
It is here for backward-compatibility for code prior to Go 1.11.
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.
LineStart returns the Pos value of the start of the specified line.
It ignores any alternative positions set using AddLineColumnInfo.
LineStart panics if the 1-based line number is invalid.
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.
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.
Calling f.Position(p) is equivalent to calling f.PositionFor(p, true).
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.
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.
SetLinesForContent sets the line offsets for the given file content.
It ignores position-altering //line comments.
Size returns the size of file f as registered with AddFile.
func (*FileSet).AddFile(filename string, base, size int) *File
func (*FileSet).File(p Pos) (f *File)
func go/scanner.(*Scanner).Init(file *File, src []byte, err scanner.ErrorHandler, mode scanner.Mode)
type FileSet(struct)
A FileSet represents a set of source files.
Methods of file sets are synchronized; multiple goroutines
may invoke them concurrently.
The byte offsets for each file in a file set are mapped into
distinct (integer) intervals, one interval [base, base+size]
per file. Base represents the first byte in the file, and size
is the corresponding file size. A Pos value is a value in such
an interval. By determining the interval a Pos value belongs
to, the file, its file base, and thus the byte offset (position)
the Pos value is representing can be computed.
When adding a new file, a file base must be provided. That can
be any integer value that is past the end of any interval of any
file already in the file set. For convenience, FileSet.Base provides
such a value, which is simply the end of the Pos interval of the most
recently added file, plus one. Unless there is a need to extend an
interval later, using the FileSet.Base should be used as argument
for 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.
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 p in the fileset into a Position value.
Calling s.Position(p) is equivalent to calling s.PositionFor(p, true).
PositionFor converts a Pos p in the fileset into a Position value.
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 s or NoPos.
Read calls decode to deserialize a file set into s; s must not be nil.
Write calls encode to serialize the file set s.
func NewFileSet() *FileSet
func go/ast.Fprint(w io.Writer, fset *FileSet, x interface{}, f ast.FieldFilter) error
func go/ast.NewCommentMap(fset *FileSet, node ast.Node, comments []*ast.CommentGroup) ast.CommentMap
func go/ast.NewPackage(fset *FileSet, files map[string]*ast.File, importer ast.Importer, universe *ast.Scope) (*ast.Package, error)
func go/ast.Print(fset *FileSet, x interface{}) error
func go/ast.SortImports(fset *FileSet, f *ast.File)
func go/doc.NewFromFiles(fset *FileSet, files []*ast.File, importPath string, opts ...interface{}) (*doc.Package, error)
func go/format.Node(dst io.Writer, fset *FileSet, node interface{}) error
func go/importer.ForCompiler(fset *FileSet, compiler string, lookup importer.Lookup) types.Importer
func go/internal/gcimporter.Import(fset *FileSet, packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error)
func go/internal/srcimporter.New(ctxt *build.Context, fset *FileSet, packages map[string]*types.Package) *srcimporter.Importer
func go/parser.ParseDir(fset *FileSet, path string, filter func(os.FileInfo) bool, mode parser.Mode) (pkgs map[string]*ast.Package, first error)
func go/parser.ParseExprFrom(fset *FileSet, filename string, src interface{}, mode parser.Mode) (expr ast.Expr, err error)
func go/parser.ParseFile(fset *FileSet, filename string, src interface{}, mode parser.Mode) (f *ast.File, err error)
func go/printer.Fprint(output io.Writer, fset *FileSet, node interface{}) error
func go/printer.(*Config).Fprint(output io.Writer, fset *FileSet, node interface{}) error
func go/types.CheckExpr(fset *FileSet, pkg *types.Package, pos Pos, expr ast.Expr, info *types.Info) (err error)
func go/types.Eval(fset *FileSet, pkg *types.Package, pos Pos, expr string) (_ types.TypeAndValue, err error)
func go/types.NewChecker(conf *types.Config, fset *FileSet, pkg *types.Package, info *types.Info) *types.Checker
func go/types.(*Config).Check(path string, fset *FileSet, files []*ast.File, info *types.Info) (*types.Package, error)
type Position(struct)
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 (character count per line)
// filename, if any
// line number, starting at 1
// byte offset, starting at 0
IsValid reports whether the position is valid.
String returns a string in one of several forms:
file:line:column valid position with file name
file:line valid position with file name but no column (column == 0)
line:column valid position without file name
line valid position without file name and no column (column == 0)
file invalid position with file name
- invalid position without file name
*T : database/sql/driver.Validator
T : expvar.Var
T : fmt.Stringer
func (*File).Position(p Pos) (pos Position)
func (*File).PositionFor(p Pos, adjusted bool) (pos Position)
func (*FileSet).Position(p Pos) (pos Position)
func (*FileSet).PositionFor(p Pos, adjusted bool) (pos Position)
func go/scanner.(*ErrorList).Add(pos Position, msg string)
const HighestPrec = 7
A set of constants for precedence-based expression parsing.
Non-operators have lowest precedence, followed by operators
starting with precedence 1 up to unary operators. The highest
precedence serves as "catch-all" precedence for selector,
indexing, and other operator and delimiter tokens.
const IDENTToken = 4 // main
Identifiers and basic type literals
(these tokens stand for classes of literals)
func IsExported(name string) bool
IsExported reports whether name starts with an upper-case letter.
func IsIdentifier(name string) bool
IsIdentifier reports whether name is a Go identifier, that is, a non-empty
string made up of letters, digits, and underscores, where the first character
is not a digit. Keywords are not identifiers.
func IsKeyword(name string) bool
IsKeyword reports whether name is a Go keyword, such as "func" or "return".
const LowestPrec = 0 // non-operators
A set of constants for precedence-based expression parsing.
Non-operators have lowest precedence, followed by operators
starting with precedence 1 up to unary operators. The highest
precedence serves as "catch-all" precedence for selector,
indexing, and other operator and delimiter tokens.
const NoPosPos = 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.
const UnaryPrec = 6
A set of constants for precedence-based expression parsing.
Non-operators have lowest precedence, followed by operators
starting with precedence 1 up to unary operators. The highest
precedence serves as "catch-all" precedence for selector,
indexing, and other operator and delimiter tokens.
The pages are generated with Goldsv0.1.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project and 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.