Documentation
¶
Index ¶
- func IsStatement(v interface{}) bool
- func StripCR(b []byte, comment bool) []byte
- type ArrayLit
- type AssignStmt
- type BadDecl
- type BadExpr
- type BadStmt
- type BinaryExpr
- type BlockStmt
- type BoolLit
- type BranchStmt
- type CallExpr
- type CatchStmt
- type CharLit
- type Comment
- type CommentGroup
- type CondExpr
- type Decl
- type DeclStmt
- type EmptyStmt
- type Error
- type ErrorList
- type Expr
- type ExprStmt
- type File
- type FinallyStmt
- type FloatLit
- type ForInStmt
- type ForStmt
- type FuncLit
- type FuncType
- type GenDecl
- type Ident
- type IdentList
- type IfStmt
- type ImportExpr
- type IncDecStmt
- type IndexExpr
- type IntLit
- type MapElementLit
- type MapLit
- type Mode
- type Node
- type ParamSpec
- type ParenExpr
- type Parser
- type Pos
- type ReturnStmt
- type ScanMode
- type Scanner
- type ScannerErrorHandler
- type SelectorExpr
- type SliceExpr
- type SourceFile
- func (f *SourceFile) AddLine(offset int)
- func (f *SourceFile) FileSetPos(offset int) Pos
- func (f *SourceFile) Line(p Pos) int
- func (f *SourceFile) LineCount() int
- func (f *SourceFile) LineStart(line int) Pos
- func (f *SourceFile) Offset(p Pos) int
- func (f *SourceFile) Position(p Pos) (pos SourceFilePos)
- func (f *SourceFile) Set() *SourceFileSet
- type SourceFilePos
- type SourceFileSet
- type Spec
- type Stmt
- type StringLit
- type ThrowStmt
- type TryStmt
- type UintLit
- type UnaryExpr
- type UndefinedLit
- type ValueSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStatement ¶
func IsStatement(v interface{}) bool
IsStatement returns true if given value is implements interface{ stmtNode() }.
Types ¶
type ArrayLit ¶
ArrayLit represents an array literal.
type AssignStmt ¶
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 BadDecl ¶
type BadDecl struct {
From, To Pos // position range of bad declaration
}
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
type BadExpr ¶
BadExpr represents a bad expression.
type BadStmt ¶
BadStmt represents a bad statement.
type BinaryExpr ¶
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 ¶
BlockStmt represents a block statement.
type BoolLit ¶
BoolLit represents a boolean literal.
type BranchStmt ¶
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 ¶
CallExpr represents a function call expression.
type CatchStmt ¶
type CatchStmt struct { CatchPos Pos Ident *Ident // can be nil if ident is missing Body *BlockStmt }
CatchStmt represents an catch statement.
type CharLit ¶
CharLit represents a character literal.
type Comment ¶
type Comment struct { Slash Pos // position of "/" starting the comment Text string // comment text (excluding '\n' for //-style comments) }
A Comment node represents a single //-style or /*-style comment.
type CommentGroup ¶
type CommentGroup struct {
List []*Comment // len(List) > 0
}
A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.
func (*CommentGroup) End ¶
func (g *CommentGroup) End() Pos
End returns the position of last comment's end position.
func (*CommentGroup) Pos ¶
func (g *CommentGroup) Pos() Pos
Pos returns the position of the first comment.
func (*CommentGroup) Text ¶
func (g *CommentGroup) Text() string
Text returns the text of the comment. Comment markers (//, /*, and */), the first space of a line comment, and leading and trailing empty lines are removed. Multiple empty lines are reduced to one, and trailing space on lines is trimmed. Unless the result is empty, it is newline-terminated.
type CondExpr ¶
CondExpr represents a ternary conditional expression.
type Decl ¶
type Decl interface { Node // contains filtered or unexported methods }
Decl wraps methods for all declaration nodes.
type DeclStmt ¶
type DeclStmt struct {
Decl // *GenDecl with VAR token
}
A DeclStmt node represents a declaration in a statement list.
type EmptyStmt ¶
EmptyStmt represents an empty statement.
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.
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.
type File ¶
type File struct { InputFile *SourceFile Stmts []Stmt Comments []*CommentGroup }
File represents a file unit.
type FinallyStmt ¶
FinallyStmt represents an finally statement.
func (*FinallyStmt) End ¶
func (s *FinallyStmt) End() Pos
End returns the position of first character immediately after the node.
func (*FinallyStmt) Pos ¶
func (s *FinallyStmt) Pos() Pos
Pos returns the position of first character belonging to the node.
func (*FinallyStmt) String ¶
func (s *FinallyStmt) String() string
type FloatLit ¶
FloatLit represents a floating point literal.
type ForInStmt ¶
ForInStmt represents a for-in statement.
type ForStmt ¶
ForStmt represents a for statement.
type FuncLit ¶
FuncLit represents a function literal.
type FuncType ¶
FuncType represents a function type definition.
type GenDecl ¶
type GenDecl struct { TokPos Pos // position of Tok Tok token.Token // Var Lparen Pos // position of '(', if any Specs []Spec Rparen Pos // position of ')', if any }
A GenDecl node (generic declaration node) represents a variable declaration. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.
Relationship between Tok value and Specs element type:
token.Var *ValueSpec
type Ident ¶
Ident represents an identifier.
type IdentList ¶
IdentList represents a list of identifiers.
type IfStmt ¶
type IfStmt struct { IfPos Pos Init Stmt Cond Expr Body *BlockStmt Else Stmt // else branch; or nil }
IfStmt represents an if statement.
type ImportExpr ¶
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 ¶
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 ¶
IndexExpr represents an index expression.
type IntLit ¶
IntLit represents an integer literal.
type MapElementLit ¶
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.
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 ParamSpec ¶
A ParamSpec node represents a parameter declaration
type ParenExpr ¶
ParenExpr represents a parenthesis wrapped expression.
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 NewParserWithMode ¶
NewParserWithMode creates a Parser with parser mode flags.
type Pos ¶
type Pos int
Pos represents a position in the file set.
const NoPos Pos = 0
NoPos represents an invalid position.
type ReturnStmt ¶
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 Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner reads the Charlang 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 ¶
ErrorCount returns the number of errors.
type ScannerErrorHandler ¶
type ScannerErrorHandler func(pos SourceFilePos, msg string)
ScannerErrorHandler is an error handler for the scanner.
type SelectorExpr ¶
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 ¶
SliceExpr represents a slice expression.
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) FileSetPos ¶
func (f *SourceFile) FileSetPos(offset int) Pos
FileSetPos returns the position in the file set.
func (*SourceFile) Line ¶
func (f *SourceFile) Line(p Pos) int
Line returns the line of given position.
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.
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 (*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 Spec ¶
type Spec interface { Node // contains filtered or unexported methods }
Spec node represents a single (non-parenthesized) variable declaration. The Spec type stands for any of *ParamSpec or *ValueSpec.
type Stmt ¶
type Stmt interface { Node // contains filtered or unexported methods }
Stmt represents a statement in the AST.
type StringLit ¶
StringLit represents a string literal.
type ThrowStmt ¶
ThrowStmt represents an throw statement.
type TryStmt ¶
type TryStmt struct { TryPos Pos Body *BlockStmt Catch *CatchStmt // catch branch; or nil Finally *FinallyStmt // finally branch; or nil }
TryStmt represents an try statement.
type UintLit ¶
UintLit represents an unsigned integer literal.
type UnaryExpr ¶
UnaryExpr represents an unary operator expression.
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
type ValueSpec ¶
type ValueSpec struct { Idents []*Ident // TODO: slice is reserved for tuple assignment Values []Expr // initial values; or nil Data interface{} // iota }
A ValueSpec node represents a variable declaration