Documentation
¶
Overview ¶
Package gosrc provide type safe way to represent go source code along with way to convert them to actual go source code
Index ¶
- Constants
- Variables
- func AddComments(sb *strings.Builder, comments []string)
- func CapitalizeFirstLetter(name string) string
- func LowercaseFirstLetter(name string) string
- func ToIdentifier(name string, public bool) string
- type ArrayLiteral
- type AssignStatement
- type BinaryExpression
- type BooleanLiteral
- type CallExpression
- type CallStatement
- type CastExpression
- type CatchClause
- type CharLiteral
- type CommentStmt
- type ConstBlock
- type Expression
- type FailedMigration
- type ForStatement
- type Function
- type GoExpression
- type GoSource
- type GoStatement
- type IfStatement
- type Import
- type Int64Literal
- type IntLiteral
- type Interface
- type InterfaceMethod
- type Method
- type ModuleConst
- type ModuleVar
- type Param
- type RangeForStatement
- type ReturnExpression
- type ReturnStatement
- type SourceElement
- type Statement
- type Struct
- type StructField
- type SwitchCase
- type SwitchStatement
- type TryStatement
- type Type
- type UnaryExpression
- type UnhandledExpression
- type VarDeclaration
- type VarRef
Constants ¶
const ( SelfRef = "this" PackageName = "converted" )
Variables ¶
var NIL = VarRef{Ref: "nil"}
NIL is a predefined nil expression
Functions ¶
func AddComments ¶
AddComments adds comment lines to a string builder
func CapitalizeFirstLetter ¶
TODO: move thse to a common string utils package CapitalizeFirstLetter capitalizes the first letter of a string
func LowercaseFirstLetter ¶
LowercaseFirstLetter lowercases the first letter of a string
func ToIdentifier ¶
ToIdentifier converts a name to a public or private identifier
Types ¶
type ArrayLiteral ¶
type ArrayLiteral struct {
ElementType Type
Elements []Expression
}
ArrayLiteral represents an array/slice literal
func (*ArrayLiteral) ToSource ¶
func (e *ArrayLiteral) ToSource() string
type AssignStatement ¶
type AssignStatement struct {
Ref VarRef
Value Expression
}
AssignStatement represents an assignment
func (*AssignStatement) ToSource ¶
func (s *AssignStatement) ToSource() string
type BinaryExpression ¶
type BinaryExpression struct {
Left Expression
Operator string
Right Expression
}
BinaryExpression represents a binary operation
func (*BinaryExpression) ToSource ¶
func (e *BinaryExpression) ToSource() string
type BooleanLiteral ¶
type BooleanLiteral struct {
Value bool
}
BooleanLiteral represents a boolean literal
func (*BooleanLiteral) ToSource ¶
func (e *BooleanLiteral) ToSource() string
type CallExpression ¶
type CallExpression struct {
Function string
Args []Expression
}
CallExpression represents a function call
func (*CallExpression) ToSource ¶
func (e *CallExpression) ToSource() string
type CallStatement ¶
type CallStatement struct {
Exp Expression
}
CallStatement represents a function call statement
func (*CallStatement) ToSource ¶
func (s *CallStatement) ToSource() string
type CastExpression ¶
type CastExpression struct {
Ty Type
Value Expression
}
CastExpression represents a type cast
func (*CastExpression) ToSource ¶
func (e *CastExpression) ToSource() string
type CatchClause ¶
CatchClause represents a catch clause in a try statement
type CharLiteral ¶
type CharLiteral struct {
Value string
}
CharLiteral represents a character literal
func (*CharLiteral) ToSource ¶
func (e *CharLiteral) ToSource() string
type CommentStmt ¶
type CommentStmt struct {
Comments []string
}
CommentStmt represents comment statements
func (*CommentStmt) ToSource ¶
func (s *CommentStmt) ToSource() string
type ConstBlock ¶
ConstBlock represents a const block with iota
func (*ConstBlock) ToSource ¶
func (cb *ConstBlock) ToSource() string
type FailedMigration ¶
FailedMigration represents a migration that failed
type ForStatement ¶
type ForStatement struct {
Init Statement
Condition Expression
Post Statement
Body []Statement
}
ForStatement represents a traditional for loop
func (*ForStatement) ToSource ¶
func (s *ForStatement) ToSource() string
type Function ¶
type Function struct {
Name string
Params []Param
ReturnType *Type
Body []Statement
Comments []string
Public bool
}
Function represents a Go function
type GoExpression ¶
type GoExpression struct {
Source string
}
GoExpression represents a raw Go expression string
func (*GoExpression) ToSource ¶
func (e *GoExpression) ToSource() string
type GoSource ¶
type GoSource struct {
Imports []Import
Interfaces []Interface
Structs []Struct
Constants []ModuleConst
ConstBlocks []ConstBlock
Vars []ModuleVar
Functions []Function
Methods []Method
FailedMigrations []FailedMigration
}
GoSource represents a complete Go source file
type GoStatement ¶
type GoStatement struct {
Source string
}
GoStatement represents a raw Go statement string
func (*GoStatement) ToSource ¶
func (s *GoStatement) ToSource() string
type IfStatement ¶
type IfStatement struct {
Condition Expression
Body []Statement
ElseIf []IfStatement
ElseStmts []Statement
}
IfStatement represents an if-else statement
func (*IfStatement) ToSource ¶
func (s *IfStatement) ToSource() string
type Int64Literal ¶
type Int64Literal struct {
Value int64
}
Int64Literal represents a 64-bit integer literal
func (*Int64Literal) ToSource ¶
func (e *Int64Literal) ToSource() string
type IntLiteral ¶
type IntLiteral struct {
Value int
}
IntLiteral represents an integer literal
func (*IntLiteral) ToSource ¶
func (e *IntLiteral) ToSource() string
type Interface ¶
type Interface struct {
Name string
Embeds []Type
Methods []InterfaceMethod
Public bool
Comments []string
}
Interface represents a Go interface definition
type InterfaceMethod ¶
InterfaceMethod represents a method signature in an interface
type ModuleConst ¶
type ModuleConst struct {
Name string
Ty Type
Value Expression
}
ModuleConst represents a module-level constant
func (*ModuleConst) ToSource ¶
func (c *ModuleConst) ToSource() string
type ModuleVar ¶
type ModuleVar struct {
Name string
Ty Type
Value Expression
Comments []string
}
ModuleVar represents a module-level variable
type RangeForStatement ¶
type RangeForStatement struct {
IndexVar string
ValueVar string
CollectionExpr Expression
Body []Statement
}
RangeForStatement represents a range-based for loop
func (*RangeForStatement) ToSource ¶
func (s *RangeForStatement) ToSource() string
type ReturnExpression ¶
type ReturnExpression struct {
Value Expression
}
ReturnExpression represents a return expression
func (*ReturnExpression) ToSource ¶
func (e *ReturnExpression) ToSource() string
type ReturnStatement ¶
type ReturnStatement struct {
Value Expression
}
ReturnStatement represents a return statement
func (*ReturnStatement) ToSource ¶
func (s *ReturnStatement) ToSource() string
type SourceElement ¶
type SourceElement interface {
ToSource() string
}
SourceElement represents any element that can be converted to Go source
type Struct ¶
type Struct struct {
Name string
Includes []Type
Fields []StructField
Public bool
Comments []string
}
Struct represents a Go struct definition
type StructField ¶
StructField represents a field in a struct
func (*StructField) ToSource ¶
func (f *StructField) ToSource() string
type SwitchCase ¶
type SwitchCase struct {
Condition Expression
Body []Statement
}
SwitchCase represents a case in a switch statement
type SwitchStatement ¶
type SwitchStatement struct {
Condition Expression
Cases []SwitchCase
DefaultBody []Statement
}
SwitchStatement represents a switch statement
func (*SwitchStatement) ToSource ¶
func (s *SwitchStatement) ToSource() string
type TryStatement ¶
type TryStatement struct {
TryBody []Statement
CatchClauses []CatchClause
FinallyBody []Statement
}
TryStatement represents a try-catch-finally block
func (*TryStatement) ToSource ¶
func (s *TryStatement) ToSource() string
type Type ¶
type Type string
Type represents a Go type
type UnaryExpression ¶
type UnaryExpression struct {
Operator string
Operand Expression
}
UnaryExpression represents a unary operation
func (*UnaryExpression) ToSource ¶
func (e *UnaryExpression) ToSource() string
type UnhandledExpression ¶
type UnhandledExpression struct {
Text string
}
UnhandledExpression represents an unhandled expression (fallback)
func (*UnhandledExpression) ToSource ¶
func (e *UnhandledExpression) ToSource() string
type VarDeclaration ¶
type VarDeclaration struct {
Name string
Ty Type
Value Expression
}
VarDeclaration represents a variable declaration
func (*VarDeclaration) ToSource ¶
func (s *VarDeclaration) ToSource() string