Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package ast declares the types used to represent syntax trees for batch scripts. All node types implement the Node interface.
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 ¶
- func Print(node Node)
 - func String(node Node) string
 - func Walk(v Visitor, node Node)
 - func Write(node Node, w io.Writer)
 - type AssignStmt
 - type BinaryExpr
 - type BlockStmt
 - type CallExpr
 - type CallStmt
 - type CmdExpr
 - type Comment
 - type CommentGroup
 - type DblQuote
 - type Expr
 - type ExprStmt
 - type File
 - type ForStmt
 - type FuncDecl
 - type GotoStmt
 - type IfStmt
 - type LabelStmt
 - type Lit
 - type Node
 - type SglQuote
 - type Stmt
 - type UnaryExpr
 - type Visitor
 - type Word
 
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AssignStmt ¶
type AssignStmt struct {
	Docs   *CommentGroup // associated documentation; or nil
	Set    token.Pos     // position of "set" keyword
	Opt    Expr          // optional expression
	Lhs    Expr          // left-hand side of assignment
	Assign token.Pos     // position of "="
	Rhs    Expr          // right-hand side of assignment
}
    An AssignStmt node represents an assignment statement. set variable = value
func AssignStatement ¶ added in v0.2.0
func AssignStatement(lhs, rhs Expr) *AssignStmt
func (*AssignStmt) End ¶
func (s *AssignStmt) End() token.Pos
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() token.Pos
type BinaryExpr ¶
type BinaryExpr struct {
	X  Expr        // left operand
	Op token.Token // operator
	Y  Expr        // right operand
}
    A BinaryExpr node represents a binary expression. Binary expressions include operators like ==, !=, <, >, etc.
func (*BinaryExpr) End ¶
func (b *BinaryExpr) End() token.Pos
func (*BinaryExpr) Pos ¶
func (b *BinaryExpr) Pos() token.Pos
type BlockStmt ¶
type BlockStmt struct {
	List []Stmt // list of statements
}
    A BlockStmt node represents a block of statements.
type CallExpr ¶
A CallExpr node represents a function call expression. Function calls in batch scripts
type CallStmt ¶
type CallStmt struct {
	Docs   *CommentGroup // associated documentation; or nil
	Call   token.Pos     // position of "call" keyword
	Colon  token.Pos     // position of ":"
	Name   string        // name of the function to call
	Recv   []Expr        // arguments to the function
	IsFile bool          // whether the function is a file
}
    A CallStmt node represents a call statement. call :label arguments
func CallStatement ¶ added in v0.2.0
type CmdExpr ¶ added in v0.2.0
type CmdExpr struct {
	Docs *CommentGroup // associated documentation; or nil
	Name Expr          // command name
	Recv []Expr        // command arguments
}
    A CmdExpr node represents a command statement. Command expressions represent executable commands in batch scripts
func CmdExpression ¶ added in v0.2.0
type Comment ¶
type Comment struct {
	TokPos token.Pos   // position of comment token
	Tok    token.Token // token.DOUBLE_COLON | token.REM
	Text   string      // comment text
}
    A Comment node represents a single comment. Comments in batch scripts start with :: or REM
type CommentGroup ¶
type CommentGroup struct {
	Comments []*Comment // list of comments
}
    A CommentGroup represents a sequence of comments. Comment groups are used to associate documentation with AST nodes
func (*CommentGroup) End ¶
func (c *CommentGroup) End() token.Pos
func (*CommentGroup) Pos ¶
func (c *CommentGroup) Pos() token.Pos
type DblQuote ¶
type DblQuote struct {
	DelayedExpansion bool      // whether to use delayed expansion (!var!)
	Left             token.Pos // position of "%"
	Val              Expr      // quoted expression
	Right            token.Pos // position of "%"
}
    A DblQuote node represents a double quote expression. Double quotes are used for variable expansion in batch scripts
func DoubleQuote ¶ added in v0.2.0
type Expr ¶
type Expr interface {
	Node
	// contains filtered or unexported methods
}
    Expr represents an expression node in the AST. All expression types implement the Expr interface.
type ExprStmt ¶
type ExprStmt struct {
	Docs *CommentGroup // associated documentation; or nil
	X    Expr          // expression
}
    An ExprStmt node represents a (stand-alone) expression in a statement list.
type File ¶
type File struct {
	Docs  []*CommentGroup // list of documentation comments
	Stmts []Stmt          // list of statements
}
    A File node represents a batch script file. Files contain the complete AST for a batch script
type ForStmt ¶
type ForStmt struct {
	Docs   *CommentGroup // associated documentation; or nil
	For    token.Pos     // position of "for" keyword
	X      Expr          // variable to iterate over
	In     token.Pos     // position of "in" keyword
	List   Expr          // list to iterate over
	Do     token.Pos     // position of "do" keyword
	Lparen token.Pos     // position of "("
	Body   *BlockStmt    // body of the for statement
	Rparen token.Pos     // position of ")"
}
    A ForStmt node represents a for statement. for variable in list do ( body )
type FuncDecl ¶
type FuncDecl struct {
	Docs  *CommentGroup // associated documentation; or nil
	Colon token.Pos     // position of ":"
	Name  string        // function name
	Body  *BlockStmt    // function body
}
    A FuncDecl node represents a function declaration. :label body
type GotoStmt ¶
type GotoStmt struct {
	Docs  *CommentGroup // associated documentation; or nil
	GoTo  token.Pos     // position of "goto" keyword
	Colon token.Pos     // position of ":"
	Label string        // label to jump to
}
    A GotoStmt node represents a goto statement. goto :label
type IfStmt ¶
type IfStmt struct {
	Docs   *CommentGroup // associated documentation; or nil
	If     token.Pos     // position of "if" keyword
	Cond   Expr          // condition expression
	Lparen token.Pos     // position of "("
	Body   Stmt          // body of the if statement
	Rparen token.Pos     // position of ")"
	Else   Stmt          // else branch; or nil
}
    An IfStmt node represents an if statement. if condition ( body ) else body
type LabelStmt ¶
type LabelStmt struct {
	Docs  *CommentGroup // associated documentation; or nil
	Colon token.Pos     // position of ":"
	Name  string        // label name
}
    A LabelStmt node represents a label statement. :label
type Lit ¶
A Lit node represents a literal expression. Literals include strings, numbers, and other constant values
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
}
    Node represents a node in the AST. All node types implement the Node interface.
type SglQuote ¶
A SglQuote node represents a single quote expression. Single quotes are used for literal strings in batch scripts
func SingleQuote ¶ added in v0.2.0
type Stmt ¶
type Stmt interface {
	Node
	// contains filtered or unexported methods
}
    Stmt represents a statement node in the AST. All statement types implement the Stmt interface.
type UnaryExpr ¶
A UnaryExpr node represents a unary expression. Unary expressions include operators like ! (logical NOT)
type Visitor ¶ added in v0.2.0
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).