token

package
v0.0.0-...-4cc5765 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LowestPrec  = 0 // non-operators
	UnaryPrec   = 6
	HighestPrec = 7
)

Variables

This section is empty.

Functions

func IsExported

func IsExported(name string) bool

Types

type Error

type Error struct {
	Pos Position
	Msg string
}

func (*Error) Error

func (e *Error) Error() string

type ErrorList

type ErrorList []*Error

type File

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

functionally equivalent to go/token.File

func NewFile

func NewFile(name string, base int) *File

func (*File) AddLine

func (f *File) AddLine(offset int)

func (*File) Base

func (f *File) Base() int

func (*File) End

func (f *File) End() int

return Base() + Size()

func (*File) Line

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

return the line number for the given position p

func (*File) Name

func (f *File) Name() string

func (*File) Offset

func (*File) Offset(p Pos) int

func (*File) Pos

func (f *File) Pos(offset int) Pos

func (*File) Position

func (f *File) Position(p Pos) Position

return the Position for the given Pos p

func (*File) PositionFor

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

func (*File) SetSize

func (f *File) SetSize(size int)

func (*File) SetSkipLines

func (f *File) SetSkipLines(skipLines int)

func (*File) Size

func (f *File) Size() int

return size, or a lower bound if unknown

type FileSet

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

functionally equivalent to go/token.FileSet

func NewFileSet

func NewFileSet(pkgPath string) *FileSet

func (*FileSet) AddFile

func (f *FileSet) AddFile(name string) *File

func (*FileSet) PkgPath

func (f *FileSet) PkgPath() string

func (*FileSet) Position

func (f *FileSet) Position(p Pos) Position

return the Position for the given Pos p

func (*FileSet) Size

func (f *FileSet) Size() int

type Kind

type Kind uint8

equivalent to go/token.Kind

const (
	Invalid Kind = iota

	Bool
	Int
	Int8
	Int16
	Int32
	Int64
	Uint
	Uint8
	Uint16
	Uint32
	Uint64
	Uintptr
	Float32
	Float64
	Complex64
	Complex128
	ArrayKind
	ChanKind
	FuncKind
	InterfaceKind
	MapKind
	PtrKind
	SliceKind
	String
	StructKind
	UnsafePointer

	// types for untyped values
	UntypedBool
	UntypedInt
	UntypedRune
	UntypedFloat
	UntypedComplex
	UntypedString
	UntypedNil

	// aliases
	Byte = Uint8
	Rune = Int32
)

func (Kind) Category

func (k Kind) Category() Kind

group together typed and untyped: 1. booleans 2. integers 3. floats 4. complex numbers 5. strings

func (Kind) IsBasic

func (k Kind) IsBasic() bool

func (Kind) IsComplex

func (k Kind) IsComplex() bool

func (Kind) IsFloat

func (k Kind) IsFloat() bool

func (Kind) IsInteger

func (k Kind) IsInteger() bool

func (Kind) IsNillable

func (k Kind) IsNillable() bool

func (Kind) IsOrdered

func (k Kind) IsOrdered() bool

func (Kind) IsUntyped

func (k Kind) IsUntyped() bool

func (Kind) Size

func (k Kind) Size() uint64

return size of specified kind, in bytes. 0 means unknown/variable. returned size depends on config.TargetArch()

func (Kind) String

func (k Kind) String() string

type Pos

type Pos int

equivalent to go/token.Pos

const NoPos Pos = 0

equivalent go/token.NoPos

func (Pos) IsValid

func (p Pos) IsValid() bool

type Position

type Position struct {
	Filename string
	Offset   int
	Line     int
	Column   int
}

equivalent to go/token.Position

func (*Position) IsValid

func (pos *Position) IsValid() bool

func (*Position) String

func (pos *Position) String() string

type Token

type Token int

equivalent to go/token.Token

const (
	ILLEGAL Token = iota
	EOF
	COMMENT

	IDENT
	INT
	FLOAT
	IMAG
	CHAR
	STRING

	// Operators
	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

	// array or slice type. if first child is nil => slice type.
	// otherwise first child is array length (possibly '...')
	ARRAY
	BLOCK
	BOTH_DIR
	CALL
	COMPOSITE_LIT // type { elem0, elem1 ... }
	DECLS         // list of declarations
	DIR           // list of files
	EXPRS
	// struct field, interface element, function param or result.
	// stored in *ast.Field
	FIELD
	FILE
	GENERIC     // generic type parameters [T0 i0, T1 i1, ...]
	IMPORT_SPEC // single import line 'alias "full/pkg/path"'
	IMPORTS     // list of IMPORT nodes
	INDEX       // array/map/slice indexing a[b] or generic instantiation a[b,c...]
	KEY_VALUE   // key: value inside a composite literal
	LABEL       // label: statement
	LAMBDA      // function literal
	NAMES       // list of identifiers
	PARAMS
	RECV_DIR
	RESULTS
	SEND_DIR
	SLICE // slice expression a[b:c] or a[b:c:d]
	TYPE_ASSERT
	TYPES      // list of types. used by generics in 'interface { type /* typelist */ }'
	TYPESWITCH // switch x.(type) { }
	VALUE_SPEC
)

func Lookup

func Lookup(str string) Token

func LookupOperator

func LookupOperator(str string) Token

func (Token) IsKeyword

func (tok Token) IsKeyword() bool

func (Token) IsLiteral

func (tok Token) IsLiteral() bool

func (Token) IsOperator

func (tok Token) IsOperator() bool

func (Token) Precedence

func (tok Token) Precedence() int

func (Token) String

func (tok Token) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL