ast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	// The expansion is a string that is the value of parameter
	// with lowercase alphabetic characters converted to uppercase.
	ExpOperatorU = "U"

	// The expansion is a string that is the value of parameter
	// with the first character converted to uppercase,
	// if it is alphabetic.
	ExpOperatoru = "u"

	// The expansion is a string that is the value of parameter
	// with uppercase alphabetic characters converted to lowercase.
	ExpOperatorL = "L"

	// The expansion is a string that is the value of parameter quoted
	// in a format that can be reused as input.
	ExpOperatorQ = "Q"

	// The expansion is a string that is the value of parameter
	// with backslash escape sequences expanded as with the $'…' quoting mechanism.
	ExpOperatorE = "E"

	// The expansion is a string that is the result of expanding the value of parameter
	// as if it were a prompt string (see Controlling the Prompt).
	ExpOperatorP = "P"

	// The expansion is a string in the form of an assignment statement or declare command that,
	// if evaluated, will recreate parameter with its attributes and value.
	ExpOperatorA = "A"

	// Produces a possibly-quoted version of the value of parameter,
	// except that it prints the values of indexed and
	// associative arrays as a sequence of quoted key-value pairs (see Arrays).
	ExpOperatorK = "K"

	// The expansion is a string consisting of flag values representing parameter’s attributes.
	ExpOperatora = "a"

	// Like the ‘K’ transformation, but expands the keys and values of indexed and
	// associative arrays to separate words after word splitting.
	ExpOperatork = "k"
)

Variables

This section is empty.

Functions

func Inspect

func Inspect(node Node, f func(Node) bool)

func Print

func Print(node Node)

func String

func String(node Node) string

func Walk

func Walk(v Visitor, node Node)

Types

type ArithEvalExpr

type ArithEvalExpr struct {
	Lparen token.Pos // position of "(("
	X      Expr
	Rparen token.Pos // position of "))"
}

(( ))

An ArithEvalExpr node represents an arithmetic evaluation expression.

func (*ArithEvalExpr) End

func (x *ArithEvalExpr) End() token.Pos

func (*ArithEvalExpr) Pos

func (x *ArithEvalExpr) Pos() token.Pos

func (*ArithEvalExpr) String

func (e *ArithEvalExpr) String() string

type ArithExpr

type ArithExpr struct {
	Dollar token.Pos // position of "$"
	Lparen token.Pos // position of "(("
	X      Expr
	Rparen token.Pos // position of "))"
}

Arithmetic Expansion: $(())

An ArithExpr node represents an arithmetic expansion expression.

func (*ArithExpr) End

func (x *ArithExpr) End() token.Pos

func (*ArithExpr) Pos

func (x *ArithExpr) Pos() token.Pos

func (*ArithExpr) String

func (e *ArithExpr) String() string

type ArrExpr

type ArrExpr struct {
	Lparen token.Pos // position of "("
	Vars   []Expr
	Rparen token.Pos // position of ")"
}

(VAR1 VAR2 ... VARN)

func (*ArrExpr) End

func (x *ArrExpr) End() token.Pos

func (*ArrExpr) Pos

func (x *ArrExpr) Pos() token.Pos

func (*ArrExpr) String

func (e *ArrExpr) String() string

type ArrayIndexExp

type ArrayIndexExp struct {
	Bitnot   token.Pos   // position of '!'
	Lbracket token.Pos   // position of '['
	Tok      token.Token // Token.AT or Token.MUL
	TokPos   token.Pos
	Rbracket token.Pos // position of ']'
}

type AssignStmt

type AssignStmt struct {
	Local  token.Pos // position of "local"
	Lhs    Expr
	Assign token.Pos // position of "="
	Rhs    Expr
}

func (*AssignStmt) End

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

func (*AssignStmt) Pos

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

type BasicLit

type BasicLit struct {
	Kind     token.Token
	Value    string
	ValuePos token.Pos // literal position
}

A BasicLit node represents a literal of basic type.

func (*BasicLit) End

func (x *BasicLit) End() token.Pos

func (*BasicLit) Pos

func (x *BasicLit) Pos() token.Pos

func (*BasicLit) String

func (e *BasicLit) String() string

type BinaryExpr

type BinaryExpr struct {
	Compress bool
	X        Expr        // left operand
	OpPos    token.Pos   // position of Op
	Op       token.Token // operator
	Y        Expr        // right operand
}

A BinaryExpr node represents a binary expression.

func (*BinaryExpr) End

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

func (x Word) End() token.Pos { return token.NoPos }

func (*BinaryExpr) Pos

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

func (x Word) Pos() token.Pos { return token.NoPos }

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

type BlockStmt

type BlockStmt struct {
	Tok     token.Token // Token.NONE | Token.LBRACE
	Opening token.Pos
	List    []Stmt
	Closing token.Pos
}

func (*BlockStmt) End

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

func (*BlockStmt) Pos

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

type BreakStmt

type BreakStmt struct {
	Break token.Pos // position of "break"
}

func (*BreakStmt) End

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

func (*BreakStmt) Pos

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

type CallExpr

type CallExpr struct {
	Func *Ident
	Recv []Expr
}

A CallExpr node represents a call expression.

func (*CallExpr) End

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

func (*CallExpr) Pos

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

func (*CallExpr) String

func (e *CallExpr) String() string

type CaseClause

type CaseClause struct {
	Conds  []Expr
	Rparen token.Pos // position of ")"
	Body   *BlockStmt
	Semi   token.Pos // position of ";;"
}

type CaseConversionExp

type CaseConversionExp struct {
	FirstChar bool
	ToUpper   bool
}

type CaseStmt

type CaseStmt struct {
	Case     token.Pos // position of "case"
	X        Expr
	In       token.Pos // position of "in"
	Patterns []*CaseClause
	Else     *BlockStmt
	Esac     token.Pos // position of "esac"
}

func (*CaseStmt) End

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

func (*CaseStmt) Pos

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

type CmdGroup

type CmdGroup struct {
	Lbrace token.Pos // position of "{"
	List   []Stmt
	Rbrace token.Pos // position of "}"
}

Command Grouping: { }

A CmdGroup node represents a command group expression.

type CmdSubst

type CmdSubst struct {
	Dollar  token.Pos
	Tok     token.Token // Token.LPAREN or Token.BACK_QUOTE
	Opening token.Pos
	X       Expr
	Closing token.Pos
}

Command Substitution: $( ) or ` `

A CmdSubst node represents a command substitution expression.

func (*CmdSubst) End

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

func (*CmdSubst) Pos

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

func (*CmdSubst) String

func (e *CmdSubst) String() string

type Comment

type Comment struct {
	Hash token.Pos
	Text string
}

func (*Comment) End

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

func (*Comment) Pos

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

type CommentGroup

type CommentGroup struct {
	List []*Comment
}

func (*CommentGroup) End

func (g *CommentGroup) End() token.Pos

func (*CommentGroup) Pos

func (g *CommentGroup) Pos() token.Pos

type ContinueStmt

type ContinueStmt struct {
	Continue token.Pos // position of "continue"
}

func (*ContinueStmt) End

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

func (*ContinueStmt) Pos

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

type Decl

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

All declaration nodes implement the Decl interface.

type DefaultValAssignExp

type DefaultValAssignExp struct {
	Colon  token.Pos
	Assign token.Pos
	Val    Expr
}

If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.

type DefaultValExp

type DefaultValExp struct {
	Colon token.Pos
	Sub   token.Pos
	Val   Expr
}

If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

type DelPrefix

type DelPrefix struct {
	Longest bool
	Hash    token.Pos // position of "#" or "##"
	Val     Expr
}

type DelSuffix

type DelSuffix struct {
	Longest bool
	Mod     token.Pos // position of "%" or "%%"
	Val     Expr
}

type ExpOperator

type ExpOperator string

type Expr

type Expr interface {
	Node

	String() string
	// contains filtered or unexported methods
}

All expression nodes implement the Expr interface.

type ExprStmt

type ExprStmt struct {
	X Expr
}

func (*ExprStmt) End

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

func (*ExprStmt) Pos

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

type ExtendedTestExpr

type ExtendedTestExpr struct {
	Lbrack token.Pos // position of "[["
	X      Expr
	Rbrack token.Pos // position of "]]"
}

[[ ]]

An ExtendedTestExpr node represents an extended test command expression.

func (*ExtendedTestExpr) End

func (x *ExtendedTestExpr) End() token.Pos

func (*ExtendedTestExpr) Pos

func (x *ExtendedTestExpr) Pos() token.Pos

func (*ExtendedTestExpr) String

func (e *ExtendedTestExpr) String() string

type File

type File struct {
	Doc *CommentGroup

	Stmts []Stmt
	Decls []Decl
}

func (*File) End

func (*File) End() token.Pos

func (*File) Pos

func (*File) Pos() token.Pos

type ForInStmt

type ForInStmt struct {
	For  token.Pos // position of "for"
	Var  Expr
	In   token.Pos // position of "in"
	List Expr
	Semi token.Pos // position of ";"
	Do   token.Pos // position of "do"
	Body *BlockStmt
	Done token.Pos // position of "done"
}

for name [ [in [words …] ] ; ] do commands; done

func (*ForInStmt) End

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

func (*ForInStmt) Pos

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

type ForStmt

type ForStmt struct {
	For    token.Pos // position of "for"
	Lparen token.Pos // position of "(("
	Init   Node
	Semi1  token.Pos // position of ";"
	Cond   Expr
	Semi2  token.Pos // position of ";"
	Post   Node
	Rparen token.Pos // position of "))"
	Do     token.Pos // position of "do"
	Body   *BlockStmt
	Done   token.Pos // position of "done"
}

for (( expr1 ; expr2 ; expr3 )) ; do commands ; done

func (*ForStmt) End

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

func (*ForStmt) Pos

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

type FuncDecl

type FuncDecl struct {
	Function token.Pos
	Name     *Ident
	Lparen   token.Pos
	Rparen   token.Pos
	Body     *BlockStmt
}

func (*FuncDecl) End

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

func (*FuncDecl) Pos

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

type Ident

type Ident struct {
	NamePos token.Pos
	Name    string
}

A Ident node represents an identifier expression.

func (*Ident) End

func (x *Ident) End() token.Pos

func (*Ident) Pos

func (x *Ident) Pos() token.Pos

func (*Ident) String

func (e *Ident) String() string

type IfStmt

type IfStmt struct {
	If   token.Pos // position of "if"
	Cond Expr
	Semi token.Pos // position of ";"
	Then token.Pos // position of "then"
	Body *BlockStmt
	Else Stmt
	Fi   token.Pos // position of "fi"
}

func (*IfStmt) End

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

func (*IfStmt) Pos

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

type IndexExpr

type IndexExpr struct {
	X      Expr
	Lbrack token.Pos // position of "["
	Y      Expr
	Rbrack token.Pos // position of "]"
}

X[Y]

A IndexExpr node represents index expression.

func (*IndexExpr) End

func (x *IndexExpr) End() token.Pos

func (*IndexExpr) Pos

func (x *IndexExpr) Pos() token.Pos

func (*IndexExpr) String

func (e *IndexExpr) String() string

type LengthExp

type LengthExp struct {
	Hash token.Pos // position of "#"
}

type Node

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

All node types implement the Node interface.

type NonNullCheckExp

type NonNullCheckExp struct {
	Colon token.Pos
	Quest token.Pos
	Val   Expr
}

If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted.

type NonNullExp

type NonNullExp struct {
	Colon token.Pos
	Add   token.Pos
	Val   Expr
}

If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

type OperatorExp

type OperatorExp struct {
	At token.Pos // position of "@"
	Op ExpOperator
}

type ParamExpExpr

type ParamExpExpr struct {
	Dollar               token.Pos // position of "$"
	Lbrace               token.Pos // position of "{"
	Var                  Expr
	*DefaultValExp                 // ${var:-val}
	*DefaultValAssignExp           // ${var:=val}
	*NonNullCheckExp               // ${var:?val}
	*NonNullExp                    // ${var:+val}
	*PrefixExp                     // ${!var*}
	*PrefixArrayExp                // ${!var@}
	*ArrayIndexExp                 // ${!var[*]} or ${!var[@]}
	*LengthExp                     // ${#var}
	*DelPrefix                     // ${var#val} or ${var##val}
	*DelSuffix                     // ${var%val} or ${var%%val}
	*SubstringExp                  // ${var:offset} or ${var:offset:length}
	*ReplaceExp                    // ${var/old/new}
	*ReplacePrefixExp              // ${var/#old/new}
	*ReplaceSuffixExp              // ${var/%old/new}
	*CaseConversionExp             // ${var,} or ${var^} or ${var,,} or ${var^^}
	*OperatorExp                   // ${var@op}
	Rbrace               token.Pos // position of "}"
}

Parameter Expandsion: ${}

A ParamExpExpr node represents an parameter expansion expression.

func (*ParamExpExpr) End

func (x *ParamExpExpr) End() token.Pos

func (*ParamExpExpr) Pos

func (x *ParamExpExpr) Pos() token.Pos

func (*ParamExpExpr) String

func (e *ParamExpExpr) String() string

type PrefixArrayExp

type PrefixArrayExp struct {
	Bitnot token.Pos // position of '!'
	At     token.Pos // position of '@'
}

type PrefixExp

type PrefixExp struct {
	Bitnot token.Pos // position of '!'
	Mul    token.Pos // position of '*'
}

type ProcSubst

type ProcSubst struct {
	Tok    token.Token // Token.GT or Token.LT
	TokPos token.Pos
	Lparen token.Pos // position of "("
	X      Expr
	Rparen token.Pos // position of ")"
}

Process Substitution: <( ) or >( )

A ProcSubst node represents a process substitution expression.

func (*ProcSubst) End

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

func (*ProcSubst) Pos

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

func (*ProcSubst) String

func (e *ProcSubst) String() string

type ReplaceExp

type ReplaceExp struct {
	All  bool
	Div1 token.Pos // position of "/" or "//"
	Old  string
	Div2 token.Pos // position of "/"
	New  string
}

type ReplacePrefixExp

type ReplacePrefixExp struct {
	Div1 token.Pos // position of "/"
	Hash token.Pos // position of "#"
	Old  string
	Div2 token.Pos // position of "/"
	New  string
}

type ReplaceSuffixExp

type ReplaceSuffixExp struct {
	Div1 token.Pos // position of "/"
	Mod  token.Pos // position of "%"
	Old  string
	Div2 token.Pos // position of "/"
	New  string
}

type ReturnStmt

type ReturnStmt struct {
	Return token.Pos // position of "return"
	X      Expr
}

func (*ReturnStmt) End

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

func (*ReturnStmt) Pos

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

type SelectStmt

type SelectStmt struct {
	Select token.Pos // position of "select"
	Var    Expr
	In     token.Pos // position of "in"
	List   Expr
	Semi   token.Pos // position of ";"
	Do     token.Pos // position of "do"
	Body   *BlockStmt
	Done   token.Pos // position of "done"
}

func (*SelectStmt) End

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

func (*SelectStmt) Pos

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

type Stmt

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

All statement nodes implement the Stmt interface.

type SubstringExp

type SubstringExp struct {
	Colon1 token.Pos // position of ":"
	Offset int
	Colon2 token.Pos // position of ":"
	Length int
}

type TestExpr

type TestExpr struct {
	Lbrack token.Pos // position of "["
	X      Expr
	Rbrack token.Pos // position of "]"
}

[ ]

A TestExpr node represents a basic test command expression.

func (*TestExpr) End

func (x *TestExpr) End() token.Pos

func (*TestExpr) Pos

func (x *TestExpr) Pos() token.Pos

func (*TestExpr) String

func (e *TestExpr) String() string

type UnaryExpr

type UnaryExpr struct {
	OpPos token.Pos   // position of Op
	Op    token.Token // operator
	X     Expr
}

func (*UnaryExpr) End

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

func (*UnaryExpr) Pos

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

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

type UntilStmt

type UntilStmt struct {
	Until token.Pos // position of "until"
	Cond  Expr
	Semi  token.Pos // position of ";"
	Do    token.Pos // position of "do"
	Body  *BlockStmt
	Done  token.Pos // position of "done"
}

func (*UntilStmt) End

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

func (*UntilStmt) Pos

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

type VarExpExpr

type VarExpExpr struct {
	Dollar token.Pos // position of "$"
	X      Expr
}

Variable Expansion: $a

A VarExpExpr node represents an variable expansion expression.

func (*VarExpExpr) End

func (x *VarExpExpr) End() token.Pos

func (*VarExpExpr) Pos

func (x *VarExpExpr) Pos() token.Pos

func (*VarExpExpr) String

func (e *VarExpExpr) String() string

type Visitor

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

A Visitor's Visit method 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 WhileStmt

type WhileStmt struct {
	While token.Pos // position of "while"
	Cond  Expr
	Semi  token.Pos // position of ";"
	Do    token.Pos // position of "do"
	Body  *BlockStmt
	Done  token.Pos // position of "done"
}

func (*WhileStmt) End

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

func (*WhileStmt) Pos

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

Jump to

Keyboard shortcuts

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