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 VBScript.

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

func String(node Node) string

func Walk

func Walk(v Visitor, node Node)

Types

type AssignStmt

type AssignStmt struct {
	Doc    *CommentGroup // associated documentation; or nil
	Lhs    Expr          // left hand side
	Assign token.Pos     // position of "="
	Rhs    Expr          // right hand side
}

An AssignStmt node represents an assignment 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      // literal value
	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 {
	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 (*BinaryExpr) Pos

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

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

type BlockStmt

type BlockStmt struct {
	List []Stmt // statement list
}

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 CallExpr

type CallExpr struct {
	Func   Expr
	Lparen token.Pos // position of "("
	Recv   []Expr
	Rparen token.Pos // position of ")"
}

A CallExpr node represents an expression followed by an argument list.

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 CallStmt

type CallStmt struct {
	Call token.Pos // position of "Call"
	Name *Ident    // procedure name
	Recv []Expr    // arguments
}

A CallStmt node represents a call statement.

func (*CallStmt) End

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

func (*CallStmt) Pos

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

type CaseStmt

type CaseStmt struct {
	Doc  *CommentGroup // associated documentation; or nil
	Case token.Pos     // position of "Case"
	Cond Expr          // case condition
	Body *BlockStmt    // case body
}

A CaseStmt node represents a case statement.

type ClassDecl

type ClassDecl struct {
	Doc    *CommentGroup // associated documentation; or nil
	Mod    token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos token.Pos     // position of Mod
	Class  token.Pos     // position of "Class"
	Name   *Ident        // class name
	// Stmts contains all statements in the class body:
	// dim, func, member, property, assign statements
	Stmts    []Stmt    // class body statements
	EndClass token.Pos // position of "End Class"
}

A ClassDecl node represents a class declaration.

func (*ClassDecl) End

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

func (*ClassDecl) Pos

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

type CmdExpr

type CmdExpr struct {
	Cmd  Expr
	Recv []Expr
}

A CmdExpr node represents a command expression.

func (*CmdExpr) End

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

func (*CmdExpr) Pos

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

func (*CmdExpr) String

func (e *CmdExpr) String() string

type Comment

type Comment struct {
	TokPos token.Pos   // position of comment token
	Tok    token.Token // ' or Rem
	Text   string      // comment text (excluding '\n' for line comments)
}

A Comment represents a single comment.

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 // len(List) > 0
}

A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.

func (*CommentGroup) End

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

func (*CommentGroup) Pos

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

type ConstStmt

type ConstStmt struct {
	Doc         *CommentGroup // associated documentation; or nil
	ModifierPos token.Pos     // position of Modifier
	Modifier    token.Token   // Token.PUBLIC | PRIVATE
	Const       token.Pos     // position of "Const"
	Lhs         Expr          // left hand side
	Assign      token.Pos     // position of "="
	Rhs         Expr          // right hand side
}

A ConstStmt node represents a constant declaration.

func (*ConstStmt) End

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

func (*ConstStmt) Pos

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

type DimDecl

type DimDecl struct {
	Doc   *CommentGroup // associated documentation; or nil
	Dim   token.Pos     // position of "Dim"
	List  []Expr        // variable list
	Colon token.Pos     // position of ":"
	Set   *SetStmt      // optional initial value
}

A DimDecl node represents a variable declaration.

func (*DimDecl) End

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

func (*DimDecl) Pos

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

type DoLoopStmt

type DoLoopStmt struct {
	Doc    *CommentGroup // associated documentation; or nil
	Do     token.Pos     // position of "Do"
	Pre    bool          // whether condition is before loop
	Tok    token.Token   // Token.WHILE | Token.UNTIL
	TokPos token.Pos     // position of Tok
	Cond   Expr          // condition expression
	Body   *BlockStmt    // do body
	Loop   token.Pos     // position of "Loop"
}

A DoLoopStmt node represents a Do..Loop statement.

func (*DoLoopStmt) End

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

func (*DoLoopStmt) Pos

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

type EraseStmt

type EraseStmt struct {
	Doc   *CommentGroup // associated documentation; or nil
	Erase token.Pos     // position of "Erase"
	X     Expr          // array expression
}

An EraseStmt node represents an erase statement.

func (*EraseStmt) End

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

func (*EraseStmt) Pos

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

type ExecuteStmt

type ExecuteStmt struct {
	Doc       *CommentGroup // associated documentation; or nil
	Execute   token.Pos     // position of "Execute"
	Statement string        // statement to execute
}

An ExecuteStmt node represents an execute statement.

func (*ExecuteStmt) End

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

func (*ExecuteStmt) Pos

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

type ExitStmt

type ExitStmt struct {
	Doc  *CommentGroup // associated documentation; or nil
	Exit token.Pos     // position of "Exit"
	Tok  token.Token   // Token.Do | For | Function | Property | Sub
}

An ExitStmt node represents an exit statement.

func (*ExitStmt) End

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

func (*ExitStmt) Pos

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

type Expr

type Expr interface {
	Node

	String() string // string representation of the expression
	// contains filtered or unexported methods
}

All expression nodes implement the Expr interface.

type ExprStmt

type ExprStmt struct {
	Doc *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 Field

type Field struct {
	TokPos token.Pos
	Tok    token.Token // Token.BYVAL | Token.BYREF
	Name   *Ident
}

func (*Field) End

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

func (*Field) Pos

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

func (*Field) String

func (f *Field) String() string

type File

type File struct {
	Doc []*CommentGroup

	Stmts []Stmt
}

A File node represents a VBScript source file.

func (*File) End

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

func (*File) Pos

func (*File) Pos() token.Pos

type ForEachStmt

type ForEachStmt struct {
	Doc   *CommentGroup // associated documentation; or nil
	For   token.Pos     // position of "For"
	Each  token.Pos     // position of "Each"
	Elem  Expr          // element expression
	In    token.Pos     // position of "In"
	Group Expr          // group expression
	Body  *BlockStmt    // for body
	Next  token.Pos     // position of "Next"
	Stmt  Stmt          // next statement; or nil
}

A ForEachStmt node represents a For..Each statement.

func (*ForEachStmt) End

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

func (*ForEachStmt) Pos

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

type ForNextStmt

type ForNextStmt struct {
	Doc     *CommentGroup // associated documentation; or nil
	For     token.Pos     // position of "For"
	Start   Expr          // start expression
	To      token.Pos     // position of "To"
	End_    Expr          // end expression
	StepPos token.Pos     // position of "Step"
	Step    Expr          // step expression; or nil
	Body    *BlockStmt    // for body
	Next    token.Pos     // position of "Next"
}

A ForNextStmt node represents a For..Next statement.

func (*ForNextStmt) End

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

func (*ForNextStmt) Pos

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

type FuncDecl

type FuncDecl struct {
	Doc    *CommentGroup // associated documentation; or nil
	Mod    token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos token.Pos     // position of Mod
	// Default is used only with the Public keyword in a Class block
	// to indicate that the Function procedure is the default method for the class.
	Default  token.Pos  // position of "Default"
	Function token.Pos  // position of "Function"
	Name     *Ident     // function name
	Recv     []*Field   // receiver parameters; or nil
	Body     *BlockStmt // function body
	EndFunc  token.Pos  // position of "End Function"
}

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 // identifier position
	Name    string    // identifier name
}

An Ident node represents an identifier.

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 {
	Doc   *CommentGroup // associated documentation; or nil
	If    token.Pos     // position of "If"
	Cond  Expr          // condition expression
	Then  token.Pos     // position of "Then"
	Body  *BlockStmt    // if body
	Else  Stmt          // elseif or else
	EndIf token.Pos     // position of "End If"
}

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 IndexExpr

type IndexExpr struct {
	X      Expr      // expression
	Lparen token.Pos // position of "("
	Index  Expr      // index expression
	Rparen token.Pos // position of ")"
}

An IndexExpr node represents an expression followed by an index.

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 IndexListExpr

type IndexListExpr struct {
	X       Expr      // expression
	Lparen  token.Pos // position of "("
	Indices []Expr    // index expressions
	Rparen  token.Pos // position of ")"
}

An IndexListExpr node represents an expression followed by multiple indices.

func (*IndexListExpr) End

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

func (*IndexListExpr) Pos

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

func (*IndexListExpr) String

func (e *IndexListExpr) String() string

type NewExpr

type NewExpr struct {
	New token.Pos // position of "New"
	X   Expr
}

func (*NewExpr) End

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

func (*NewExpr) Pos

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

func (*NewExpr) String

func (e *NewExpr) String() string

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 OnErrorGoto

type OnErrorGoto struct {
	GoTo token.Pos // position of "Goto"
	Zero token.Pos // position of "0"
}

An OnErrorGoto node represents a goto 0 statement.

type OnErrorResume

type OnErrorResume struct {
	Resume token.Pos // position of "Resume"
	Next   token.Pos // position of "Next"
}

An OnErrorResume node represents a resume next statement.

type OnErrorStmt

type OnErrorStmt struct {
	Doc            *CommentGroup // associated documentation; or nil
	On             token.Pos     // position of "On"
	Error          token.Pos     // position of "Error"
	*OnErrorResume               // resume next; or nil
	*OnErrorGoto                 // goto 0; or nil
}

An OnErrorStmt node represents an on error statement.

func (*OnErrorStmt) End

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

func (*OnErrorStmt) Pos

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

type OptionStmt

type OptionStmt struct {
	Doc      *CommentGroup // associated documentation; or nil
	Option   token.Pos     // position of "Option"
	Explicit token.Pos     // position of "Explicit"
}

An OptionStmt node represents an option statement.

func (*OptionStmt) End

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

func (*OptionStmt) Pos

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

type PrivateStmt

type PrivateStmt struct {
	Doc     *CommentGroup // associated documentation; or nil
	Private token.Pos     // position of "Private"
	List    []Expr        // variable list
}

A PrivateStmt node represents a private statement.

func (*PrivateStmt) End

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

func (*PrivateStmt) Pos

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

type PropertyGetStmt

type PropertyGetStmt struct {
	Doc         *CommentGroup // associated documentation; or nil
	Mod         token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos      token.Pos     // position of Mod
	Property    token.Pos     // position of "Property"
	Get         token.Pos     // position of "Get"
	Name        *Ident        // property name
	LParen      token.Pos     // position of "("
	Recv        []*Field      // receiver parameters; or nil
	RParen      token.Pos     // position of ")"
	Body        *BlockStmt    // property body
	EndProverty token.Pos     // position of "End Property"
}

A PropertyGetStmt node represents a property get declaration.

func (*PropertyGetStmt) End

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

func (*PropertyGetStmt) Pos

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

type PropertyLetStmt

type PropertyLetStmt struct {
	Doc         *CommentGroup // associated documentation; or nil
	Mod         token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos      token.Pos     // position of Mod
	Property    token.Pos     // position of "Property"
	Let         token.Pos     // position of "Let"
	Name        *Ident        // property name
	LParen      token.Pos     // position of "("
	Recv        []*Field      // receiver parameters; or nil
	RParen      token.Pos     // position of ")"
	Body        *BlockStmt    // property body
	EndProverty token.Pos     // position of "End Property"
}

A PropertyLetStmt node represents a property let declaration.

func (*PropertyLetStmt) End

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

func (*PropertyLetStmt) Pos

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

type PropertySetStmt

type PropertySetStmt struct {
	Doc         *CommentGroup // associated documentation; or nil
	Mod         token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos      token.Pos     // position of Mod
	Property    token.Pos     // position of "Property"
	Set         token.Pos     // position of "Set"
	Name        *Ident        // property name
	LParen      token.Pos     // position of "("
	Recv        []*Field      // receiver parameters; or nil
	RParen      token.Pos     // position of ")"
	Body        *BlockStmt    // property body
	EndProverty token.Pos     // position of "End Property"
}

A PropertySetStmt node represents a property set declaration.

func (*PropertySetStmt) End

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

func (*PropertySetStmt) Pos

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

type PropertyStmt

type PropertyStmt struct {
	Doc         *CommentGroup // associated documentation; or nil
	Mod         token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos      token.Pos     // position of Mod
	Property    token.Pos     // position of "Property"
	Name        *Ident        // property name
	LParen      token.Pos     // position of "("
	Recv        []*Field      // receiver parameters; or nil
	RParen      token.Pos     // position of ")"
	Body        *BlockStmt    // property body
	EndProverty token.Pos     // position of "End Property"
}

A PropertyStmt node represents a property declaration.

type PublicStmt

type PublicStmt struct {
	Doc    *CommentGroup // associated documentation; or nil
	Public token.Pos     // position of "Public"
	List   []Expr        // variable list
}

A PublicStmt node represents a public statement.

func (*PublicStmt) End

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

func (*PublicStmt) Pos

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

type RandomizeStmt

type RandomizeStmt struct {
	Doc       *CommentGroup // associated documentation; or nil
	Randomize token.Pos     // position of "Randomize"
}

A RandomizeStmt node represents a randomize statement.

func (*RandomizeStmt) End

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

func (*RandomizeStmt) Pos

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

type ReDimDecl

type ReDimDecl struct {
	Doc      *CommentGroup // associated documentation; or nil
	ReDim    token.Pos     // position of "ReDim"
	Preserve token.Pos     // position of "Preserve"
	List     []Expr        // variable list
}

A ReDimDecl node represents a variable redimension declaration.

func (*ReDimDecl) End

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

func (*ReDimDecl) Pos

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

type SelectStmt

type SelectStmt struct {
	Doc       *CommentGroup // associated documentation; or nil
	Select    token.Pos     // position of "Select"
	Var       Expr          // select variable
	Cases     []*CaseStmt   // case statements
	Else      *CaseStmt     // else case; or nil
	EndSelect token.Pos     // position of "End Select"
}

A SelectStmt node represents a select statement.

func (*SelectStmt) End

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

func (*SelectStmt) Pos

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

type SelectorExpr

type SelectorExpr struct {
	X   Expr // expression
	Sel Expr // field selector
}

A SelectorExpr node represents an expression followed by a selector.

func (*SelectorExpr) End

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

func (*SelectorExpr) Pos

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

func (*SelectorExpr) String

func (e *SelectorExpr) String() string

type SetStmt

type SetStmt struct {
	Doc    *CommentGroup // associated documentation; or nil
	Set    token.Pos     // position of "Set"
	Lhs    Expr          // left hand side
	Assign token.Pos     // position of "="
	Rhs    Expr          // right hand side
}

A SetStmt node represents a set statement.

func (*SetStmt) End

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

func (*SetStmt) Pos

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

type Stmt

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

All statement nodes implement the Stmt interface.

type StopStmt

type StopStmt struct {
	Doc  *CommentGroup // associated documentation; or nil
	Stop token.Pos     // position of "Stop"
}

A StopStmt node represents a stop statement.

func (*StopStmt) End

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

func (*StopStmt) Pos

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

type SubDecl

type SubDecl struct {
	Doc    *CommentGroup // associated documentation; or nil
	Mod    token.Token   // modifier token (PUBLIC, PRIVATE)
	ModPos token.Pos     // position of Mod
	Sub    token.Pos     // position of "Sub"
	Name   *Ident        // sub name
	Recv   []*Field      // receiver parameters; or nil
	Body   *BlockStmt    // sub body
	EndSub token.Pos     // position of "End Sub"
}

A SubDecl node represents a sub declaration.

func (*SubDecl) End

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

func (*SubDecl) Pos

func (d *SubDecl) 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 WhileWendStmt

type WhileWendStmt struct {
	Doc   *CommentGroup // associated documentation; or nil
	While token.Pos     // position of "While"
	Cond  Expr          // condition expression
	Body  *BlockStmt    // while body
	Wend  token.Pos     // position of "Wend"
}

A WhileWendStmt node represents a While..Wend statement.

func (*WhileWendStmt) End

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

func (*WhileWendStmt) Pos

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

type WithStmt

type WithStmt struct {
	Doc     *CommentGroup // associated documentation; or nil
	With    token.Pos     // position of "With"
	Cond    Expr          // condition expression
	Body    *BlockStmt    // with body
	EndWith token.Pos     // position of "End With"
}

A WithStmt node represents a with statement.

func (*WithStmt) End

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

func (*WithStmt) Pos

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

Jump to

Keyboard shortcuts

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