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.
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 Token(tok htok.Token) btok.Token
- func Transpile(opts *config.Huloc, vfs vfs.VFS, basePath string) (map[string]string, error)
- type BashTranspiler
- func (b *BashTranspiler) Convert(node hast.Node) bast.Node
- func (b *BashTranspiler) ConvertArrayLiteralExpr(node *hast.ArrayLiteralExpr) bast.Node
- func (b *BashTranspiler) ConvertAssignStmt(node *hast.AssignStmt) bast.Node
- func (b *BashTranspiler) ConvertBinaryExpr(node *hast.BinaryExpr) bast.Node
- func (b *BashTranspiler) ConvertBlockStmt(node *hast.BlockStmt) bast.Node
- func (b *BashTranspiler) ConvertCallExpr(node *hast.CallExpr) bast.Node
- func (b *BashTranspiler) ConvertClassDecl(node *hast.ClassDecl) bast.Node
- func (b *BashTranspiler) ConvertCmdExpr(node *hast.CmdExpr) bast.Node
- func (b *BashTranspiler) ConvertComment(node *hast.Comment) bast.Node
- func (b *BashTranspiler) ConvertCommentGroup(node *hast.CommentGroup) bast.Node
- func (b *BashTranspiler) ConvertDeclareDecl(node *hast.DeclareDecl) bast.Node
- func (b *BashTranspiler) ConvertDoWhileStmt(node *hast.DoWhileStmt) bast.Node
- func (b *BashTranspiler) ConvertExprStmt(node *hast.ExprStmt) bast.Node
- func (b *BashTranspiler) ConvertFalseLiteral(node *hast.FalseLiteral) bast.Node
- func (b *BashTranspiler) ConvertFile(node *hast.File) bast.Node
- func (b *BashTranspiler) ConvertForInStmt(node *hast.ForInStmt) bast.Node
- func (b *BashTranspiler) ConvertForOfStmt(node *hast.ForeachStmt) bast.Node
- func (b *BashTranspiler) ConvertForStmt(node *hast.ForStmt) bast.Node
- func (b *BashTranspiler) ConvertForeachStmt(node *hast.ForeachStmt) bast.Node
- func (b *BashTranspiler) ConvertFuncDecl(node *hast.FuncDecl) bast.Node
- func (b *BashTranspiler) ConvertIdent(node *hast.Ident) bast.Node
- func (b *BashTranspiler) ConvertIfStmt(node *hast.IfStmt) bast.Node
- func (b *BashTranspiler) ConvertImport(node *hast.Import) bast.Node
- func (b *BashTranspiler) ConvertIncDecExpr(node *hast.IncDecExpr) bast.Node
- func (b *BashTranspiler) ConvertMatchStmt(node *hast.MatchStmt) bast.Node
- func (b *BashTranspiler) ConvertNumericLiteral(node *hast.NumericLiteral) bast.Node
- func (b *BashTranspiler) ConvertObjectLiteralExpr(node *hast.ObjectLiteralExpr) bast.Node
- func (b *BashTranspiler) ConvertParameter(node *hast.Parameter) bast.Node
- func (b *BashTranspiler) ConvertRefExpr(node *hast.RefExpr) bast.Node
- func (b *BashTranspiler) ConvertReturnStmt(node *hast.ReturnStmt) bast.Node
- func (b *BashTranspiler) ConvertSelectExpr(node *hast.SelectExpr) bast.Node
- func (b *BashTranspiler) ConvertStringLiteral(node *hast.StringLiteral) bast.Node
- func (b *BashTranspiler) ConvertTrueLiteral(node *hast.TrueLiteral) bast.Node
- func (b *BashTranspiler) ConvertWhileStmt(node *hast.WhileStmt) bast.Node
- func (b *BashTranspiler) Emit(stmt bast.Stmt)
- func (v *BashTranspiler) Flush() []bast.Stmt
- func (b *BashTranspiler) Transpile(mainFile string) (map[string]string, error)
- type CompileRuleFunc
- type DependencyResolver
- type ExportInfo
- type ExportKind
- type HCRDispatcher
- type ImportInfo
- type ImportKind
- type Module
- type ModuleManager
- type Scope
- type ScopeStack
- type ScopeType
- type Symbol
- type SymbolTable
- func (st *SymbolTable) AddClass(name string, node hast.Node)
- func (st *SymbolTable) AddConstant(name string, node hast.Node)
- func (st *SymbolTable) AddFunction(name string, node hast.Node)
- func (st *SymbolTable) AddSymbol(symbol *Symbol)
- func (st *SymbolTable) AddVariable(name string, node hast.Node)
- func (st *SymbolTable) AllocVariableName(originalName string, scope *Scope) string
- func (st *SymbolTable) CurrentScope() *Scope
- func (st *SymbolTable) HasClass(name string) bool
- func (st *SymbolTable) HasConstant(name string) bool
- func (st *SymbolTable) HasFunction(name string) bool
- func (st *SymbolTable) HasVariable(name string) bool
- func (st *SymbolTable) LookupSymbol(name string) *Symbol
- func (st *SymbolTable) PopScope()
- func (st *SymbolTable) PushScope(scopeType ScopeType, module *Module) *Scope
- type SymbolType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BashTranspiler ¶
type BashTranspiler struct {
// contains filtered or unexported fields
}
func NewBashTranspiler ¶
func NewBashTranspiler(opts *config.Huloc, vfs vfs.VFS) *BashTranspiler
func (*BashTranspiler) ConvertArrayLiteralExpr ¶
func (b *BashTranspiler) ConvertArrayLiteralExpr(node *hast.ArrayLiteralExpr) bast.Node
ConvertArrayLiteralExpr 转换数组字面量表达式
func (*BashTranspiler) ConvertAssignStmt ¶
func (b *BashTranspiler) ConvertAssignStmt(node *hast.AssignStmt) bast.Node
func (*BashTranspiler) ConvertBinaryExpr ¶
func (b *BashTranspiler) ConvertBinaryExpr(node *hast.BinaryExpr) bast.Node
func (*BashTranspiler) ConvertBlockStmt ¶
func (b *BashTranspiler) ConvertBlockStmt(node *hast.BlockStmt) bast.Node
func (*BashTranspiler) ConvertCallExpr ¶
func (b *BashTranspiler) ConvertCallExpr(node *hast.CallExpr) bast.Node
func (*BashTranspiler) ConvertClassDecl ¶
func (b *BashTranspiler) ConvertClassDecl(node *hast.ClassDecl) bast.Node
func (*BashTranspiler) ConvertCmdExpr ¶
func (b *BashTranspiler) ConvertCmdExpr(node *hast.CmdExpr) bast.Node
func (*BashTranspiler) ConvertComment ¶
func (b *BashTranspiler) ConvertComment(node *hast.Comment) bast.Node
func (*BashTranspiler) ConvertCommentGroup ¶
func (b *BashTranspiler) ConvertCommentGroup(node *hast.CommentGroup) bast.Node
func (*BashTranspiler) ConvertDeclareDecl ¶
func (b *BashTranspiler) ConvertDeclareDecl(node *hast.DeclareDecl) bast.Node
func (*BashTranspiler) ConvertDoWhileStmt ¶
func (b *BashTranspiler) ConvertDoWhileStmt(node *hast.DoWhileStmt) bast.Node
ConvertDoWhileStmt 将 do-while 语句转换为 while 循环
func (*BashTranspiler) ConvertExprStmt ¶
func (b *BashTranspiler) ConvertExprStmt(node *hast.ExprStmt) bast.Node
func (*BashTranspiler) ConvertFalseLiteral ¶
func (b *BashTranspiler) ConvertFalseLiteral(node *hast.FalseLiteral) bast.Node
func (*BashTranspiler) ConvertFile ¶
func (b *BashTranspiler) ConvertFile(node *hast.File) bast.Node
func (*BashTranspiler) ConvertForInStmt ¶
func (b *BashTranspiler) ConvertForInStmt(node *hast.ForInStmt) bast.Node
ConvertForInStmt 转换 for-in 循环
func (*BashTranspiler) ConvertForOfStmt ¶
func (b *BashTranspiler) ConvertForOfStmt(node *hast.ForeachStmt) bast.Node
func (*BashTranspiler) ConvertForStmt ¶
func (b *BashTranspiler) ConvertForStmt(node *hast.ForStmt) bast.Node
func (*BashTranspiler) ConvertForeachStmt ¶
func (b *BashTranspiler) ConvertForeachStmt(node *hast.ForeachStmt) bast.Node
ConvertForeachStmt 转换 foreach 循环
func (*BashTranspiler) ConvertFuncDecl ¶
func (b *BashTranspiler) ConvertFuncDecl(node *hast.FuncDecl) bast.Node
func (*BashTranspiler) ConvertIdent ¶
func (b *BashTranspiler) ConvertIdent(node *hast.Ident) bast.Node
func (*BashTranspiler) ConvertIfStmt ¶
func (b *BashTranspiler) ConvertIfStmt(node *hast.IfStmt) bast.Node
func (*BashTranspiler) ConvertImport ¶
func (b *BashTranspiler) ConvertImport(node *hast.Import) bast.Node
func (*BashTranspiler) ConvertIncDecExpr ¶
func (b *BashTranspiler) ConvertIncDecExpr(node *hast.IncDecExpr) bast.Node
func (*BashTranspiler) ConvertMatchStmt ¶
func (b *BashTranspiler) ConvertMatchStmt(node *hast.MatchStmt) bast.Node
ConvertMatchStmt 将 match 语句转换为 case 语句
func (*BashTranspiler) ConvertNumericLiteral ¶
func (b *BashTranspiler) ConvertNumericLiteral(node *hast.NumericLiteral) bast.Node
func (*BashTranspiler) ConvertObjectLiteralExpr ¶
func (b *BashTranspiler) ConvertObjectLiteralExpr(node *hast.ObjectLiteralExpr) bast.Node
ConvertObjectLiteralExpr 转换对象字面量表达式
func (*BashTranspiler) ConvertParameter ¶
func (b *BashTranspiler) ConvertParameter(node *hast.Parameter) bast.Node
ConvertParameter 处理函数参数
func (*BashTranspiler) ConvertRefExpr ¶
func (b *BashTranspiler) ConvertRefExpr(node *hast.RefExpr) bast.Node
ConvertRefExpr 处理引用表达式 $x
func (*BashTranspiler) ConvertReturnStmt ¶
func (b *BashTranspiler) ConvertReturnStmt(node *hast.ReturnStmt) bast.Node
func (*BashTranspiler) ConvertSelectExpr ¶
func (b *BashTranspiler) ConvertSelectExpr(node *hast.SelectExpr) bast.Node
ConvertSelectExpr 处理选择表达式,区分模块访问和对象方法调用
func (*BashTranspiler) ConvertStringLiteral ¶
func (b *BashTranspiler) ConvertStringLiteral(node *hast.StringLiteral) bast.Node
func (*BashTranspiler) ConvertTrueLiteral ¶
func (b *BashTranspiler) ConvertTrueLiteral(node *hast.TrueLiteral) bast.Node
func (*BashTranspiler) ConvertWhileStmt ¶
func (b *BashTranspiler) ConvertWhileStmt(node *hast.WhileStmt) bast.Node
func (*BashTranspiler) Emit ¶
func (b *BashTranspiler) Emit(stmt bast.Stmt)
func (*BashTranspiler) Flush ¶
func (v *BashTranspiler) Flush() []bast.Stmt
type DependencyResolver ¶
type DependencyResolver struct {
// contains filtered or unexported fields
}
type ExportInfo ¶
type ExportInfo struct { Name string Value hast.Node Kind ExportKind Public bool }
type ExportKind ¶
type ExportKind int
Function, Class, Constant, etc.
const ( ExportFunction ExportKind = iota ExportClass ExportConstant ExportVariable )
type HCRDispatcher ¶
type HCRDispatcher struct {
// contains filtered or unexported fields
}
func (*HCRDispatcher) Get ¶
func (d *HCRDispatcher) Get(ruleName string) (transpiler.Strategy[bast.Node], error)
func (*HCRDispatcher) Put ¶
func (d *HCRDispatcher) Put(fullRule string, cb transpiler.Strategy[bast.Node]) error
type ImportInfo ¶
type ImportInfo struct { ModulePath string SymbolName []string Alias string Kind ImportKind }
type ImportKind ¶
type ImportKind int
Named, All, Default
const ( ImportSingle ImportKind = iota ImportMulti ImportAll )
type Module ¶
type Module struct { Name string Path string AST *hast.File Exports map[string]*ExportInfo Imports []*ImportInfo Dependencies []string Transpiled *bast.File Symbols *SymbolTable }
type ModuleManager ¶
type ModuleManager struct {
// contains filtered or unexported fields
}
func (*ModuleManager) GetModule ¶
func (mm *ModuleManager) GetModule(path string) *Module
func (*ModuleManager) ResolveAllDependencies ¶
func (mm *ModuleManager) ResolveAllDependencies(mainFile string) ([]*Module, error)
type ScopeStack ¶
type ScopeStack struct {
// contains filtered or unexported fields
}
func (*ScopeStack) Current ¶
func (ss *ScopeStack) Current() *Scope
func (*ScopeStack) Pop ¶
func (ss *ScopeStack) Pop()
func (*ScopeStack) Push ¶
func (ss *ScopeStack) Push(scope *Scope)
type SymbolTable ¶
type SymbolTable struct {
// contains filtered or unexported fields
}
func NewSymbolTable ¶
func NewSymbolTable(moduleName string, enableMangle bool) *SymbolTable
NewSymbolTable 创建新的符号表
func (*SymbolTable) AddClass ¶
func (st *SymbolTable) AddClass(name string, node hast.Node)
AddClass 添加类
func (*SymbolTable) AddConstant ¶
func (st *SymbolTable) AddConstant(name string, node hast.Node)
AddConstant 添加常量
func (*SymbolTable) AddFunction ¶
func (st *SymbolTable) AddFunction(name string, node hast.Node)
AddFunction 添加函数
func (*SymbolTable) AddVariable ¶
func (st *SymbolTable) AddVariable(name string, node hast.Node)
AddVariable 添加变量
func (*SymbolTable) AllocVariableName ¶
func (st *SymbolTable) AllocVariableName(originalName string, scope *Scope) string
变量分配策略
func (*SymbolTable) CurrentScope ¶
func (st *SymbolTable) CurrentScope() *Scope
func (*SymbolTable) HasConstant ¶
func (st *SymbolTable) HasConstant(name string) bool
HasConstant 检查是否包含常量
func (*SymbolTable) HasFunction ¶
func (st *SymbolTable) HasFunction(name string) bool
HasFunction 检查是否包含函数
func (*SymbolTable) HasVariable ¶
func (st *SymbolTable) HasVariable(name string) bool
HasVariable 检查是否包含变量
func (*SymbolTable) PopScope ¶
func (st *SymbolTable) PopScope()
type SymbolType ¶
type SymbolType int
const ( SymbolVariable SymbolType = iota SymbolFunction SymbolClass SymbolConstant SymbolArray SymbolObject )