Documentation ¶
Overview ¶
Package token defines the lexical elements of a River config and utilities surrounding their position.
Index ¶
Constants ¶
const ( LowestPrecedence = 0 // non-operators UnaryPrecedence = 7 HighestPrecedence = 8 )
Levels of precedence for operator tokens.
Variables ¶
var NoPos = Pos{}
NoPos is the zero value for Pos. It has no file or line information associated with it, and NoPos.Valid is false.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File holds position information for a specific file.
func (*File) AddLine ¶
AddLine tracks a new line from a byte offset. The line offset must be larger than the offset for the previous line, otherwise the line offset is ignored.
func (*File) PositionFor ¶
PositionFor returns a Position from an offset.
type Pos ¶
type Pos struct {
// contains filtered or unexported fields
}
Pos is a compact representation of a position within a file. It can be converted into a Position for a more convenient, but larger, representation.
type Position ¶
type Position struct { Filename string // Filename (if any) Offset int // Byte offset (starting at 0) Line int // Line number (starting at 1) Column int // Offset from start of line (starting at 1) }
Position holds full position information for a location within an individual file.
func (Position) String ¶
String returns a string in one of the following forms:
file:line:column Valid position with file name file:line Valid position with file name but no column line:column Valid position with no file name line Valid position with no file name or column file Invalid position with file name - Invalid position with no file name
type Token ¶
type Token int
Token is an individual River lexical token.
const ( ILLEGAL Token = iota // Invalid token. LITERAL // Literal text. EOF // End-of-file. COMMENT // // Hello, world! IDENT // foobar NUMBER // 1234 FLOAT // 1234.0 STRING // "foobar" BOOL // true NULL // null OR // || AND // && NOT // ! ASSIGN // = EQ // == NEQ // != LT // < LTE // <= GT // > GTE // >= ADD // + SUB // - MUL // * DIV // / MOD // % POW // ^ LCURLY // { RCURLY // } LPAREN // ( RPAREN // ) LBRACK // [ RBRACK // ] COMMA // , DOT // . TERMINATOR // \n )
List of all lexical tokens and examples that represent them.
LITERAL is used by token/builder to represent literal strings for writing tokens, but never used for reading (so scanner never returns a token.LITERAL).
func (Token) BinaryPrecedence ¶
BinaryPrecedence returns the operator precedence of the binary operator t. If t is not a binary operator, the result is LowestPrecedence.
func (Token) IsLiteral ¶
IsLiteral returns true if the token corresponds to a literal token or identifier.
func (Token) IsOperator ¶
IsOperator returns true if the token corresponds to an operator or delimiter.