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

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(node Node)

func String added in v0.2.0

func String(node Node) string

func Walk added in v0.2.0

func Walk(v Visitor, node Node)

func Write

func Write(node Node, w io.Writer)

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.

func (*BlockStmt) End

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

func (*BlockStmt) Pos

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

type CallExpr

type CallExpr struct {
	Fun  Expr   // function expression
	Recv []Expr // arguments
}

A CallExpr node represents a function call expression. Function calls in batch scripts

func (*CallExpr) End

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

func (*CallExpr) Pos

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

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

func CallStatement(name string, recv ...Expr) *CallStmt

func (*CallStmt) End

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

func (*CallStmt) Pos

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

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

func CmdExpression(name string, recv ...Expr) *CmdExpr

func (*CmdExpr) End added in v0.2.0

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

func (*CmdExpr) Pos added in v0.2.0

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

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

func (*Comment) End

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

func (*Comment) Pos

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

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

func DoubleQuote(val Expr) *DblQuote

func (*DblQuote) End

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

func (*DblQuote) Pos

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

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.

func (*ExprStmt) End

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

func (*ExprStmt) Pos

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

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

func (*File) End

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

func (*File) Pos

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

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 )

func (*ForStmt) End

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

func (*ForStmt) Pos

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

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

func (*FuncDecl) End

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

End position methods for statements

func (*FuncDecl) Pos

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

Position methods for statements

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

func (*GotoStmt) End

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

func (*GotoStmt) Pos

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

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

func (*IfStmt) End

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

func (*IfStmt) Pos

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

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

func (*LabelStmt) End

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

func (*LabelStmt) Pos

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

type Lit

type Lit struct {
	ValPos token.Pos // position of value
	Val    string    // literal value
}

A Lit node represents a literal expression. Literals include strings, numbers, and other constant values

func Literal added in v0.2.0

func Literal(val string) *Lit

func (*Lit) End

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

func (*Lit) Pos

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

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

type SglQuote struct {
	ModPos token.Pos // position of "%"
	Val    Expr      // quoted expression
}

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

func SingleQuote(val Expr) *SglQuote

func (*SglQuote) End

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

func (*SglQuote) Pos

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

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

type UnaryExpr struct {
	Op token.Token // operator
	X  Expr        // operand
}

A UnaryExpr node represents a unary expression. Unary expressions include operators like ! (logical NOT)

func (*UnaryExpr) End

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

End position methods for expressions

func (*UnaryExpr) Pos

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

Position methods for expressions

type Visitor added in v0.2.0

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 Word

type Word struct {
	Parts []Expr // parts of the word
}

A Word node represents a word expression, which is a sequence of expressions. Words are the basic building blocks of batch commands and arguments.

func Words added in v0.2.0

func Words(parts ...Expr) *Word

func (*Word) End

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

func (*Word) Pos

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

Jump to

Keyboard shortcuts

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