ast

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2016 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk added in v0.2.0

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. 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).

Types

type ArithmExp

type ArithmExp struct {
	Token       token.Token
	Left, Right token.Pos
	X           ArithmExpr
}

ArithmExp represents an arithmetic expansion.

func (*ArithmExp) End

func (a *ArithmExp) End() token.Pos

func (*ArithmExp) Pos

func (a *ArithmExp) Pos() token.Pos

type ArithmExpr

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

ArithmExpr represents all nodes that form arithmetic expressions.

type ArrayExpr

type ArrayExpr struct {
	Lparen, Rparen token.Pos
	List           []Word
}

ArrayExpr represents a Bash array expression.

func (*ArrayExpr) End

func (a *ArrayExpr) End() token.Pos

func (*ArrayExpr) Pos

func (a *ArrayExpr) Pos() token.Pos

type Assign

type Assign struct {
	Append bool
	Name   *Lit
	Value  Word
}

Assign represents an assignment to a variable.

func (*Assign) End

func (a *Assign) End() token.Pos

func (*Assign) Pos

func (a *Assign) Pos() token.Pos

type BinaryCmd

type BinaryCmd struct {
	OpPos token.Pos
	Op    token.Token
	X, Y  *Stmt
}

BinaryCmd represents a binary expression between two statements.

func (*BinaryCmd) End

func (b *BinaryCmd) End() token.Pos

func (*BinaryCmd) Pos

func (b *BinaryCmd) Pos() token.Pos

type BinaryExpr

type BinaryExpr struct {
	OpPos token.Pos
	Op    token.Token
	X, Y  ArithmExpr
}

BinaryExpr represents a binary expression between two arithmetic expression.

func (*BinaryExpr) End

func (b *BinaryExpr) End() token.Pos

func (*BinaryExpr) Pos

func (b *BinaryExpr) Pos() token.Pos

type Block

type Block struct {
	Lbrace, Rbrace token.Pos
	Stmts          []*Stmt
}

Block represents a series of commands that should be executed in a nested scope.

func (*Block) End

func (b *Block) End() token.Pos

func (*Block) Pos

func (b *Block) Pos() token.Pos

type CStyleLoop

type CStyleLoop struct {
	Lparen, Rparen   token.Pos
	Init, Cond, Post ArithmExpr
}

CStyleLoop represents the behaviour of a for clause similar to the C language.

func (*CStyleLoop) End

func (c *CStyleLoop) End() token.Pos

func (*CStyleLoop) Pos

func (c *CStyleLoop) Pos() token.Pos

type CallExpr

type CallExpr struct {
	Args []Word
}

CallExpr represents a command execution or function call.

func (*CallExpr) End

func (c *CallExpr) End() token.Pos

func (*CallExpr) Pos

func (c *CallExpr) Pos() token.Pos

type CaseClause

type CaseClause struct {
	Case, Esac token.Pos
	Word       Word
	List       []*PatternList
}

CaseClause represents a case (switch) clause.

func (*CaseClause) End

func (c *CaseClause) End() token.Pos

func (*CaseClause) Pos

func (c *CaseClause) Pos() token.Pos

type CmdSubst

type CmdSubst struct {
	Left, Right token.Pos
	Backquotes  bool
	Stmts       []*Stmt
}

CmdSubst represents a command substitution.

func (*CmdSubst) End

func (c *CmdSubst) End() token.Pos

func (*CmdSubst) Pos

func (c *CmdSubst) Pos() token.Pos

type Command

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

Command represents all nodes that are simple commands, which are directly placed in a Stmt.

type Comment

type Comment struct {
	Hash token.Pos
	Text string
}

Comment represents a single comment on a single line.

func (*Comment) End

func (c *Comment) End() token.Pos

func (*Comment) Pos

func (c *Comment) Pos() token.Pos

type CoprocClause added in v0.3.0

type CoprocClause struct {
	Coproc token.Pos
	Name   *Lit
	Stmt   *Stmt
}

CoprocClause represents a Bash coproc clause.

func (*CoprocClause) End added in v0.3.0

func (c *CoprocClause) End() token.Pos

func (*CoprocClause) Pos added in v0.3.0

func (c *CoprocClause) Pos() token.Pos

type DeclClause

type DeclClause struct {
	Position token.Pos
	Variant  string
	Opts     []Word
	Assigns  []*Assign
}

DeclClause represents a Bash declare clause.

func (*DeclClause) End

func (d *DeclClause) End() token.Pos

func (*DeclClause) Pos

func (d *DeclClause) Pos() token.Pos

type Elif

type Elif struct {
	Elif, Then token.Pos
	CondStmts  []*Stmt
	ThenStmts  []*Stmt
}

Elif represents an "else if" case in an if clause.

type EvalClause

type EvalClause struct {
	Eval token.Pos
	Stmt *Stmt
}

EvalClause represents a Bash eval clause.

func (*EvalClause) End

func (e *EvalClause) End() token.Pos

func (*EvalClause) Pos

func (e *EvalClause) Pos() token.Pos

type Expansion

type Expansion struct {
	Op   token.Token
	Word Word
}

Expansion represents string manipulation in a ParamExp other than those covered by Replace.

type ExtGlob added in v0.3.0

type ExtGlob struct {
	Token   token.Token
	Pattern Lit
}

ExtGlob represents a Bash extended globbing expression. Note that these are parsed independently of whether shopt has been called or not.

func (*ExtGlob) End added in v0.3.0

func (e *ExtGlob) End() token.Pos

func (*ExtGlob) Pos added in v0.3.0

func (e *ExtGlob) Pos() token.Pos

type File

type File struct {
	Name string

	Stmts    []*Stmt
	Comments []*Comment

	// Lines contains the offset of the first character for each
	// line (the first entry is always 0)
	Lines []int
}

File is a shell program.

func (*File) End

func (f *File) End() token.Pos

func (*File) Pos

func (f *File) Pos() token.Pos

func (*File) Position

func (f *File) Position(p token.Pos) (pos token.Position)

type ForClause

type ForClause struct {
	For, Do, Done token.Pos
	Loop          Loop
	DoStmts       []*Stmt
}

ForClause represents a for clause.

func (*ForClause) End

func (f *ForClause) End() token.Pos

func (*ForClause) Pos

func (f *ForClause) Pos() token.Pos

type FuncDecl

type FuncDecl struct {
	Position  token.Pos
	BashStyle bool
	Name      Lit
	Body      *Stmt
}

FuncDecl represents the declaration of a function.

func (*FuncDecl) End

func (f *FuncDecl) End() token.Pos

func (*FuncDecl) Pos

func (f *FuncDecl) Pos() token.Pos

type IfClause

type IfClause struct {
	If, Then, Fi token.Pos
	CondStmts    []*Stmt
	ThenStmts    []*Stmt
	Elifs        []*Elif
	Else         token.Pos
	ElseStmts    []*Stmt
}

IfClause represents an if statement.

func (*IfClause) End

func (c *IfClause) End() token.Pos

func (*IfClause) Pos

func (c *IfClause) Pos() token.Pos

type Index

type Index struct {
	Word Word
}

Index represents access to an array via an index inside a ParamExp.

type LetClause

type LetClause struct {
	Let   token.Pos
	Exprs []ArithmExpr
}

LetClause represents a Bash let clause.

func (*LetClause) End

func (l *LetClause) End() token.Pos

func (*LetClause) Pos

func (l *LetClause) Pos() token.Pos

type Lit

type Lit struct {
	ValuePos token.Pos
	Value    string
}

Lit represents an unquoted string consisting of characters that were not tokenized.

func (*Lit) End

func (l *Lit) End() token.Pos

func (*Lit) Pos

func (l *Lit) Pos() token.Pos

type Loop

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

Loop represents all nodes that can be loops in a for clause.

type Node

type Node interface {
	// Pos returns the first character of the node
	Pos() token.Pos
	// End returns the character immediately after the node
	End() token.Pos
}

Node represents an AST node.

type ParamExp

type ParamExp struct {
	Dollar        token.Pos
	Short, Length bool
	Param         Lit
	Ind           *Index
	Repl          *Replace
	Exp           *Expansion
}

ParamExp represents a parameter expansion.

func (*ParamExp) End

func (p *ParamExp) End() token.Pos

func (*ParamExp) Pos

func (p *ParamExp) Pos() token.Pos

type ParenExpr

type ParenExpr struct {
	Lparen, Rparen token.Pos
	X              ArithmExpr
}

ParenExpr represents an expression within parentheses inside an ArithmExp.

func (*ParenExpr) End

func (p *ParenExpr) End() token.Pos

func (*ParenExpr) Pos

func (p *ParenExpr) Pos() token.Pos

type PatternList

type PatternList struct {
	Op       token.Token
	OpPos    token.Pos
	Patterns []Word
	Stmts    []*Stmt
}

PatternList represents a pattern list (case) within a CaseClause.

type ProcSubst

type ProcSubst struct {
	OpPos, Rparen token.Pos
	Op            token.Token
	Stmts         []*Stmt
}

ProcSubst represents a Bash process substitution.

func (*ProcSubst) End

func (s *ProcSubst) End() token.Pos

func (*ProcSubst) Pos

func (s *ProcSubst) Pos() token.Pos

type Quoted

type Quoted struct {
	QuotePos token.Pos
	Quote    token.Token
	Parts    []WordPart
}

Quoted represents a list of nodes within double quotes.

func (*Quoted) End

func (q *Quoted) End() token.Pos

func (*Quoted) Pos

func (q *Quoted) Pos() token.Pos

type Redirect

type Redirect struct {
	OpPos      token.Pos
	Op         token.Token
	N          *Lit
	Word, Hdoc Word
}

Redirect represents an input/output redirection.

func (*Redirect) End

func (r *Redirect) End() token.Pos

func (*Redirect) Pos

func (r *Redirect) Pos() token.Pos

type Replace

type Replace struct {
	All        bool
	Orig, With Word
}

Replace represents a search and replace inside a ParamExp.

type SglQuoted

type SglQuoted struct {
	QuotePos token.Pos
	Quote    token.Token
	Value    string
}

SglQuoted represents a single-quoted string.

func (*SglQuoted) End

func (q *SglQuoted) End() token.Pos

func (*SglQuoted) Pos

func (q *SglQuoted) Pos() token.Pos

type Stmt

type Stmt struct {
	Cmd        Command
	Position   token.Pos
	Negated    bool
	Background bool
	Assigns    []*Assign
	Redirs     []*Redirect
}

Stmt represents a statement, otherwise known as a compound command. It is compromised of a command and other components that may come before or after it.

func (*Stmt) End

func (s *Stmt) End() token.Pos

func (*Stmt) Pos

func (s *Stmt) Pos() token.Pos

type Subshell

type Subshell struct {
	Lparen, Rparen token.Pos
	Stmts          []*Stmt
}

Subshell represents a series of commands that should be executed in a nested shell environment.

func (*Subshell) End

func (s *Subshell) End() token.Pos

func (*Subshell) Pos

func (s *Subshell) Pos() token.Pos

type TestClause

type TestClause struct {
	Left, Right token.Pos
	X           ArithmExpr
}

TestClause represents a Bash extended test clause.

func (*TestClause) End

func (t *TestClause) End() token.Pos

func (*TestClause) Pos

func (t *TestClause) Pos() token.Pos

type UnaryExpr

type UnaryExpr struct {
	OpPos token.Pos
	Op    token.Token
	Post  bool
	X     ArithmExpr
}

UnaryExpr represents an unary expression over a node, either before or after it.

func (*UnaryExpr) End

func (u *UnaryExpr) End() token.Pos

func (*UnaryExpr) Pos

func (u *UnaryExpr) Pos() token.Pos

type UntilClause

type UntilClause struct {
	Until, Do, Done token.Pos
	CondStmts       []*Stmt
	DoStmts         []*Stmt
}

UntilClause represents an until clause.

func (*UntilClause) End

func (u *UntilClause) End() token.Pos

func (*UntilClause) Pos

func (u *UntilClause) Pos() token.Pos

type Visitor added in v0.2.0

type Visitor interface {
	Visit(node Node) (w Visitor)
}

Visitor holds 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).

type WhileClause

type WhileClause struct {
	While, Do, Done token.Pos
	CondStmts       []*Stmt
	DoStmts         []*Stmt
}

WhileClause represents a while clause.

func (*WhileClause) End

func (w *WhileClause) End() token.Pos

func (*WhileClause) Pos

func (w *WhileClause) Pos() token.Pos

type Word

type Word struct {
	Parts []WordPart
}

Word represents a list of nodes that are contiguous to each other. The word is delimeted by word boundaries.

func (*Word) End

func (w *Word) End() token.Pos

func (*Word) Pos

func (w *Word) Pos() token.Pos

type WordIter

type WordIter struct {
	Name Lit
	List []Word
}

WordIter represents the iteration of a variable over a series of words in a for clause.

func (*WordIter) End

func (w *WordIter) End() token.Pos

func (*WordIter) Pos

func (w *WordIter) Pos() token.Pos

type WordPart

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

WordPart represents all nodes that can form a word.

Jump to

Keyboard shortcuts

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