parser

package
v2.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpcodeNames = [...]string{
	OpConstant:      "CONST",
	OpPop:           "POP",
	OpTrue:          "TRUE",
	OpFalse:         "FALSE",
	OpBComplement:   "NEG",
	OpEqual:         "EQL",
	OpNotEqual:      "NEQ",
	OpMinus:         "NEG",
	OpLNot:          "NOT",
	OpJumpFalsy:     "JMPF",
	OpAndJump:       "ANDJMP",
	OpOrJump:        "ORJMP",
	OpJump:          "JMP",
	OpNull:          "NULL",
	OpGetGlobal:     "GETG",
	OpSetGlobal:     "SETG",
	OpSetSelGlobal:  "SETSG",
	OpArray:         "ARR",
	OpMap:           "MAP",
	OpError:         "ERROR",
	OpImmutable:     "IMMUT",
	OpIndex:         "INDEX",
	OpSliceIndex:    "SLICE",
	OpCall:          "CALL",
	OpReturn:        "RET",
	OpGetLocal:      "GETL",
	OpSetLocal:      "SETL",
	OpDefineLocal:   "DEFL",
	OpSetSelLocal:   "SETSL",
	OpGetBuiltin:    "BUILTIN",
	OpClosure:       "CLOSURE",
	OpGetFreePtr:    "GETFP",
	OpGetFree:       "GETF",
	OpSetFree:       "SETF",
	OpGetLocalPtr:   "GETLP",
	OpSetSelFree:    "SETSF",
	OpIteratorInit:  "ITER",
	OpIteratorNext:  "ITNXT",
	OpIteratorKey:   "ITKEY",
	OpIteratorValue: "ITVAL",
	OpBinaryOp:      "BINARYOP",
	OpSuspend:       "SUSPEND",
}

OpcodeNames are string representation of opcodes.

View Source
var OpcodeOperands = [...][]int{
	OpConstant:      {2},
	OpPop:           {},
	OpTrue:          {},
	OpFalse:         {},
	OpBComplement:   {},
	OpEqual:         {},
	OpNotEqual:      {},
	OpMinus:         {},
	OpLNot:          {},
	OpJumpFalsy:     {2},
	OpAndJump:       {2},
	OpOrJump:        {2},
	OpJump:          {2},
	OpNull:          {},
	OpGetGlobal:     {2},
	OpSetGlobal:     {2},
	OpSetSelGlobal:  {2, 1},
	OpArray:         {2},
	OpMap:           {2},
	OpError:         {},
	OpImmutable:     {},
	OpIndex:         {1},
	OpSliceIndex:    {},
	OpCall:          {1, 1},
	OpReturn:        {1},
	OpGetLocal:      {1},
	OpSetLocal:      {1},
	OpDefineLocal:   {1},
	OpSetSelLocal:   {1, 1},
	OpGetBuiltin:    {1},
	OpClosure:       {2, 1},
	OpGetFreePtr:    {1},
	OpGetFree:       {1},
	OpSetFree:       {1},
	OpGetLocalPtr:   {1},
	OpSetSelFree:    {1, 1},
	OpIteratorInit:  {},
	OpIteratorNext:  {},
	OpIteratorKey:   {},
	OpIteratorValue: {},
	OpBinaryOp:      {1},
	OpSuspend:       {},
}

OpcodeOperands is the number of operands.

Functions

func ReadOperands

func ReadOperands(numOperands []int, ins []byte) (operands []int, offset int)

ReadOperands reads operands from the bytecode.

func StripCR

func StripCR(b []byte, comment bool) []byte

StripCR removes carriage return characters.

Types

type ArrayLit

type ArrayLit struct {
	Elements []Expr
	LBrack   Pos
	RBrack   Pos
}

ArrayLit represents an array literal.

func (*ArrayLit) End

func (e *ArrayLit) End() Pos

End returns the position of first character immediately after the node.

func (*ArrayLit) Pos

func (e *ArrayLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ArrayLit) String

func (e *ArrayLit) String() string

type AssignStmt

type AssignStmt struct {
	LHS      []Expr
	RHS      []Expr
	Token    token.Token
	TokenPos Pos
}

AssignStmt represents an assignment statement.

func (*AssignStmt) End

func (s *AssignStmt) End() Pos

End returns the position of first character immediately after the node.

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*AssignStmt) String

func (s *AssignStmt) String() string

type BadExpr

type BadExpr struct {
	From Pos
	To   Pos
}

BadExpr represents a bad expression.

func (*BadExpr) End

func (e *BadExpr) End() Pos

End returns the position of first character immediately after the node.

func (*BadExpr) Pos

func (e *BadExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*BadExpr) String

func (e *BadExpr) String() string

type BadStmt

type BadStmt struct {
	From Pos
	To   Pos
}

BadStmt represents a bad statement.

func (*BadStmt) End

func (s *BadStmt) End() Pos

End returns the position of first character immediately after the node.

func (*BadStmt) Pos

func (s *BadStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*BadStmt) String

func (s *BadStmt) String() string

type BinaryExpr

type BinaryExpr struct {
	LHS      Expr
	RHS      Expr
	Token    token.Token
	TokenPos Pos
}

BinaryExpr represents a binary operator expression.

func (*BinaryExpr) End

func (e *BinaryExpr) End() Pos

End returns the position of first character immediately after the node.

func (*BinaryExpr) Pos

func (e *BinaryExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

type BlockStmt

type BlockStmt struct {
	Stmts  []Stmt
	LBrace Pos
	RBrace Pos
}

BlockStmt represents a block statement.

func (*BlockStmt) End

func (s *BlockStmt) End() Pos

End returns the position of first character immediately after the node.

func (*BlockStmt) Pos

func (s *BlockStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*BlockStmt) String

func (s *BlockStmt) String() string

type BoolLit

type BoolLit struct {
	Value    bool
	ValuePos Pos
	Literal  string
}

BoolLit represents a boolean literal.

func (*BoolLit) End

func (e *BoolLit) End() Pos

End returns the position of first character immediately after the node.

func (*BoolLit) Pos

func (e *BoolLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*BoolLit) String

func (e *BoolLit) String() string

type BranchStmt

type BranchStmt struct {
	Token    token.Token
	TokenPos Pos
	Label    *Ident
}

BranchStmt represents a branch statement.

func (*BranchStmt) End

func (s *BranchStmt) End() Pos

End returns the position of first character immediately after the node.

func (*BranchStmt) Pos

func (s *BranchStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*BranchStmt) String

func (s *BranchStmt) String() string

type CallExpr

type CallExpr struct {
	Func     Expr
	LParen   Pos
	Args     []Expr
	Ellipsis Pos
	RParen   Pos
}

CallExpr represents a function call expression.

func (*CallExpr) End

func (e *CallExpr) End() Pos

End returns the position of first character immediately after the node.

func (*CallExpr) Pos

func (e *CallExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*CallExpr) String

func (e *CallExpr) String() string

type CharLit

type CharLit struct {
	Value    rune
	ValuePos Pos
	Literal  string
}

CharLit represents a character literal.

func (*CharLit) End

func (e *CharLit) End() Pos

End returns the position of first character immediately after the node.

func (*CharLit) Pos

func (e *CharLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*CharLit) String

func (e *CharLit) String() string

type CondExpr

type CondExpr struct {
	Cond        Expr
	True        Expr
	False       Expr
	QuestionPos Pos
	ColonPos    Pos
}

CondExpr represents a ternary conditional expression.

func (*CondExpr) End

func (e *CondExpr) End() Pos

End returns the position of first character immediately after the node.

func (*CondExpr) Pos

func (e *CondExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*CondExpr) String

func (e *CondExpr) String() string

type EmptyStmt

type EmptyStmt struct {
	Semicolon Pos
	Implicit  bool
}

EmptyStmt represents an empty statement.

func (*EmptyStmt) End

func (s *EmptyStmt) End() Pos

End returns the position of first character immediately after the node.

func (*EmptyStmt) Pos

func (s *EmptyStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*EmptyStmt) String

func (s *EmptyStmt) String() string

type Error

type Error struct {
	Pos SourceFilePos
	Msg string
}

Error represents a parser error.

func (Error) Error

func (e Error) Error() string

type ErrorExpr

type ErrorExpr struct {
	Expr     Expr
	ErrorPos Pos
	LParen   Pos
	RParen   Pos
}

ErrorExpr represents an error expression

func (*ErrorExpr) End

func (e *ErrorExpr) End() Pos

End returns the position of first character immediately after the node.

func (*ErrorExpr) Pos

func (e *ErrorExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ErrorExpr) String

func (e *ErrorExpr) String() string

type ErrorList

type ErrorList []*Error

ErrorList is a collection of parser errors.

func (*ErrorList) Add

func (p *ErrorList) Add(pos SourceFilePos, msg string)

Add adds a new parser error to the collection.

func (ErrorList) Err

func (p ErrorList) Err() error

Err returns an error.

func (ErrorList) Error

func (p ErrorList) Error() string

func (ErrorList) Len

func (p ErrorList) Len() int

Len returns the number of elements in the collection.

func (ErrorList) Less

func (p ErrorList) Less(i, j int) bool

func (ErrorList) Sort

func (p ErrorList) Sort()

Sort sorts the collection.

func (ErrorList) Swap

func (p ErrorList) Swap(i, j int)

type ExportStmt

type ExportStmt struct {
	ExportPos Pos
	Result    Expr
}

ExportStmt represents an export statement.

func (*ExportStmt) End

func (s *ExportStmt) End() Pos

End returns the position of first character immediately after the node.

func (*ExportStmt) Pos

func (s *ExportStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ExportStmt) String

func (s *ExportStmt) String() string

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr represents an expression node in the AST.

type ExprStmt

type ExprStmt struct {
	Expr Expr
}

ExprStmt represents an expression statement.

func (*ExprStmt) End

func (s *ExprStmt) End() Pos

End returns the position of first character immediately after the node.

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ExprStmt) String

func (s *ExprStmt) String() string

type File

type File struct {
	InputFile *SourceFile
	Stmts     []Stmt
}

File represents a file unit.

func (*File) End

func (n *File) End() Pos

End returns the position of first character immediately after the node.

func (*File) Pos

func (n *File) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*File) String

func (n *File) String() string

type FloatLit

type FloatLit struct {
	Value    float64
	ValuePos Pos
	Literal  string
}

FloatLit represents a floating point literal.

func (*FloatLit) End

func (e *FloatLit) End() Pos

End returns the position of first character immediately after the node.

func (*FloatLit) Pos

func (e *FloatLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*FloatLit) String

func (e *FloatLit) String() string

type ForInStmt

type ForInStmt struct {
	ForPos   Pos
	Key      *Ident
	Value    *Ident
	Iterable Expr
	Body     *BlockStmt
}

ForInStmt represents a for-in statement.

func (*ForInStmt) End

func (s *ForInStmt) End() Pos

End returns the position of first character immediately after the node.

func (*ForInStmt) Pos

func (s *ForInStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ForInStmt) String

func (s *ForInStmt) String() string

type ForStmt

type ForStmt struct {
	ForPos Pos
	Init   Stmt
	Cond   Expr
	Post   Stmt
	Body   *BlockStmt
}

ForStmt represents a for statement.

func (*ForStmt) End

func (s *ForStmt) End() Pos

End returns the position of first character immediately after the node.

func (*ForStmt) Pos

func (s *ForStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ForStmt) String

func (s *ForStmt) String() string

type FuncLit

type FuncLit struct {
	Type *FuncType
	Body *BlockStmt
}

FuncLit represents a function literal.

func (*FuncLit) End

func (e *FuncLit) End() Pos

End returns the position of first character immediately after the node.

func (*FuncLit) Pos

func (e *FuncLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*FuncLit) String

func (e *FuncLit) String() string

type FuncType

type FuncType struct {
	FuncPos  Pos
	Params   *IdentList
	Receiver *IdentList
}

FuncType represents a function type definition.

func (*FuncType) End

func (e *FuncType) End() Pos

End returns the position of first character immediately after the node.

func (*FuncType) Pos

func (e *FuncType) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*FuncType) String

func (e *FuncType) String() string

type Ident

type Ident struct {
	Name    string
	NamePos Pos
}

Ident represents an identifier.

func (*Ident) End

func (e *Ident) End() Pos

End returns the position of first character immediately after the node.

func (*Ident) Pos

func (e *Ident) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*Ident) String

func (e *Ident) String() string

type IdentList

type IdentList struct {
	LParen  Pos
	VarArgs bool
	List    []*Ident
	RParen  Pos
}

IdentList represents a list of identifiers.

func (*IdentList) End

func (n *IdentList) End() Pos

End returns the position of first character immediately after the node.

func (*IdentList) NumFields

func (n *IdentList) NumFields() int

NumFields returns the number of fields.

func (*IdentList) Pos

func (n *IdentList) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*IdentList) String

func (n *IdentList) String() string

type IfStmt

type IfStmt struct {
	IfPos Pos
	Init  Stmt
	Cond  Expr
	Body  *BlockStmt
	Else  Stmt // else branch; or nil
}

IfStmt represents an if statement.

func (*IfStmt) End

func (s *IfStmt) End() Pos

End returns the position of first character immediately after the node.

func (*IfStmt) Pos

func (s *IfStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*IfStmt) String

func (s *IfStmt) String() string

type ImmutableExpr

type ImmutableExpr struct {
	Expr     Expr
	ErrorPos Pos
	LParen   Pos
	RParen   Pos
}

ImmutableExpr represents an immutable expression

func (*ImmutableExpr) End

func (e *ImmutableExpr) End() Pos

End returns the position of first character immediately after the node.

func (*ImmutableExpr) Pos

func (e *ImmutableExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ImmutableExpr) String

func (e *ImmutableExpr) String() string

type ImportExpr

type ImportExpr struct {
	ModuleName string
	Token      token.Token
	TokenPos   Pos
}

ImportExpr represents an import expression

func (*ImportExpr) End

func (e *ImportExpr) End() Pos

End returns the position of first character immediately after the node.

func (*ImportExpr) Pos

func (e *ImportExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ImportExpr) String

func (e *ImportExpr) String() string

type IncDecStmt

type IncDecStmt struct {
	Expr     Expr
	Token    token.Token
	TokenPos Pos
}

IncDecStmt represents increment or decrement statement.

func (*IncDecStmt) End

func (s *IncDecStmt) End() Pos

End returns the position of first character immediately after the node.

func (*IncDecStmt) Pos

func (s *IncDecStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*IncDecStmt) String

func (s *IncDecStmt) String() string

type IndexExpr

type IndexExpr struct {
	Expr   Expr
	LBrack Pos
	Index  Expr
	RBrack Pos
	Reci   bool
}

IndexExpr represents an index expression.

func (*IndexExpr) End

func (e *IndexExpr) End() Pos

End returns the position of first character immediately after the node.

func (*IndexExpr) Pos

func (e *IndexExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*IndexExpr) String

func (e *IndexExpr) String() string

type IntLit

type IntLit struct {
	Value    int64
	ValuePos Pos
	Literal  string
}

IntLit represents an integer literal.

func (*IntLit) End

func (e *IntLit) End() Pos

End returns the position of first character immediately after the node.

func (*IntLit) Pos

func (e *IntLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*IntLit) String

func (e *IntLit) String() string

type MapElementLit

type MapElementLit struct {
	Key      string
	KeyPos   Pos
	ColonPos Pos
	Value    Expr
}

MapElementLit represents a map element.

func (*MapElementLit) End

func (e *MapElementLit) End() Pos

End returns the position of first character immediately after the node.

func (*MapElementLit) Pos

func (e *MapElementLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*MapElementLit) String

func (e *MapElementLit) String() string

type MapLit

type MapLit struct {
	LBrace   Pos
	Elements []*MapElementLit
	RBrace   Pos
}

MapLit represents a map literal.

func (*MapLit) End

func (e *MapLit) End() Pos

End returns the position of first character immediately after the node.

func (*MapLit) Pos

func (e *MapLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*MapLit) String

func (e *MapLit) String() string

type Node

type Node interface {
	// Pos returns the position of first character belonging to the node.
	Pos() Pos
	// End returns the position of first character immediately after the node.
	End() Pos
	// String returns a string representation of the node.
	String() string
}

Node represents a node in the AST.

type Opcode

type Opcode = byte

Opcode represents a single byte operation code.

const (
	OpConstant      Opcode = iota // Load constant
	OpBComplement                 // bitwise complement
	OpPop                         // Pop
	OpTrue                        // Push true
	OpFalse                       // Push false
	OpEqual                       // Equal ==
	OpNotEqual                    // Not equal !=
	OpMinus                       // Minus -
	OpLNot                        // Logical not !
	OpJumpFalsy                   // Jump if falsy
	OpAndJump                     // Logical AND jump
	OpOrJump                      // Logical OR jump
	OpJump                        // Jump
	OpNull                        // Push null
	OpArray                       // Array object
	OpMap                         // Map object
	OpError                       // Error object
	OpImmutable                   // Immutable object
	OpIndex                       // Index operation
	OpSliceIndex                  // Slice operation
	OpCall                        // Call function
	OpReturn                      // Return
	OpGetGlobal                   // Get global variable
	OpSetGlobal                   // Set global variable
	OpSetSelGlobal                // Set global variable using selectors
	OpGetLocal                    // Get local variable
	OpSetLocal                    // Set local variable
	OpDefineLocal                 // Define local variable
	OpSetSelLocal                 // Set local variable using selectors
	OpGetFreePtr                  // Get free variable pointer object
	OpGetFree                     // Get free variables
	OpSetFree                     // Set free variables
	OpGetLocalPtr                 // Get local variable as a pointer
	OpSetSelFree                  // Set free variables using selectors
	OpGetBuiltin                  // Get builtin function
	OpClosure                     // Push closure
	OpIteratorInit                // Iterator init
	OpIteratorNext                // Iterator next
	OpIteratorKey                 // Iterator key
	OpIteratorValue               // Iterator value
	OpBinaryOp                    // Binary operation
	OpSuspend                     // Suspend VM
)

List of opcodes

type ParenExpr

type ParenExpr struct {
	Expr   Expr
	LParen Pos
	RParen Pos
}

ParenExpr represents a parenthesis wrapped expression.

func (*ParenExpr) End

func (e *ParenExpr) End() Pos

End returns the position of first character immediately after the node.

func (*ParenExpr) Pos

func (e *ParenExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ParenExpr) String

func (e *ParenExpr) String() string

type Parser

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

Parser parses the Tengo source files. It's based on Go's parser implementation.

func NewParser

func NewParser(file *SourceFile, src []byte, trace io.Writer) *Parser

NewParser creates a Parser.

func (*Parser) ParseFile

func (p *Parser) ParseFile() (file *File, err error)

ParseFile parses the source and returns an AST file unit.

type Pos

type Pos int

Pos represents a position in the file set.

const NoPos Pos = 0

NoPos represents an invalid position.

func (Pos) IsValid

func (p Pos) IsValid() bool

IsValid returns true if the position is valid.

type ReturnStmt

type ReturnStmt struct {
	ReturnPos Pos
	Result    Expr
}

ReturnStmt represents a return statement.

func (*ReturnStmt) End

func (s *ReturnStmt) End() Pos

End returns the position of first character immediately after the node.

func (*ReturnStmt) Pos

func (s *ReturnStmt) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*ReturnStmt) String

func (s *ReturnStmt) String() string

type ScanMode

type ScanMode int

ScanMode represents a scanner mode.

const (
	ScanComments ScanMode = 1 << iota
	DontInsertSemis
)

List of scanner modes.

type Scanner

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

Scanner reads the Tengo source text. It's based on Go's scanner implementation.

func NewScanner

func NewScanner(
	file *SourceFile,
	src []byte,
	errorHandler ScannerErrorHandler,
	mode ScanMode,
) *Scanner

NewScanner creates a Scanner.

func (*Scanner) ErrorCount

func (s *Scanner) ErrorCount() int

ErrorCount returns the number of errors.

func (*Scanner) Scan

func (s *Scanner) Scan() (
	tok token.Token,
	literal string,
	pos Pos,
)

Scan returns a token, token literal and its position.

type ScannerErrorHandler

type ScannerErrorHandler func(pos SourceFilePos, msg string)

ScannerErrorHandler is an error handler for the scanner.

type SelectorExpr

type SelectorExpr struct {
	Expr Expr
	Sel  Expr
	Reci bool
}

SelectorExpr represents a selector expression.

func (*SelectorExpr) End

func (e *SelectorExpr) End() Pos

End returns the position of first character immediately after the node.

func (*SelectorExpr) Pos

func (e *SelectorExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*SelectorExpr) String

func (e *SelectorExpr) String() string

type SliceExpr

type SliceExpr struct {
	Expr   Expr
	LBrack Pos
	Low    Expr
	High   Expr
	RBrack Pos
}

SliceExpr represents a slice expression.

func (*SliceExpr) End

func (e *SliceExpr) End() Pos

End returns the position of first character immediately after the node.

func (*SliceExpr) Pos

func (e *SliceExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*SliceExpr) String

func (e *SliceExpr) String() string

type SourceFile

type SourceFile struct {

	// SourceFile name as provided to AddFile
	Name string
	// SourcePos value range for this file is [base...base+size]
	Base int
	// SourceFile size as provided to AddFile
	Size int
	// Lines contains the offset of the first character for each line
	// (the first entry is always 0)
	Lines []int
	// contains filtered or unexported fields
}

SourceFile represents a source file.

func (*SourceFile) AddLine

func (f *SourceFile) AddLine(offset int)

AddLine adds a new line.

func (*SourceFile) FileSetPos

func (f *SourceFile) FileSetPos(offset int) Pos

FileSetPos returns the position in the file set.

func (*SourceFile) LineCount

func (f *SourceFile) LineCount() int

LineCount returns the current number of lines.

func (*SourceFile) LineStart

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

LineStart returns the position of the first character in the line.

func (*SourceFile) Offset

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

Offset translates the file set position into the file offset.

func (*SourceFile) Position

func (f *SourceFile) Position(p Pos) (pos SourceFilePos)

Position translates the file set position into the file position.

func (*SourceFile) Set

func (f *SourceFile) Set() *SourceFileSet

Set returns SourceFileSet.

type SourceFilePos

type SourceFilePos 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)
}

SourceFilePos represents a position information in the file.

func (SourceFilePos) IsValid

func (p SourceFilePos) IsValid() bool

IsValid returns true if the position is valid.

func (SourceFilePos) String

func (p SourceFilePos) String() string

String returns a string in one of several forms:

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

type SourceFileSet

type SourceFileSet struct {
	Base     int           // base offset for the next file
	Files    []*SourceFile // list of files in the order added to the set
	LastFile *SourceFile   // cache of last file looked up
}

SourceFileSet represents a set of source files.

func NewFileSet

func NewFileSet() *SourceFileSet

NewFileSet creates a new file set.

func (*SourceFileSet) AddFile

func (s *SourceFileSet) AddFile(filename string, base, size int) *SourceFile

AddFile adds a new file in the file set.

func (*SourceFileSet) File

func (s *SourceFileSet) File(p Pos) (f *SourceFile)

File returns the file that contains the position p. If no such file is found (for instance for p == NoPos), the result is nil.

func (*SourceFileSet) Position

func (s *SourceFileSet) Position(p Pos) (pos SourceFilePos)

Position converts a SourcePos p in the fileset into a SourceFilePos value.

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt represents a statement in the AST.

type StringLit

type StringLit struct {
	Value    string
	ValuePos Pos
	Literal  string
}

StringLit represents a string literal.

func (*StringLit) End

func (e *StringLit) End() Pos

End returns the position of first character immediately after the node.

func (*StringLit) Pos

func (e *StringLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*StringLit) String

func (e *StringLit) String() string

type UnaryExpr

type UnaryExpr struct {
	Expr     Expr
	Token    token.Token
	TokenPos Pos
}

UnaryExpr represents an unary operator expression.

func (*UnaryExpr) End

func (e *UnaryExpr) End() Pos

End returns the position of first character immediately after the node.

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

type UndefinedLit

type UndefinedLit struct {
	TokenPos Pos
}

UndefinedLit represents an undefined literal.

func (*UndefinedLit) End

func (e *UndefinedLit) End() Pos

End returns the position of first character immediately after the node.

func (*UndefinedLit) Pos

func (e *UndefinedLit) Pos() Pos

Pos returns the position of first character belonging to the node.

func (*UndefinedLit) String

func (e *UndefinedLit) String() string

Jump to

Keyboard shortcuts

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