Documentation
¶
Overview ¶
generator.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateMain ¶
GenerateMain generates a simple main function
Types ¶
type CodeBuilder ¶
type CodeBuilder struct {
// contains filtered or unexported fields
}
CodeBuilder helps in constructing code with proper indentation.
func NewCodeBuilder ¶
func NewCodeBuilder() *CodeBuilder
NewCodeBuilder initializes a new CodeBuilder using a tab for indentation.
func (*CodeBuilder) Format ¶
func (cb *CodeBuilder) Format() (string, error)
Format returns the source code formatted according to Go standards.
func (*CodeBuilder) Indent ¶
func (cb *CodeBuilder) Indent()
Indent increases the indentation level.
func (*CodeBuilder) Outdent ¶
func (cb *CodeBuilder) Outdent()
Outdent decreases the indentation level.
func (*CodeBuilder) String ¶
func (cb *CodeBuilder) String() string
String returns the accumulated source code.
func (*CodeBuilder) Write ¶
func (cb *CodeBuilder) Write(lines ...string)
Write writes multiple lines of code.
func (*CodeBuilder) WriteLine ¶
func (cb *CodeBuilder) WriteLine(line string)
WriteLine writes a single line of code with the current indentation.
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
CodeGenerator is the enterprise-grade code generator.
func NewCodeGenerator ¶
func NewCodeGenerator(packageName string) *CodeGenerator
NewCodeGenerator creates a new CodeGenerator for a given package name.
func (*CodeGenerator) AddFunction ¶
func (cg *CodeGenerator) AddFunction(fn Function)
AddFunction registers a function to be included in the generated source.
func (*CodeGenerator) AddGlobal ¶
func (cg *CodeGenerator) AddGlobal(global string)
AddGlobal adds a global variable declaration or any global-level code.
func (*CodeGenerator) AddImport ¶
func (cg *CodeGenerator) AddImport(pkg string)
AddImport registers an import package, avoiding duplicates.
func (*CodeGenerator) Build ¶
func (cg *CodeGenerator) Build() (string, error)
Build constructs the complete Go source file and returns the formatted source code.
type Function ¶
type Function struct {
Name string // Function name.
Parameters []Parameter // List of parameters.
ReturnType string // Return type (empty if none).
Body []string // Lines of code in the function body.
Comments []string // Optional comment lines to document the function.
}
Function represents a Go function with its signature, body, and optional comments.
type FunctionData ¶
FunctionData holds data for function template
type GoCodeGenerator ¶
type GoCodeGenerator struct {
IR *parser.IntermediateRepresentation
RequiredImports map[string]bool
Generator *CodeGenerator
}
GoCodeGenerator generates Go code from an intermediate representation
func NewGoCodeGenerator ¶
func NewGoCodeGenerator(ir *parser.IntermediateRepresentation) *GoCodeGenerator
NewGoCodeGenerator creates a new code generator
func (*GoCodeGenerator) Generate ¶
func (g *GoCodeGenerator) Generate() (string, error)
Generate generates Go code from the intermediate representation
type TemplateData ¶
type TemplateData struct {
Imports []string
Functions []FunctionData
Variables []VariableData
MainBody string
RequiresExec bool
RequiresFilepath bool
RequiresStrings bool
RequiresGexe bool
}
TemplateData holds data for main template
type VariableData ¶
VariableData holds data for variable template