go: cuelang.org/go/cue/token Index | Files

package token

import "cuelang.org/go/cue/token"

Package token defines constants representing the lexical tokens of the Go programming language and basic operations on tokens (printing, predicates).

Index

Package Files

position.go token.go

Constants

const (
    LowestPrec  = lowestPrec
    UnaryPrec   = unaryPrec
    HighestPrec = highestPrec
)

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.

Variables

var NoPos = Pos{}

NoPos is the zero value for Pos; 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 File Uses

type File struct {
    // contains filtered or unexported fields
}

A File has a name, size, and line offset table.

func NewFile Uses

func NewFile(filename string, base, size int) *File

NewFile returns a new file.

func (*File) AddLine Uses

func (f *File) AddLine(offset int)

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 Uses

func (f *File) AddLineInfo(offset int, filename string, line int)

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) Base Uses

func (f *File) Base() int

Base returns the base offset of file f as registered with AddFile.

func (*File) Line Uses

func (f *File) Line(p Pos) int

Line returns the line number for the given file position p; p must be a Pos value in that file or NoPos.

func (*File) LineCount Uses

func (f *File) LineCount() int

LineCount returns the number of lines in file f.

func (*File) MergeLine Uses

func (f *File) MergeLine(line int)

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) Name Uses

func (f *File) Name() string

Name returns the file name of file f as registered with AddFile.

func (*File) Offset Uses

func (f *File) Offset(p Pos) int

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 Uses

func (f *File) Pos(offset int, rel RelPos) 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 Uses

func (f *File) Position(p Pos) (pos 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 Uses

func (f *File) PositionFor(p Pos, adjusted bool) (pos Position)

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 Uses

func (f *File) SetLines(lines []int) bool

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 Uses

func (f *File) SetLinesForContent(content []byte)

SetLinesForContent sets the line offsets for the given file content. It ignores position-altering //line comments.

func (*File) Size Uses

func (f *File) Size() int

Size returns the size of file f as registered with AddFile.

type Pos Uses

type Pos struct {
    // contains filtered or unexported fields
}

Pos is a compact encoding of a source position within a file, as well as relative positioning information. It can be converted into a Position for a more convenient, but much larger, representation.

func (Pos) Add Uses

func (p Pos) Add(n int) Pos

Add creates a new position relative to the p offset by n.

func (Pos) Before Uses

func (p Pos) Before(q Pos) bool

func (Pos) Column Uses

func (p Pos) Column() int

func (Pos) File Uses

func (p Pos) File() *File

File returns the file that contains the position p or nil if there is no such file (for instance for p == NoPos).

func (Pos) Filename Uses

func (p Pos) Filename() string

func (Pos) HasRelPos Uses

func (p Pos) HasRelPos() bool

HasRelPos repors whether p has a relative position.

func (Pos) IsNewline Uses

func (p Pos) IsNewline() bool

IsNewline reports whether the relative information suggests this node should be printed on a new lien.

func (Pos) IsValid Uses

func (p Pos) IsValid() bool

IsValid reports whether the position is valid.

func (Pos) Line Uses

func (p Pos) Line() int

func (Pos) Offset Uses

func (p Pos) Offset() int

Offset reports the byte offset relative to the file.

func (Pos) Position Uses

func (p Pos) Position() Position

func (Pos) RelPos Uses

func (p Pos) RelPos() RelPos

func (Pos) String Uses

func (p Pos) String() string

func (Pos) WithRel Uses

func (p Pos) WithRel(rel RelPos) Pos

type Position Uses

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)

}

Position describes an arbitrary source position including the file, line, and column location. A Position is valid if the line number is > 0.

func (*Position) IsValid Uses

func (pos *Position) IsValid() bool

IsValid reports whether the position is valid.

func (Position) String Uses

func (pos Position) String() string

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

type RelPos Uses

type RelPos int

RelPos indicates the relative position of token to the previous token.

const (
    // NoRelPos indicates no relative position is specified.
    NoRelPos RelPos = iota

    // Elided indicates that the token for which this position is defined is
    // not rendered at all.
    Elided

    // NoSpace indicates there is no whitespace after this token.
    NoSpace

    // Blank means there is horizontal space after this token.
    Blank

    // Newline means there is a single newline after this token.
    Newline

    // NewSection means there are two or more newlines after this token.
    NewSection
)

func (RelPos) Pos Uses

func (p RelPos) Pos() Pos

func (RelPos) String Uses

func (p RelPos) String() string

type Token Uses

type Token int

Token is the set of lexical tokens of the CUE configuration language.

const (
    // Special tokens
    ILLEGAL Token = iota
    EOF
    COMMENT
    ATTRIBUTE // @foo(bar,baz=4)

    // Identifiers and basic type literals
    // (these tokens stand for classes of literals)
    IDENT // main, _tmp
    INT   // 12_345Mi, 0700, 0xdeadbeef, 1.2M
    FLOAT // 123.45,
    // DURATION // 3m4s TODO
    STRING        // "abc"
    INTERPOLATION // a part of a template string, e.g. `"age: \(`
    BOTTOM        // _|_

    // Operators and delimiters
    ADD // +
    SUB // -
    MUL // *
    POW // ^
    QUO // /

    IQUO // quo
    IREM // rem
    IDIV // div
    IMOD // mod

    AND // &
    OR  // |

    LAND // &&
    LOR  // ||

    BIND  // =
    EQL   // ==
    LSS   // <
    GTR   // >
    NOT   // !
    ARROW // <-

    NEQ // !=
    LEQ // <=
    GEQ // >=

    MAT  // =~
    NMAT // !~

    LPAREN   // (
    LBRACK   // [
    LBRACE   // {
    COMMA    // ,
    PERIOD   // .
    ELLIPSIS // ...

    RPAREN    // )
    RBRACK    // ]
    RBRACE    // }
    SEMICOLON // ;
    COLON     // :
    ISA       // ::
    OPTION    // ?

    IF
    FOR
    IN
    LET

    TRUE
    FALSE
    NULL
)

The list of tokens.

func Lookup Uses

func Lookup(ident string) Token

Lookup maps an identifier to its keyword token or IDENT (if not a keyword).

func (Token) IsKeyword Uses

func (tok Token) IsKeyword() bool

IsKeyword returns true for tokens corresponding to keywords; it returns false otherwise.

func (Token) IsLiteral Uses

func (tok Token) IsLiteral() bool

IsLiteral returns true for tokens corresponding to identifiers and basic type literals; it returns false otherwise.

func (Token) IsOperator Uses

func (tok Token) IsOperator() bool

IsOperator returns true for tokens corresponding to operators and delimiters; it returns false otherwise.

func (Token) Precedence Uses

func (tok Token) Precedence() int

Precedence returns the operator precedence of the binary operator op. If op is not a binary operator, the result is LowestPrecedence.

func (Token) String Uses

func (tok Token) String() string

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 ADD, 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").

Package token imports 4 packages (graph) and is imported by 20 packages. Updated 2019-12-13. Refresh now. Tools for package owners.