ast

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 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 ExprListStr

func ExprListStr(list []Expr) string

func ExprStr

func ExprStr(e Expr) string

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

type ArithExp

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

Arithmetic Expansion: $(())

An ArithExp node represents an arithmetic expansion expression.

func (*ArithExp) End

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

func (*ArithExp) Pos

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

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  bool
	Lhs    Expr
	Assign token.Pos // position of "="
	Rhs    Expr
}

A AssignStmt node represents a assign statement.

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 // Token.Empty | Token.Null | Token.Boolean | Token.Byte | Token.Integer | Token.Currency | Token.Long | Token.Single | Token.Double | Token.Date | Token.String | Token.Object | Token.Error
	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

type BasicTestExpr

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

[ ]

A BasicTestExpr node represents a basic test command expression.

func (*BasicTestExpr) End

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

func (*BasicTestExpr) Pos

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

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 }

type BlockStmt

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

A BlockStmt node represents a block statement.

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"
}

A BreakStmt node represents a break statement.

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

type CaseClause

type CaseClause struct {
	Case  token.Pos // position of "case"
	Conds []Expr
	Body  *BlockStmt
}

type CaseConversionExp

type CaseConversionExp struct {
	FirstChar bool
	ToUpper   bool
}

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

type Comment

type Comment struct {
	Hash token.Pos // position of "#"
	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"
}

A ContinueStmt node represents a continue statement.

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
}

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
	// contains filtered or unexported methods
}

type ExprStmt

type ExprStmt struct {
	X Expr
}

An ExprStmt node represents an expr statement.

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

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 ForeachStmt

type ForeachStmt struct {
	For    token.Pos // position of "for"
	Elem   Expr
	In     token.Pos // position of "in"
	Group  []Expr
	Body   *BlockStmt
	EndPos token.Pos // position of "end"
}

A ForeachStmt node represents a foreach statement.

func (*ForeachStmt) End

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

func (*ForeachStmt) Pos

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

type FuncDecl

type FuncDecl struct {
	Function token.Pos // position of "function"
	Name     *Ident
	Recv     []Expr
	Body     *BlockStmt
	EndPos   token.Pos // position of "end"
}

A FuncDecl node represents a function declaration.

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

type IfStmt

type IfStmt struct {
	If     token.Pos // position of "if"
	Cond   Expr
	Body   *BlockStmt
	Elif   []*IfStmt
	Else   *BlockStmt
	EndPos token.Pos // position of "end"
}

An IfStmt node represents an if statement.

func (*IfStmt) End

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

func (*IfStmt) Pos

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

type LengthExp

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

type Node

type Node interface {
	Pos() token.Pos
	End() token.Pos
}

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 ParamExp

type ParamExp 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 ParamExp node represents an parameter expansion expression.

func (*ParamExp) End

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

func (*ParamExp) Pos

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

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

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
}

A ReturnStmt node represents a return statement.

func (*ReturnStmt) End

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

func (*ReturnStmt) Pos

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

type Stmt

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

type SubstringExp

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

type SwitchStmt

type SwitchStmt struct {
	Switch token.Pos // position of "switch"
	Lparen token.Pos // position of "("
	Var    Expr
	Rparen token.Pos // position of ")"
	Cases  []*CaseClause
	Else   *BlockStmt
	EndPos token.Pos // position of "end"
}

A SwitchStmt node represents a switch statement.

func (*SwitchStmt) End

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

func (*SwitchStmt) Pos

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

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
	Body   *BlockStmt
	EndPos token.Pos // position of "end"
}

A WhileStmt node represents a while statement.

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