gosrc

package
v0.0.0-...-e6b68ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 2 Imported by: 0

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

View Source
const (
	SelfRef     = "this"
	PackageName = "converted"
)

Variables

View Source
var NIL = VarRef{Ref: "nil"}

NIL is a predefined nil expression

Functions

func AddComments

func AddComments(sb *strings.Builder, comments []string)

AddComments adds comment lines to a string builder

func CapitalizeFirstLetter

func CapitalizeFirstLetter(name string) string

TODO: move thse to a common string utils package CapitalizeFirstLetter capitalizes the first letter of a string

func LowercaseFirstLetter

func LowercaseFirstLetter(name string) string

LowercaseFirstLetter lowercases the first letter of a string

func ToIdentifier

func ToIdentifier(name string, public bool) string

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

type CatchClause struct {
	ExceptionType string
	ExceptionVar  string
	Body          []Statement
}

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

type ConstBlock struct {
	TypeName  string
	Constants []string
}

ConstBlock represents a const block with iota

func (*ConstBlock) ToSource

func (cb *ConstBlock) ToSource() string

type Expression

type Expression interface {
	SourceElement
}

Expression represents a Go expression

type FailedMigration

type FailedMigration struct {
	ErrorMessage string
	JavaSource   string
	SExpr        string
	Location     string
}

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

func (*Function) ToSource

func (f *Function) ToSource() string

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

func (*GoSource) ToSource

func (s *GoSource) ToSource(licenseHeader, packageName string) string

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 Import

type Import struct {
	PackagePath string
	Alias       *string
}

Import represents a package import

func (*Import) ToSource

func (imp *Import) 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

func (*Interface) ToSource

func (i *Interface) ToSource() string

type InterfaceMethod

type InterfaceMethod struct {
	Name       string
	Params     []Param
	ReturnType *Type
	Public     bool
}

InterfaceMethod represents a method signature in an interface

type Method

type Method struct {
	Function
	Receiver Param
}

Method represents a Go method with a receiver

func (*Method) ToSource

func (f *Method) ToSource() string

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

func (*ModuleVar) ToSource

func (v *ModuleVar) ToSource() string

type Param

type Param struct {
	Name string
	Ty   Type
}

Param represents a function or method parameter

func (*Param) ToSource

func (p *Param) ToSource() string

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 Statement

type Statement interface {
	SourceElement
}

Statement represents a Go statement

type Struct

type Struct struct {
	Name     string
	Includes []Type
	Fields   []StructField
	Public   bool
	Comments []string
}

Struct represents a Go struct definition

func (*Struct) ToSource

func (s *Struct) ToSource() string

type StructField

type StructField struct {
	Name     string
	Ty       Type
	Public   bool
	Comments []string
}

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

const (
	TypeInt     Type = "int"
	TypeString  Type = "string"
	TypeBool    Type = "bool"
	TypeFloat64 Type = "float64"
)

Type constants

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) ToSource

func (t *Type) ToSource() string

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

type VarRef

type VarRef struct {
	Ref string
}

VarRef represents a variable reference

func (*VarRef) ToSource

func (e *VarRef) ToSource() string

Jump to

Keyboard shortcuts

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