ast

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2016 License: Apache-2.0 Imports: 6 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// RedirMapNoValue indicates the pipe has not redirection
	RedirMapNoValue = -1
	// RedirMapSupress indicates the rhs of map was suppressed
	RedirMapSupress = -2

	RforkFlags = "umnips"
)

Variables

View Source
var (
	DebugCmp bool
)

Functions

This section is empty.

Types

type AssignmentNode

type AssignmentNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

AssignmentNode is a node for variable assignments

func NewAssignmentNode

func NewAssignmentNode(info token.FileInfo, ident string, value Expr) *AssignmentNode

NewAssignmentNode creates a new assignment

func (*AssignmentNode) Identifier

func (n *AssignmentNode) Identifier() string

Identifier return the name of the variable.

func (*AssignmentNode) IsEqual

func (n *AssignmentNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*AssignmentNode) SetIdentifier

func (n *AssignmentNode) SetIdentifier(a string)

SetIdentifier sets the name of the variable

func (*AssignmentNode) SetValue

func (n *AssignmentNode) SetValue(val Expr)

SetValue sets the value of the list

func (*AssignmentNode) String

func (n *AssignmentNode) String() string

String returns the string representation of assignment statement

func (*AssignmentNode) Value

func (n *AssignmentNode) Value() Expr

Value returns the assigned object

type BindFnNode

type BindFnNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A BindFnNode represents the "bindfn" keyword.

func NewBindFnNode

func NewBindFnNode(info token.FileInfo, name, cmd string) *BindFnNode

NewBindFnNode creates a new bindfn statement

func (*BindFnNode) CmdName

func (n *BindFnNode) CmdName() string

CmdName return the command name

func (*BindFnNode) IsEqual

func (n *BindFnNode) IsEqual(other Node) bool

func (*BindFnNode) Name

func (n *BindFnNode) Name() string

Name return the function name

func (*BindFnNode) String

func (n *BindFnNode) String() string

String returns the string representation of bindfn

type BlockNode

type BlockNode struct {
	NodeType
	token.FileInfo

	Nodes []Node
}

BlockNode is the block

func NewBlockNode

func NewBlockNode(info token.FileInfo) *BlockNode

NewBlockNode creates a new block

func (*BlockNode) IsEqual

func (l *BlockNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*BlockNode) Push

func (l *BlockNode) Push(n Node)

Push adds a new node for a block of nodes

func (*BlockNode) String

func (l *BlockNode) String() string

type CommandNode

type CommandNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A CommandNode is a node for commands

func NewCommandNode

func NewCommandNode(info token.FileInfo, name string, multiline bool) *CommandNode

NewCommandNode creates a new node for commands

func (*CommandNode) AddArg

func (n *CommandNode) AddArg(a Expr)

AddArg adds a new argument to the command

func (*CommandNode) AddRedirect

func (n *CommandNode) AddRedirect(redir *RedirectNode)

AddRedirect adds a new redirect node to command

func (*CommandNode) Args

func (n *CommandNode) Args() []Expr

Args returns the list of arguments supplied to command.

func (*CommandNode) IsEqual

func (n *CommandNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*CommandNode) IsMulti

func (n *CommandNode) IsMulti() bool

func (*CommandNode) Name

func (n *CommandNode) Name() string

Name returns the program name

func (*CommandNode) Redirects

func (n *CommandNode) Redirects() []*RedirectNode

Redirects return the list of redirect maps of the command.

func (*CommandNode) SetArgs

func (n *CommandNode) SetArgs(args []Expr)

SetArgs sets an array of args to command

func (*CommandNode) SetMulti

func (n *CommandNode) SetMulti(b bool)

func (*CommandNode) String

func (n *CommandNode) String() string

type CommentNode

type CommentNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

CommentNode is the node for comments

func NewCommentNode

func NewCommentNode(info token.FileInfo, val string) *CommentNode

NewCommentNode creates a new node for comments

func (*CommentNode) IsEqual

func (n *CommentNode) IsEqual(other Node) bool

func (*CommentNode) String

func (n *CommentNode) String() string

String returns the string representation of comment

type ConcatExpr

type ConcatExpr struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

ConcatExpr is a concatenation of arguments

func NewConcatExpr

func NewConcatExpr(info token.FileInfo, parts []Expr) *ConcatExpr

func (*ConcatExpr) IsEqual

func (c *ConcatExpr) IsEqual(other Node) bool

func (*ConcatExpr) List

func (c *ConcatExpr) List() []Expr

func (*ConcatExpr) PushExpr

func (c *ConcatExpr) PushExpr(a Expr)

PushExpr push an expression to end of the concat list

func (*ConcatExpr) SetConcat

func (c *ConcatExpr) SetConcat(v []Expr)

SetConcatList set the concatenation parts

func (*ConcatExpr) String

func (c *ConcatExpr) String() string

type DumpNode

type DumpNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A DumpNode represents the "dump" keyword.

func NewDumpNode

func NewDumpNode(info token.FileInfo) *DumpNode

NewDumpNode creates a new dump statement

func (*DumpNode) Filename

func (n *DumpNode) Filename() Expr

Filename return the dump filename argument

func (*DumpNode) IsEqual

func (n *DumpNode) IsEqual(other Node) bool

func (*DumpNode) SetFilename

func (n *DumpNode) SetFilename(a Expr)

SetFilename set the dump filename

func (*DumpNode) String

func (n *DumpNode) String() string

String returns the string representation of dump node

type ExecAssignNode

type ExecAssignNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

An ExecAssignNode represents the node for execution assignment.

func NewExecAssignNode

func NewExecAssignNode(info token.FileInfo, name string, n Node) (*ExecAssignNode, error)

NewExecAssignNode creates a new node for executing something and store the result on a new variable. The assignment could be made using an operating system command, a pipe of commands or a function invocation. It returns a *ExecAssignNode ready to be executed or error when n is not a valid node for execution.

func (*ExecAssignNode) Command

func (n *ExecAssignNode) Command() Node

Command returns the command (or r-value). Command could be a CommandNode or FnNode

func (*ExecAssignNode) Identifier

func (n *ExecAssignNode) Identifier() string

Name returns the identifier (l-value)

func (*ExecAssignNode) IsEqual

func (n *ExecAssignNode) IsEqual(other Node) bool

func (*ExecAssignNode) SetCommand

func (n *ExecAssignNode) SetCommand(c Node)

SetCommand set the command part (NodeCommand or NodeFnDecl)

func (*ExecAssignNode) SetName

func (n *ExecAssignNode) SetName(name string)

SetName set the assignment identifier (l-value)

func (*ExecAssignNode) String

func (n *ExecAssignNode) String() string

String returns the string representation of command assignment statement

type Expr

type Expr Node

Expr is the interface of expression nodes.

func ExprFromToken

func ExprFromToken(val scanner.Token) (Expr, error)

ArgFromToken is a helper to get an argument based on the lexer token

type FnDeclNode

type FnDeclNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A FnDeclNode represents a function declaration.

func NewFnDeclNode

func NewFnDeclNode(info token.FileInfo, name string) *FnDeclNode

NewFnDeclNode creates a new function declaration

func (*FnDeclNode) AddArg

func (n *FnDeclNode) AddArg(arg string)

AddArg add a new argument to end of argument list

func (*FnDeclNode) Args

func (n *FnDeclNode) Args() []string

Args returns function arguments

func (*FnDeclNode) IsEqual

func (n *FnDeclNode) IsEqual(other Node) bool

func (*FnDeclNode) Name

func (n *FnDeclNode) Name() string

Name return the function name

func (*FnDeclNode) SetName

func (n *FnDeclNode) SetName(a string)

SetName set the function name

func (*FnDeclNode) SetTree

func (n *FnDeclNode) SetTree(t *Tree)

SetTree set the function tree

func (*FnDeclNode) String

func (n *FnDeclNode) String() string

String returns the string representation of function declaration

func (*FnDeclNode) Tree

func (n *FnDeclNode) Tree() *Tree

Tree return the function block

type FnInvNode

type FnInvNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A FnInvNode represents a function invocation statement.

func NewFnInvNode

func NewFnInvNode(info token.FileInfo, name string) *FnInvNode

NewFnInvNode creates a new function invocation

func (*FnInvNode) AddArg

func (n *FnInvNode) AddArg(arg Expr)

AddArg add another argument to end of argument list

func (*FnInvNode) Args

func (n *FnInvNode) Args() []Expr

Args return the invocation arguments.

func (*FnInvNode) IsEqual

func (n *FnInvNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*FnInvNode) Name

func (n *FnInvNode) Name() string

Name return the function name

func (*FnInvNode) SetName

func (n *FnInvNode) SetName(a string)

SetName set the function name

func (*FnInvNode) String

func (n *FnInvNode) String() string

type ForNode

type ForNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A ForNode represents the "for" keyword.

func NewForNode

func NewForNode(info token.FileInfo) *ForNode

NewForNode create a new for statement

func (*ForNode) Identifier

func (n *ForNode) Identifier() string

Identifier return the identifier part

func (*ForNode) InVar

func (n *ForNode) InVar() string

InVar return the "in" variable

func (*ForNode) IsEqual

func (n *ForNode) IsEqual(other Node) bool

func (*ForNode) SetIdentifier

func (n *ForNode) SetIdentifier(a string)

SetIdentifier set the for indentifier

func (*ForNode) SetInVar

func (n *ForNode) SetInVar(a string)

SetInVar set "in" variable

func (*ForNode) SetTree

func (n *ForNode) SetTree(a *Tree)

SetTree set the for block of statements

func (*ForNode) String

func (n *ForNode) String() string

String returns the string representation of for statement

func (*ForNode) Tree

func (n *ForNode) Tree() *Tree

Tree return the for block

type IfNode

type IfNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

IfNode represents the node for the "if" keyword.

func NewIfNode

func NewIfNode(info token.FileInfo) *IfNode

NewIfNode creates a new if block statement

func (*IfNode) ElseTree

func (n *IfNode) ElseTree() *Tree

ElseTree returns the else block

func (*IfNode) IfTree

func (n *IfNode) IfTree() *Tree

IfTree returns the if block

func (*IfNode) IsElseIf

func (n *IfNode) IsElseIf() bool

IsElseIf tells if the if is an else-if statement

func (*IfNode) IsEqual

func (n *IfNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*IfNode) Lvalue

func (n *IfNode) Lvalue() Expr

Lvalue returns the lefthand part of condition

func (*IfNode) Op

func (n *IfNode) Op() string

Op returns the condition operation

func (*IfNode) Rvalue

func (n *IfNode) Rvalue() Expr

Rvalue returns the righthand side of condition

func (*IfNode) SetElseTree

func (n *IfNode) SetElseTree(t *Tree)

SetElseTree sets the block of statements of the else block

func (*IfNode) SetElseif

func (n *IfNode) SetElseif(b bool)

SetElseif sets the else-if part

func (*IfNode) SetIfTree

func (n *IfNode) SetIfTree(t *Tree)

SetIfTree sets the block of statements of the if block

func (*IfNode) SetLvalue

func (n *IfNode) SetLvalue(arg Expr)

SetLvalue set the lefthand side of condition

func (*IfNode) SetOp

func (n *IfNode) SetOp(op string)

SetOp set the condition operation

func (*IfNode) SetRvalue

func (n *IfNode) SetRvalue(arg Expr)

SetRvalue set the righthand side of condition

func (*IfNode) String

func (n *IfNode) String() string

String returns the string representation of if statement

type ImportNode

type ImportNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

An ImportNode represents the node for an "import" keyword.

func NewImportNode

func NewImportNode(info token.FileInfo, path *StringExpr) *ImportNode

NewImportNode creates a new ImportNode object

func (*ImportNode) IsEqual

func (n *ImportNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*ImportNode) Path

func (n *ImportNode) Path() *StringExpr

Path returns the path of import.

func (*ImportNode) String

func (n *ImportNode) String() string

String returns the string representation of the import

type IndexExpr

type IndexExpr struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

IndexExpr is a indexed variable

func NewIndexExpr

func NewIndexExpr(info token.FileInfo, variable *VarExpr, index Expr) *IndexExpr

func (*IndexExpr) Index

func (i *IndexExpr) Index() Expr

func (*IndexExpr) IsEqual

func (i *IndexExpr) IsEqual(other Node) bool

func (*IndexExpr) String

func (i *IndexExpr) String() string

func (*IndexExpr) Var

func (i *IndexExpr) Var() *VarExpr

type IntExpr

type IntExpr struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

IntExpr is a integer used at indexing

func NewIntExpr

func NewIntExpr(info token.FileInfo, val int) *IntExpr

func (*IntExpr) IsEqual

func (i *IntExpr) IsEqual(other Node) bool

func (*IntExpr) String

func (i *IntExpr) String() string

func (*IntExpr) Value

func (i *IntExpr) Value() int

type ListExpr

type ListExpr struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

ListExpr is a list argument

func NewListExpr

func NewListExpr(info token.FileInfo, values []Expr) *ListExpr

func (*ListExpr) IsEqual

func (l *ListExpr) IsEqual(other Node) bool

func (*ListExpr) List

func (l *ListExpr) List() []Expr

func (*ListExpr) PushExpr

func (l *ListExpr) PushExpr(a Expr)

PushExpr push an expression to end of the list

func (*ListExpr) String

func (l *ListExpr) String() string

type Node

type Node interface {
	Type() NodeType
	IsEqual(Node) bool

	// Line of node in the file
	Line() int
	// Column of the node in the file
	Column() int

	// String representation of the node.
	// Note that it could not match the correspondent node in
	// the source code.
	String() string
}

Node represents nodes in the grammar

type NodeType

type NodeType int

NodeType is the types of grammar

const (
	// NodeSetenv is the type for "setenv" builtin keyword
	NodeSetenv NodeType = iota + 1

	// NodeBlock represents a program scope.
	NodeBlock

	// NodeAssignment is the type for simple variable assignment
	NodeAssignment

	// NodeExecAssign is the type for command or function assignment
	NodeExecAssign

	// NodeImport is the type for "import" builtin keyword
	NodeImport

	// NodeCommand is the type for command execution
	NodeCommand

	// NodePipe is the type for pipeline execution
	NodePipe

	// NodeRedirect is the type for redirection nodes
	NodeRedirect

	// NodeFnInv is the type for function invocation
	NodeFnInv

	// NodeStringExpr is the type of string expression (quoted or not).
	NodeStringExpr

	// NodeIntExpr is the type of integer expression (commonly list indexing)
	NodeIntExpr

	// NodeVarExpr is the type of variable expressions.
	NodeVarExpr

	// NodeListExpr is the type of list expression.
	NodeListExpr

	// NodeIndexExpr is the type of indexing expressions.
	NodeIndexExpr

	// NodeConcatExpr is the type of concatenation expressions.
	NodeConcatExpr

	// NodeString are nodes for argument strings
	NodeString

	// NodeRfork is the type for rfork statement
	NodeRfork

	// NodeRforkFlags are nodes for rfork flags
	NodeRforkFlags

	// NodeIf is the type for if statements
	NodeIf

	// NodeComment are nodes for comment
	NodeComment

	// NodeFnDecl is the type for function declaration
	NodeFnDecl

	// NodeReturn is the type for return statement
	NodeReturn

	// NodeBindFn is the type for bindfn statements
	NodeBindFn

	// NodeDump is the type for dump statements
	NodeDump

	// NodeFor is the type for "for" statements
	NodeFor
)

func (NodeType) IsExecutable

func (t NodeType) IsExecutable() bool

IsExecutable returns if the node is executable

func (NodeType) IsExpr

func (t NodeType) IsExpr() bool

IsExpr returns if the node is an expression.

func (NodeType) String

func (i NodeType) String() string

func (NodeType) Type

func (t NodeType) Type() NodeType

Type returns the type of the node

type PipeNode

type PipeNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

PipeNode represents the node for a command pipeline.

func NewPipeNode

func NewPipeNode(info token.FileInfo, multi bool) *PipeNode

NewPipeNode creates a new command pipeline

func (*PipeNode) AddCmd

func (n *PipeNode) AddCmd(c *CommandNode)

AddCmd add another command to end of the pipeline

func (*PipeNode) Commands

func (n *PipeNode) Commands() []*CommandNode

Commands returns the list of pipeline commands

func (*PipeNode) IsEqual

func (n *PipeNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*PipeNode) IsMulti

func (n *PipeNode) IsMulti() bool

func (*PipeNode) SetMulti

func (n *PipeNode) SetMulti(b bool)

func (*PipeNode) String

func (n *PipeNode) String() string

type RedirMap

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

RedirMap is the map of file descriptors of the redirection

type RedirectNode

type RedirectNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

RedirectNode represents the output redirection part of a command

func NewRedirectNode

func NewRedirectNode(info token.FileInfo) *RedirectNode

NewRedirectNode creates a new redirection node for commands

func (*RedirectNode) IsEqual

func (r *RedirectNode) IsEqual(other Node) bool

IsEqual return if it is equal to the other node.

func (*RedirectNode) LeftFD

func (r *RedirectNode) LeftFD() int

LeftFD return the lhs of the redirection map.

func (*RedirectNode) Location

func (r *RedirectNode) Location() Expr

Location return the location of the redirection.

func (*RedirectNode) RightFD

func (r *RedirectNode) RightFD() int

RightFD return the rhs of the redirection map.

func (*RedirectNode) SetLocation

func (r *RedirectNode) SetLocation(s Expr)

SetLocation of the output

func (*RedirectNode) SetMap

func (r *RedirectNode) SetMap(lfd int, rfd int)

SetMap sets the redirection map. Eg.: [2=1]

func (*RedirectNode) String

func (r *RedirectNode) String() string

String returns the string representation of redirect

type ReturnNode

type ReturnNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A ReturnNode represents the "return" keyword.

func NewReturnNode

func NewReturnNode(info token.FileInfo) *ReturnNode

NewReturnNode create a return statement

func (*ReturnNode) IsEqual

func (n *ReturnNode) IsEqual(other Node) bool

func (*ReturnNode) Return

func (n *ReturnNode) Return() Expr

Return returns the argument being returned

func (*ReturnNode) SetReturn

func (n *ReturnNode) SetReturn(a Expr)

SetReturn set the arguments to return

func (*ReturnNode) String

func (n *ReturnNode) String() string

String returns the string representation of return statement

type RforkNode

type RforkNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

RforkNode is a builtin node for rfork

func NewRforkNode

func NewRforkNode(info token.FileInfo) *RforkNode

NewRforkNode creates a new node for rfork

func (*RforkNode) Arg

func (n *RforkNode) Arg() *StringExpr

Arg return the string argument of the rfork.

func (*RforkNode) IsEqual

func (n *RforkNode) IsEqual(other Node) bool

func (*RforkNode) SetFlags

func (n *RforkNode) SetFlags(a *StringExpr)

SetFlags sets the rfork flags

func (*RforkNode) SetTree

func (n *RforkNode) SetTree(t *Tree)

SetTree set the body of the rfork block.

func (*RforkNode) String

func (n *RforkNode) String() string

String returns the string representation of rfork statement

func (*RforkNode) Tree

func (n *RforkNode) Tree() *Tree

Tree returns the child tree of node

type SetenvNode

type SetenvNode struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

A SetenvNode represents the node for a "setenv" keyword.

func NewSetenvNode

func NewSetenvNode(info token.FileInfo, name string, assign Node) (*SetenvNode, error)

NewSetenvNode creates a new assignment node

func (*SetenvNode) Assignment added in v0.2.1

func (n *SetenvNode) Assignment() Node

Assignment returns the setenv assignment (if any)

func (*SetenvNode) Identifier

func (n *SetenvNode) Identifier() string

Identifier returns the environment name.

func (*SetenvNode) IsEqual

func (n *SetenvNode) IsEqual(other Node) bool

IsEqual returns if it is equal to the other node.

func (*SetenvNode) String

func (n *SetenvNode) String() string

String returns the string representation of assignment

type StringExpr

type StringExpr struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

StringExpr is a string argument

func NewStringExpr

func NewStringExpr(info token.FileInfo, value string, quoted bool) *StringExpr

NewArgString creates a new string argument

func (*StringExpr) IsEqual

func (s *StringExpr) IsEqual(other Node) bool

func (*StringExpr) SetValue

func (s *StringExpr) SetValue(a string)

func (*StringExpr) String

func (s *StringExpr) String() string

func (*StringExpr) Value

func (s *StringExpr) Value() string

Value returns the argument string value

type Tree

type Tree struct {
	Name string
	Root *BlockNode // top-level root of the tree.
}

Tree is the AST

func NewTree

func NewTree(name string) *Tree

NewTree creates a new AST tree

func (*Tree) IsEqual

func (t *Tree) IsEqual(other *Tree) bool

func (*Tree) String

func (tree *Tree) String() string

type VarExpr

type VarExpr struct {
	NodeType
	token.FileInfo
	// contains filtered or unexported fields
}

VarExpr is a variable argument

func NewVarExpr

func NewVarExpr(info token.FileInfo, name string) *VarExpr

func (*VarExpr) IsEqual

func (v *VarExpr) IsEqual(other Node) bool

func (*VarExpr) Name

func (v *VarExpr) Name() string

func (*VarExpr) String

func (v *VarExpr) String() string

Jump to

Keyboard shortcuts

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