diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/go/go%2Ftoken%2Findex.html | |
new repository
Diffstat (limited to 'devdocs/go/go%2Ftoken%2Findex.html')
| -rw-r--r-- | devdocs/go/go%2Ftoken%2Findex.html | 339 |
1 files changed, 339 insertions, 0 deletions
diff --git a/devdocs/go/go%2Ftoken%2Findex.html b/devdocs/go/go%2Ftoken%2Findex.html new file mode 100644 index 00000000..0140e91b --- /dev/null +++ b/devdocs/go/go%2Ftoken%2Findex.html @@ -0,0 +1,339 @@ +<h1> Package token </h1> <ul id="short-nav"> +<li><code>import "go/token"</code></li> +<li><a href="#pkg-overview" class="overviewLink">Overview</a></li> +<li><a href="#pkg-index" class="indexLink">Index</a></li> +<li><a href="#pkg-examples" class="examplesLink">Examples</a></li> +</ul> <h2 id="pkg-overview">Overview </h2> <p>Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates). </p> <h4 id="example__retrievePositionInfo"> <span class="text">Example (RetrievePositionInfo)</span> +</h4> <p>Code:</p> <pre class="code" data-language="go">fset := token.NewFileSet() + +const src = `package main + +import "fmt" + +import "go/token" + + +type p = token.Pos + +const bad = token.NoPos + + +func ok(pos p) bool { + return pos != bad +} + +/*line :7:9*/func main() { + fmt.Println(ok(bad) == bad.IsValid()) +} +` + +f, err := parser.ParseFile(fset, "main.go", src, 0) +if err != nil { + fmt.Println(err) + return +} + +// Print the location and kind of each declaration in f. +for _, decl := range f.Decls { + // Get the filename, line, and column back via the file set. + // We get both the relative and absolute position. + // The relative position is relative to the last line directive. + // The absolute position is the exact position in the source. + pos := decl.Pos() + relPosition := fset.Position(pos) + absPosition := fset.PositionFor(pos, false) + + // Either a FuncDecl or GenDecl, since we exit on error. + kind := "func" + if gen, ok := decl.(*ast.GenDecl); ok { + kind = gen.Tok.String() + } + + // If the relative and absolute positions differ, show both. + fmtPosition := relPosition.String() + if relPosition != absPosition { + fmtPosition += "[" + absPosition.String() + "]" + } + + fmt.Printf("%s: %s\n", fmtPosition, kind) +} + +</pre> <p>Output:</p> <pre class="output" data-language="go"> +main.go:3:1: import +main.go:5:1: import +main.go:1:5[main.go:8:1]: type +main.go:3:1[main.go:10:1]: const +fake.go:42:11[main.go:13:1]: func +fake.go:7:9[main.go:17:14]: func +</pre> <h2 id="pkg-index">Index </h2> <ul id="manual-nav"> +<li><a href="#pkg-constants">Constants</a></li> +<li><a href="#IsExported">func IsExported(name string) bool</a></li> +<li><a href="#IsIdentifier">func IsIdentifier(name string) bool</a></li> +<li><a href="#IsKeyword">func IsKeyword(name string) bool</a></li> +<li><a href="#File">type File</a></li> +<li> <a href="#File.AddLine">func (f *File) AddLine(offset int)</a> +</li> +<li> <a href="#File.AddLineColumnInfo">func (f *File) AddLineColumnInfo(offset int, filename string, line, column int)</a> +</li> +<li> <a href="#File.AddLineInfo">func (f *File) AddLineInfo(offset int, filename string, line int)</a> +</li> +<li> <a href="#File.Base">func (f *File) Base() int</a> +</li> +<li> <a href="#File.Line">func (f *File) Line(p Pos) int</a> +</li> +<li> <a href="#File.LineCount">func (f *File) LineCount() int</a> +</li> +<li> <a href="#File.LineStart">func (f *File) LineStart(line int) Pos</a> +</li> +<li> <a href="#File.Lines">func (f *File) Lines() []int</a> +</li> +<li> <a href="#File.MergeLine">func (f *File) MergeLine(line int)</a> +</li> +<li> <a href="#File.Name">func (f *File) Name() string</a> +</li> +<li> <a href="#File.Offset">func (f *File) Offset(p Pos) int</a> +</li> +<li> <a href="#File.Pos">func (f *File) Pos(offset int) Pos</a> +</li> +<li> <a href="#File.Position">func (f *File) Position(p Pos) (pos Position)</a> +</li> +<li> <a href="#File.PositionFor">func (f *File) PositionFor(p Pos, adjusted bool) (pos Position)</a> +</li> +<li> <a href="#File.SetLines">func (f *File) SetLines(lines []int) bool</a> +</li> +<li> <a href="#File.SetLinesForContent">func (f *File) SetLinesForContent(content []byte)</a> +</li> +<li> <a href="#File.Size">func (f *File) Size() int</a> +</li> +<li><a href="#FileSet">type FileSet</a></li> +<li> <a href="#NewFileSet">func NewFileSet() *FileSet</a> +</li> +<li> <a href="#FileSet.AddFile">func (s *FileSet) AddFile(filename string, base, size int) *File</a> +</li> +<li> <a href="#FileSet.Base">func (s *FileSet) Base() int</a> +</li> +<li> <a href="#FileSet.File">func (s *FileSet) File(p Pos) (f *File)</a> +</li> +<li> <a href="#FileSet.Iterate">func (s *FileSet) Iterate(f func(*File) bool)</a> +</li> +<li> <a href="#FileSet.Position">func (s *FileSet) Position(p Pos) (pos Position)</a> +</li> +<li> <a href="#FileSet.PositionFor">func (s *FileSet) PositionFor(p Pos, adjusted bool) (pos Position)</a> +</li> +<li> <a href="#FileSet.Read">func (s *FileSet) Read(decode func(any) error) error</a> +</li> +<li> <a href="#FileSet.RemoveFile">func (s *FileSet) RemoveFile(file *File)</a> +</li> +<li> <a href="#FileSet.Write">func (s *FileSet) Write(encode func(any) error) error</a> +</li> +<li><a href="#Pos">type Pos</a></li> +<li> <a href="#Pos.IsValid">func (p Pos) IsValid() bool</a> +</li> +<li><a href="#Position">type Position</a></li> +<li> <a href="#Position.IsValid">func (pos *Position) IsValid() bool</a> +</li> +<li> <a href="#Position.String">func (pos Position) String() string</a> +</li> +<li><a href="#Token">type Token</a></li> +<li> <a href="#Lookup">func Lookup(ident string) Token</a> +</li> +<li> <a href="#Token.IsKeyword">func (tok Token) IsKeyword() bool</a> +</li> +<li> <a href="#Token.IsLiteral">func (tok Token) IsLiteral() bool</a> +</li> +<li> <a href="#Token.IsOperator">func (tok Token) IsOperator() bool</a> +</li> +<li> <a href="#Token.Precedence">func (op Token) Precedence() int</a> +</li> +<li> <a href="#Token.String">func (tok Token) String() string</a> +</li> +</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example__retrievePositionInfo">Package (RetrievePositionInfo)</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>position.go</span> <span>serialize.go</span> <span>token.go</span> </p> <h2 id="pkg-constants">Constants</h2> <p>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. </p> +<pre data-language="go">const ( + LowestPrec = 0 // non-operators + UnaryPrec = 6 + HighestPrec = 7 +)</pre> <h2 id="IsExported">func <span>IsExported</span> <span title="Added in Go 1.13">1.13</span> </h2> <pre data-language="go">func IsExported(name string) bool</pre> <p>IsExported reports whether name starts with an upper-case letter. </p> +<h2 id="IsIdentifier">func <span>IsIdentifier</span> <span title="Added in Go 1.13">1.13</span> </h2> <pre data-language="go">func IsIdentifier(name string) bool</pre> <p>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. </p> +<h2 id="IsKeyword">func <span>IsKeyword</span> <span title="Added in Go 1.13">1.13</span> </h2> <pre data-language="go">func IsKeyword(name string) bool</pre> <p>IsKeyword reports whether name is a Go keyword, such as "func" or "return". </p> +<h2 id="File">type <span>File</span> </h2> <p>A File is a handle for a file belonging to a <a href="#FileSet">FileSet</a>. A File has a name, size, and line offset table. </p> +<pre data-language="go">type File struct { + // contains filtered or unexported fields +} +</pre> <h3 id="File.AddLine">func (*File) <span>AddLine</span> </h3> <pre data-language="go">func (f *File) AddLine(offset int)</pre> <p>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. </p> +<h3 id="File.AddLineColumnInfo">func (*File) <span>AddLineColumnInfo</span> <span title="Added in Go 1.11">1.11</span> </h3> <pre data-language="go">func (f *File) AddLineColumnInfo(offset int, filename string, line, column int)</pre> <p>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. </p> +<p>AddLineColumnInfo is typically used to register alternative position information for line directives such as //line filename:line:column. </p> +<h3 id="File.AddLineInfo">func (*File) <span>AddLineInfo</span> </h3> <pre data-language="go">func (f *File) AddLineInfo(offset int, filename string, line int)</pre> <p>AddLineInfo is like <a href="#File.AddLineColumnInfo">File.AddLineColumnInfo</a> with a column = 1 argument. It is here for backward-compatibility for code prior to Go 1.11. </p> +<h3 id="File.Base">func (*File) <span>Base</span> </h3> <pre data-language="go">func (f *File) Base() int</pre> <p>Base returns the base offset of file f as registered with AddFile. </p> +<h3 id="File.Line">func (*File) <span>Line</span> </h3> <pre data-language="go">func (f *File) Line(p Pos) int</pre> <p>Line returns the line number for the given file position p; p must be a <a href="#Pos">Pos</a> value in that file or <a href="#NoPos">NoPos</a>. </p> +<h3 id="File.LineCount">func (*File) <span>LineCount</span> </h3> <pre data-language="go">func (f *File) LineCount() int</pre> <p>LineCount returns the number of lines in file f. </p> +<h3 id="File.LineStart">func (*File) <span>LineStart</span> <span title="Added in Go 1.12">1.12</span> </h3> <pre data-language="go">func (f *File) LineStart(line int) Pos</pre> <p>LineStart returns the <a href="#Pos">Pos</a> value of the start of the specified line. It ignores any alternative positions set using <a href="#File.AddLineColumnInfo">File.AddLineColumnInfo</a>. LineStart panics if the 1-based line number is invalid. </p> +<h3 id="File.Lines">func (*File) <span>Lines</span> <span title="Added in Go 1.21">1.21</span> </h3> <pre data-language="go">func (f *File) Lines() []int</pre> <p>Lines returns the effective line offset table of the form described by <a href="#File.SetLines">File.SetLines</a>. Callers must not mutate the result. </p> +<h3 id="File.MergeLine">func (*File) <span>MergeLine</span> <span title="Added in Go 1.2">1.2</span> </h3> <pre data-language="go">func (f *File) MergeLine(line int)</pre> <p>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. </p> +<h3 id="File.Name">func (*File) <span>Name</span> </h3> <pre data-language="go">func (f *File) Name() string</pre> <p>Name returns the file name of file f as registered with AddFile. </p> +<h3 id="File.Offset">func (*File) <span>Offset</span> </h3> <pre data-language="go">func (f *File) Offset(p Pos) int</pre> <p>Offset returns the offset for the given file position p; p must be a valid <a href="#Pos">Pos</a> value in that file. f.Offset(f.Pos(offset)) == offset. </p> +<h3 id="File.Pos">func (*File) <span>Pos</span> </h3> <pre data-language="go">func (f *File) Pos(offset int) Pos</pre> <p>Pos returns the Pos value for the given file offset; the offset must be <= f.Size(). f.Pos(f.Offset(p)) == p. </p> +<h3 id="File.Position">func (*File) <span>Position</span> </h3> <pre data-language="go">func (f *File) Position(p Pos) (pos Position)</pre> <p>Position returns the Position value for the given file position p. Calling f.Position(p) is equivalent to calling f.PositionFor(p, true). </p> +<h3 id="File.PositionFor">func (*File) <span>PositionFor</span> <span title="Added in Go 1.4">1.4</span> </h3> <pre data-language="go">func (f *File) PositionFor(p Pos, adjusted bool) (pos Position)</pre> <p>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. </p> +<h3 id="File.SetLines">func (*File) <span>SetLines</span> </h3> <pre data-language="go">func (f *File) SetLines(lines []int) bool</pre> <p>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. </p> +<h3 id="File.SetLinesForContent">func (*File) <span>SetLinesForContent</span> </h3> <pre data-language="go">func (f *File) SetLinesForContent(content []byte)</pre> <p>SetLinesForContent sets the line offsets for the given file content. It ignores position-altering //line comments. </p> +<h3 id="File.Size">func (*File) <span>Size</span> </h3> <pre data-language="go">func (f *File) Size() int</pre> <p>Size returns the size of file f as registered with AddFile. </p> +<h2 id="FileSet">type <span>FileSet</span> </h2> <p>A FileSet represents a set of source files. Methods of file sets are synchronized; multiple goroutines may invoke them concurrently. </p> +<p>The byte offsets for each file in a file set are mapped into distinct (integer) intervals, one interval [base, base+size] per file. <a href="#FileSet.Base">FileSet.Base</a> represents the first byte in the file, and size is the corresponding file size. A <a href="#Pos">Pos</a> value is a value in such an interval. By determining the interval a <a href="#Pos">Pos</a> value belongs to, the file, its file base, and thus the byte offset (position) the <a href="#Pos">Pos</a> value is representing can be computed. </p> +<p>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, <a href="#FileSet.Base">FileSet.Base</a> 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 <a href="#FileSet.Base">FileSet.Base</a> should be used as argument for <a href="#FileSet.AddFile">FileSet.AddFile</a>. </p> +<p>A <a href="#File">File</a> may be removed from a FileSet when it is no longer needed. This may reduce memory usage in a long-running application. </p> +<pre data-language="go">type FileSet struct { + // contains filtered or unexported fields +} +</pre> <h3 id="NewFileSet">func <span>NewFileSet</span> </h3> <pre data-language="go">func NewFileSet() *FileSet</pre> <p>NewFileSet creates a new file set. </p> +<h3 id="FileSet.AddFile">func (*FileSet) <span>AddFile</span> </h3> <pre data-language="go">func (s *FileSet) AddFile(filename string, base, size int) *File</pre> <p>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 <a href="#FileSet.Base">FileSet.Base</a>, and size must not be negative. As a special case, if a negative base is provided, the current value of the <a href="#FileSet.Base">FileSet.Base</a> is used instead. </p> +<p>Adding the file will set the file set's <a href="#FileSet.Base">FileSet.Base</a> value to base + size + 1 as the minimum base value for the next file. The following relationship exists between a <a href="#Pos">Pos</a> value p for a given file offset offs: </p> +<pre data-language="go">int(p) = base + offs +</pre> <p>with offs in the range [0, size] and thus p in the range [base, base+size]. For convenience, <a href="#File.Pos">File.Pos</a> may be used to create file-specific position values from a file offset. </p> +<h3 id="FileSet.Base">func (*FileSet) <span>Base</span> </h3> <pre data-language="go">func (s *FileSet) Base() int</pre> <p>Base returns the minimum base offset that must be provided to <a href="#FileSet.AddFile">FileSet.AddFile</a> when adding the next file. </p> +<h3 id="FileSet.File">func (*FileSet) <span>File</span> </h3> <pre data-language="go">func (s *FileSet) File(p Pos) (f *File)</pre> <p>File returns the file that contains the position p. If no such file is found (for instance for p == <a href="#NoPos">NoPos</a>), the result is nil. </p> +<h3 id="FileSet.Iterate">func (*FileSet) <span>Iterate</span> </h3> <pre data-language="go">func (s *FileSet) Iterate(f func(*File) bool)</pre> <p>Iterate calls f for the files in the file set in the order they were added until f returns false. </p> +<h3 id="FileSet.Position">func (*FileSet) <span>Position</span> </h3> <pre data-language="go">func (s *FileSet) Position(p Pos) (pos Position)</pre> <p>Position converts a <a href="#Pos">Pos</a> p in the fileset into a Position value. Calling s.Position(p) is equivalent to calling s.PositionFor(p, true). </p> +<h3 id="FileSet.PositionFor">func (*FileSet) <span>PositionFor</span> <span title="Added in Go 1.4">1.4</span> </h3> <pre data-language="go">func (s *FileSet) PositionFor(p Pos, adjusted bool) (pos Position)</pre> <p>PositionFor converts a <a href="#Pos">Pos</a> p in the fileset into a <a href="#Position">Position</a> value. If adjusted is set, the position may be adjusted by position-altering //line comments; otherwise those comments are ignored. p must be a <a href="#Pos">Pos</a> value in s or <a href="#NoPos">NoPos</a>. </p> +<h3 id="FileSet.Read">func (*FileSet) <span>Read</span> </h3> <pre data-language="go">func (s *FileSet) Read(decode func(any) error) error</pre> <p>Read calls decode to deserialize a file set into s; s must not be nil. </p> +<h3 id="FileSet.RemoveFile">func (*FileSet) <span>RemoveFile</span> <span title="Added in Go 1.20">1.20</span> </h3> <pre data-language="go">func (s *FileSet) RemoveFile(file *File)</pre> <p>RemoveFile removes a file from the <a href="#FileSet">FileSet</a> so that subsequent queries for its <a href="#Pos">Pos</a> interval yield a negative result. This reduces the memory usage of a long-lived <a href="#FileSet">FileSet</a> that encounters an unbounded stream of files. </p> +<p>Removing a file that does not belong to the set has no effect. </p> +<h3 id="FileSet.Write">func (*FileSet) <span>Write</span> </h3> <pre data-language="go">func (s *FileSet) Write(encode func(any) error) error</pre> <p>Write calls encode to serialize the file set s. </p> +<h2 id="Pos">type <span>Pos</span> </h2> <p>Pos is a compact encoding of a source position within a file set. It can be converted into a <a href="#Position">Position</a> for a more convenient, but much larger, representation. </p> +<p>The Pos value for a given file is a number in the range [base, base+size], where base and size are specified when a file is added to the file set. The difference between a Pos value and the corresponding file base corresponds to the byte offset of that position (represented by the Pos value) from the beginning of the file. Thus, the file base offset is the Pos value representing the first byte in the file. </p> +<p>To create the Pos value for a specific source offset (measured in bytes), first add the respective file to the current file set using <a href="#FileSet.AddFile">FileSet.AddFile</a> and then call <a href="#File.Pos">File.Pos</a>(offset) for that file. Given a Pos value p for a specific file set fset, the corresponding <a href="#Position">Position</a> value is obtained by calling fset.Position(p). </p> +<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. </p> +<pre data-language="go">type Pos int</pre> <p>The zero value for <a href="#Pos">Pos</a> is NoPos; there is no file and line information associated with it, and NoPos.IsValid() is false. NoPos is always smaller than any other <a href="#Pos">Pos</a> value. The corresponding <a href="#Position">Position</a> value for NoPos is the zero value for <a href="#Position">Position</a>. </p> +<pre data-language="go">const NoPos Pos = 0</pre> <h3 id="Pos.IsValid">func (Pos) <span>IsValid</span> </h3> <pre data-language="go">func (p Pos) IsValid() bool</pre> <p>IsValid reports whether the position is valid. </p> +<h2 id="Position">type <span>Position</span> </h2> <p>Position describes an arbitrary source position including the file, line, and column location. A Position is valid if the line number is > 0. </p> +<pre data-language="go">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 (byte count) +} +</pre> <h3 id="Position.IsValid">func (*Position) <span>IsValid</span> </h3> <pre data-language="go">func (pos *Position) IsValid() bool</pre> <p>IsValid reports whether the position is valid. </p> +<h3 id="Position.String">func (Position) <span>String</span> </h3> <pre data-language="go">func (pos Position) String() string</pre> <p>String returns a string in one of several forms: </p> +<pre data-language="go">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 +</pre> <h2 id="Token">type <span>Token</span> </h2> <p>Token is the set of lexical tokens of the Go programming language. </p> +<pre data-language="go">type Token int</pre> <p>The list of tokens. </p> +<pre data-language="go">const ( + // Special tokens + ILLEGAL Token = iota + EOF + COMMENT + + // Identifiers and basic type literals + // (these tokens stand for classes of literals) + IDENT // main + INT // 12345 + FLOAT // 123.45 + IMAG // 123.45i + CHAR // 'a' + STRING // "abc" + + // Operators and delimiters + ADD // + + SUB // - + MUL // * + QUO // / + REM // % + + AND // & + OR // | + XOR // ^ + SHL // << + SHR // >> + AND_NOT // &^ + + ADD_ASSIGN // += + SUB_ASSIGN // -= + MUL_ASSIGN // *= + QUO_ASSIGN // /= + REM_ASSIGN // %= + + AND_ASSIGN // &= + OR_ASSIGN // |= + XOR_ASSIGN // ^= + SHL_ASSIGN // <<= + SHR_ASSIGN // >>= + AND_NOT_ASSIGN // &^= + + LAND // && + LOR // || + ARROW // <- + INC // ++ + DEC // -- + + EQL // == + LSS // < + GTR // > + ASSIGN // = + NOT // ! + + NEQ // != + LEQ // <= + GEQ // >= + DEFINE // := + ELLIPSIS // ... + + LPAREN // ( + LBRACK // [ + LBRACE // { + COMMA // , + PERIOD // . + + RPAREN // ) + RBRACK // ] + RBRACE // } + SEMICOLON // ; + COLON // : + + // Keywords + BREAK + CASE + CHAN + CONST + CONTINUE + + DEFAULT + DEFER + ELSE + FALLTHROUGH + FOR + + FUNC + GO + GOTO + IF + IMPORT + + INTERFACE + MAP + PACKAGE + RANGE + RETURN + + SELECT + STRUCT + SWITCH + TYPE + VAR + + // additional tokens, handled in an ad-hoc manner + TILDE +)</pre> <h3 id="Lookup">func <span>Lookup</span> </h3> <pre data-language="go">func Lookup(ident string) Token</pre> <p>Lookup maps an identifier to its keyword token or <a href="#IDENT">IDENT</a> (if not a keyword). </p> +<h3 id="Token.IsKeyword">func (Token) <span>IsKeyword</span> </h3> <pre data-language="go">func (tok Token) IsKeyword() bool</pre> <p>IsKeyword returns true for tokens corresponding to keywords; it returns false otherwise. </p> +<h3 id="Token.IsLiteral">func (Token) <span>IsLiteral</span> </h3> <pre data-language="go">func (tok Token) IsLiteral() bool</pre> <p>IsLiteral returns true for tokens corresponding to identifiers and basic type literals; it returns false otherwise. </p> +<h3 id="Token.IsOperator">func (Token) <span>IsOperator</span> </h3> <pre data-language="go">func (tok Token) IsOperator() bool</pre> <p>IsOperator returns true for tokens corresponding to operators and delimiters; it returns false otherwise. </p> +<h3 id="Token.Precedence">func (Token) <span>Precedence</span> </h3> <pre data-language="go">func (op Token) Precedence() int</pre> <p>Precedence returns the operator precedence of the binary operator op. If op is not a binary operator, the result is LowestPrecedence. </p> +<h3 id="Token.String">func (Token) <span>String</span> </h3> <pre data-language="go">func (tok Token) String() string</pre> <p>String returns the string corresponding to the token tok. For operators, delimiters, and keywords the string is the actual token character sequence (e.g., for the token <a href="#ADD">ADD</a>, the string is "+"). For all other tokens the string corresponds to the token constant name (e.g. for the token <a href="#IDENT">IDENT</a>, the string is "IDENT"). </p><div class="_attribution"> + <p class="_attribution-p"> + © Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br> + <a href="http://golang.org/pkg/go/token/" class="_attribution-link">http://golang.org/pkg/go/token/</a> + </p> +</div> |
