parser

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parser extracts function signatures and types from Go source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoTypeToJSExtraction

func GoTypeToJSExtraction(t GoType, argExpr string, workerMode bool) string

GoTypeToJSExtraction generates JavaScript code to extract a value from js.Value argExpr is the expression representing the js.Value argument (e.g., "args[0]") workerMode determines whether to generate worker-compatible callback code

func GoTypeToJSReturn

func GoTypeToJSReturn(t GoType, valueExpr string) string

GoTypeToJSReturn generates JavaScript return conversion code valueExpr is the Go expression to convert (e.g., "result")

func GoTypeToTS

func GoTypeToTS(t GoType) string

GoTypeToTS converts a GoType to TypeScript type string

func HasSelectInMain added in v1.0.1

func HasSelectInMain(path string) (bool, error)

HasSelectInMain checks if a Go source file has a main function containing select {}. This is required for WASM modules to stay alive and receive JavaScript calls.

Types

type GoField

type GoField struct {
	Name    string // Field name
	Type    GoType // Field type
	JSONTag string // JSON tag value (if present)
}

GoField represents a single field in a struct

type GoFunction

type GoFunction struct {
	Name    string        // Function name
	Params  []GoParameter // Function parameters
	Returns []GoType      // Return types
	Doc     string        // Documentation comment
}

GoFunction represents a parsed exported function

type GoParameter

type GoParameter struct {
	Name string // Parameter name
	Type GoType // Parameter type
}

GoParameter represents a single function parameter

type GoType

type GoType struct {
	Name    string    // Type name (e.g., "string", "User", "[]string")
	Kind    TypeKind  // Category of the type
	Elem    *GoType   // Element type for slices/arrays/pointers
	Key     *GoType   // Key type for maps
	Value   *GoType   // Value type for maps
	Fields  []GoField // Fields for struct types
	IsError bool      // True if this is the error type

	// For KindFunction (void callbacks only)
	CallbackParams []GoType // Parameter types of the callback (nil if not a callback)
	IsVoid         bool     // True if callback has no return value (for validator)
}

GoType represents a parsed Go type with full structural information

type ParsedFile

type ParsedFile struct {
	Package   string             // Package name
	Functions []GoFunction       // Exported functions
	Types     map[string]*GoType // Type definitions in the file
}

ParsedFile represents a parsed Go source file

func ParseSourceFile

func ParseSourceFile(path string) (*ParsedFile, error)

ParseSourceFile parses a Go source file and extracts exported functions and types

type TypeKind

type TypeKind int

TypeKind represents the category of a Go type

const (
	KindUnknown TypeKind = iota // Zero value indicates uninitialized type
	KindPrimitive
	KindSlice
	KindArray
	KindMap
	KindStruct
	KindPointer
	KindError
	KindFunction // function type (for callbacks)
	KindUnsupported
)

Jump to

Keyboard shortcuts

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