Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
 - func IsLValue(expr Expr) bool
 - func PosErrorf(pos Position, format string, args ...interface{}) error
 - func SpecialVarIndex(name string) int
 - func SpecialVarName(index int) string
 - func Walk(v Visitor, node Node)
 - func WalkExprList(v Visitor, exprs []Expr)
 - func WalkStmtList(v Visitor, stmts []Stmt)
 - type Action
 - type AssignExpr
 - type AugAssignExpr
 - type BinaryExpr
 - type BlockStmt
 - type BreakStmt
 - type CallExpr
 - type CondExpr
 - type ContinueStmt
 - type DeleteStmt
 - type DoWhileStmt
 - type ExitStmt
 - type Expr
 - type ExprStmt
 - type FieldExpr
 - type ForInStmt
 - type ForStmt
 - type Function
 - type GetlineExpr
 - type GroupingExpr
 - type IfStmt
 - type InExpr
 - type IncrExpr
 - type IndexExpr
 - type MultiExpr
 - type NamedFieldExpr
 - type NextStmt
 - type NextfileStmt
 - type Node
 - type NumExpr
 - type PositionError
 - type PrintStmt
 - type PrintfStmt
 - type Program
 - type RegExpr
 - type ReturnStmt
 - type Stmt
 - type Stmts
 - type StrExpr
 - type UnaryExpr
 - type UserCallExpr
 - type VarExpr
 - type Visitor
 - type WhileStmt
 
Constants ¶
const ( V_ILLEGAL = iota V_ARGC V_CONVFMT V_FILENAME V_FNR V_FS V_INPUTMODE V_NF V_NR V_OFMT V_OFS V_ORS V_OUTPUTMODE V_RLENGTH V_RS V_RSTART V_RT V_SUBSEP V_LAST = V_SUBSEP )
Variables ¶
This section is empty.
Functions ¶
func IsLValue ¶
IsLValue returns true if the given expression can be used as an lvalue (on the left-hand side of an assignment, in a ++ or -- operation, or as the third argument to sub or gsub).
func SpecialVarIndex ¶
SpecialVarIndex returns the "index" of the special variable, or 0 if it's not a special variable.
func SpecialVarName ¶ added in v1.15.0
SpecialVarName returns the name of the special variable by index.
func Walk ¶ added in v1.21.0
Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); if node is nil, it does nothing. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).
func WalkExprList ¶ added in v1.21.0
WalkExprList walks a visitor over a list of expression AST nodes
func WalkStmtList ¶ added in v1.21.0
WalkStmtList walks a visitor over a list of statement AST nodes
Types ¶
type AssignExpr ¶
AssignExpr is an expression like x = 1234.
func (*AssignExpr) String ¶
func (e *AssignExpr) String() string
type AugAssignExpr ¶
AugAssignExpr is an assignment expression like x += 5.
func (*AugAssignExpr) String ¶
func (e *AugAssignExpr) String() string
type BinaryExpr ¶
BinaryExpr is an expression like 1 + 2.
func (*BinaryExpr) String ¶
func (e *BinaryExpr) String() string
type BlockStmt ¶
type BlockStmt struct {
	Body  Stmts
	Start Position
	End   Position
}
    BlockStmt is a stand-alone block like { print "x" }.
type BreakStmt ¶
type BreakStmt struct {
	Start Position
	End   Position
}
    BreakStmt is a break statement.
type CallExpr ¶
type CallExpr struct {
	Func Token
	Args []Expr
}
    CallExpr is a builtin function call like length($1).
type ContinueStmt ¶
type ContinueStmt struct {
	Start Position
	End   Position
}
    ContinueStmt is a continue statement.
func (*ContinueStmt) EndPos ¶ added in v1.21.0
func (s *ContinueStmt) EndPos() Position
func (*ContinueStmt) StartPos ¶ added in v1.21.0
func (s *ContinueStmt) StartPos() Position
func (*ContinueStmt) String ¶
func (s *ContinueStmt) String() string
type DeleteStmt ¶
DeleteStmt is a statement like delete a[k].
func (*DeleteStmt) EndPos ¶ added in v1.21.0
func (s *DeleteStmt) EndPos() Position
func (*DeleteStmt) StartPos ¶ added in v1.21.0
func (s *DeleteStmt) StartPos() Position
func (*DeleteStmt) String ¶
func (s *DeleteStmt) String() string
type DoWhileStmt ¶
DoWhileStmt is a do-while loop.
func (*DoWhileStmt) EndPos ¶ added in v1.21.0
func (s *DoWhileStmt) EndPos() Position
func (*DoWhileStmt) StartPos ¶ added in v1.21.0
func (s *DoWhileStmt) StartPos() Position
func (*DoWhileStmt) String ¶
func (s *DoWhileStmt) String() string
type ExitStmt ¶
type ExitStmt struct {
	Status Expr
	Start  Position
	End    Position
}
    ExitStmt is an exit statement.
type ExprStmt ¶
type ExprStmt struct {
	Expr  Expr
	Start Position
	End   Position
}
    ExprStmt is statement like a bare function call: my_func(x).
type ForInStmt ¶
type ForInStmt struct {
	Var       string
	VarPos    Position
	Array     string
	ArrayPos  Position
	BodyStart Position
	Body      Stmts
	Start     Position
	End       Position
}
    ForInStmt is a for loop like for (k in a) print k, a[k].
type ForStmt ¶
type ForStmt struct {
	Pre       Stmt
	Cond      Expr
	Post      Stmt
	BodyStart Position
	Body      Stmts
	Start     Position
	End       Position
}
    ForStmt is a C-like for loop: for (i=0; i<10; i++) print i.
type GetlineExpr ¶
GetlineExpr is an expression read from file or pipe input.
func (*GetlineExpr) String ¶
func (e *GetlineExpr) String() string
type GroupingExpr ¶ added in v1.22.0
type GroupingExpr struct {
	Expr Expr
}
    GroupingExpr is a parenthesized grouping expression.
func (*GroupingExpr) String ¶ added in v1.22.0
func (e *GroupingExpr) String() string
type IfStmt ¶
type IfStmt struct {
	Cond      Expr
	BodyStart Position
	Body      Stmts
	Else      Stmts
	Start     Position
	End       Position
}
    IfStmt is an if or if-else statement.
type MultiExpr ¶
type MultiExpr struct {
	Exprs []Expr
}
    MultiExpr isn't an interpretable expression, but it's used as a pseudo-expression for print[f] parsing.
type NamedFieldExpr ¶ added in v1.17.0
type NamedFieldExpr struct {
	Field Expr
}
    NamedFieldExpr is an expression like @"name".
func (*NamedFieldExpr) String ¶ added in v1.17.0
func (e *NamedFieldExpr) String() string
type NextfileStmt ¶ added in v1.22.0
type NextfileStmt struct {
	Start Position
	End   Position
}
    NextfileStmt is a nextfile statement.
func (*NextfileStmt) EndPos ¶ added in v1.22.0
func (s *NextfileStmt) EndPos() Position
func (*NextfileStmt) StartPos ¶ added in v1.22.0
func (s *NextfileStmt) StartPos() Position
func (*NextfileStmt) String ¶ added in v1.22.0
func (s *NextfileStmt) String() string
type Node ¶ added in v1.21.0
type Node interface {
	// contains filtered or unexported methods
}
    Node is an interface to be satisfied by all AST elements. We need it to be able to work with AST in a generic way, like in ast.Walk().
type PositionError ¶ added in v1.21.0
type PositionError struct {
	// Source line/column position where the error occurred.
	Position Position
	// Error message.
	Message string
}
    PositionError represents an error bound to specific position in source.
func (*PositionError) Error ¶ added in v1.21.0
func (e *PositionError) Error() string
Error returns a formatted version of the error, including the line and column numbers.
type PrintfStmt ¶
PrintfStmt is a statement like printf "%3d", 1234.
func (*PrintfStmt) EndPos ¶ added in v1.21.0
func (s *PrintfStmt) EndPos() Position
func (*PrintfStmt) StartPos ¶ added in v1.21.0
func (s *PrintfStmt) StartPos() Position
func (*PrintfStmt) String ¶
func (s *PrintfStmt) String() string
type RegExpr ¶
type RegExpr struct {
	Regex string
}
    RegExpr is a stand-alone regex expression, equivalent to: $0 ~ /regex/.
type ReturnStmt ¶
type ReturnStmt struct {
	Value Expr
	Start Position
	End   Position
}
    ReturnStmt is a return statement.
func (*ReturnStmt) EndPos ¶ added in v1.21.0
func (s *ReturnStmt) EndPos() Position
func (*ReturnStmt) StartPos ¶ added in v1.21.0
func (s *ReturnStmt) StartPos() Position
func (*ReturnStmt) String ¶
func (s *ReturnStmt) String() string
type Stmt ¶
type Stmt interface {
	Node
	StartPos() Position // position of first character belonging to the node
	EndPos() Position   // position of first character immediately after the node
	String() string
	// contains filtered or unexported methods
}
    Stmt is the abstract syntax tree for any AWK statement.
type UnaryExpr ¶
type UnaryExpr struct {
	Op    Token
	Value Expr
}
    UnaryExpr is an expression like -1234.
type UserCallExpr ¶
UserCallExpr is a user-defined function call like my_func(1, 2, 3), where my_func is either AWK-defined or a native Go function.
func (*UserCallExpr) String ¶
func (e *UserCallExpr) String() string
type VarExpr ¶
type VarExpr struct {
	Name string
	Pos  Position
}
    VarExpr is a variable reference (special var, global, or local).
type Visitor ¶ added in v1.21.0
Visitor has a Visit method which is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).