token

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrecedenceLowest  = 0
	PrecedenceUnary   = 9
	PrecedenceHighest = 10
)

Variables

This section is empty.

Functions

func IsIdentifier

func IsIdentifier(name string) bool

func IsKeyword

func IsKeyword(tok string) bool

func IsPostfixOperator

func IsPostfixOperator(tok Token) bool

Types

type File

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

func (*File) AddLine

func (f *File) AddLine(offset int)

func (*File) Base

func (f *File) Base() int

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

func (*File) GetPosition

func (f *File) GetPosition(line, column int) (pos Position)

GetPosition returns the Position value for the specified file, line, and column.

func (*File) Line

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

func (f *File) LineCount() int

func (*File) LineStart

func (f *File) LineStart(line int) Pos

func (*File) Lines

func (f *File) Lines() []int

Lines returns the line offsets for the given file.

func (*File) Mutex

func (s *File) Mutex() *sync.Mutex

func (*File) Offset

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

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

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

func (f *File) Scheme() string

Scheme returns the scheme of file f as registered with AddFile.

func (*File) SetLinesForContent

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

func (f *File) Size() int

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

func (*File) Specifier

func (f *File) Specifier() string

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

type FileSet

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

func NewFileSet

func NewFileSet() *FileSet

func (*FileSet) AddFile

func (s *FileSet) AddFile(specifier string, base, size int) *File

func (*FileSet) Base

func (s *FileSet) Base() int

func (*FileSet) File

func (s *FileSet) File(filename string) *File

func (*FileSet) GetPosition

func (s *FileSet) GetPosition(specifier string, line, column int) Position

func (*FileSet) Mutex

func (s *FileSet) Mutex() *sync.Mutex

func (*FileSet) Pos

func (s *FileSet) Pos(position Position) Pos

func (*FileSet) Position

func (s *FileSet) Position(pos Pos) Position

type Lockable

type Lockable interface {
	Mutex() *sync.Mutex
}

type Pos

type Pos int
const NoPos Pos = 0

func (Pos) IsValid

func (p Pos) IsValid() bool

type Position

type Position struct {
	Filename string
	Offset   int // offset, starting at 0
	Line     int
	Column   int
}

func (*Position) IsValid

func (pos *Position) IsValid() bool

func (Position) String

func (pos Position) String() string

type Token

type Token int
const (
	Illegal Token = iota
	EOF
	Comment

	LiteralStart
	Ident
	Int   // int64
	Float // float64
	StringStart
	StringMid
	StringInterpIdent
	StringInterpExprStart
	StringInterpExprEnd
	StringEnd
	Null
	True
	False
	LiteralEnd

	OperatorStart
	Assign
	OverloadAllowedStart
	Add
	Sub
	Mul
	Quo
	Rem
	Pow
	Gt
	Lt
	Lte
	Gte
	Inc
	Dec
	Question
	BitShl
	BitShr
	BitNot
	BitAnd
	BitOr
	BitXor
	Eq
	Neq
	Spaceship
	OverloadAllowedEnd
	AddAssign
	SubAssign
	MulAssign
	QuoAssign
	RemAssign
	PowAssign
	LogAnd
	LogOr
	LogNot
	LogNull
	LogAndAssign
	LogOrAssign
	LogNullAssign
	BitAndAssign
	BitOrAssign
	BitXorAssign
	BitShlAssign
	BitShrAssign
	LParen
	RParen
	LBracket
	RBracket
	LBrace
	RBrace
	Colon
	Semi
	Comma
	Period
	Arrow
	Ellipsis
	HashLBracket
	Bind
	MatchBind
	EOL
	OperatorEnd

	KeywordStart
	Let
	Const
	Symbol
	If
	Then
	Else
	Repeat
	While
	Forever
	Times
	For
	In
	Break
	Continue
	Func
	End
	Return
	Memo
	Import
	Export
	As
	Show
	Generator
	Yield
	To
	Step
	Struct
	Init
	Operator
	Try
	Catch
	Finally
	Throw
	Do
	Async
	Await
	Native
	Match
	When
	Frozen
	Is
	KeywordEnd

	None
)

func Lookup

func Lookup(ident 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