Documentation
¶
Index ¶
- Constants
- func FindLocalEntryPoint(dir string) (string, error)
- func FindRugoFile(basePath string) string
- func IsRugoBenchFile(name string) bool
- func IsRugoFile(name string) bool
- func IsRugoTestFile(name string) bool
- func TrimRugoExt(name string) string
- func WalkExprs(prog *ast.Program, fn func(ast.Expr) bool) bool
- func WalkStmts(prog *ast.Program, fn func(ast.Statement) bool)
- func WarnDeprecatedExt(filename string)
- type CompileResult
- type Compiler
- func (c *Compiler) Build(filename, output string) error
- func (c *Compiler) Compile(filename string) (*CompileResult, error)
- func (c *Compiler) Emit(filename string) (string, error)
- func (c *Compiler) ParseFile(filename string) (*ast.Program, error)
- func (c *Compiler) ParseSource(source, name string) (*ast.Program, error)
- func (c *Compiler) Run(filename string, extraArgs ...string) error
- type FuncTypeInfo
- type RugoType
- type TypeInfo
Constants ¶
const ( // RugoExt is the preferred file extension for Rugo source files. RugoExt = ".rugo" // DeprecatedExt is the old file extension, still supported but deprecated. DeprecatedExt = ".rg" )
Variables ¶
This section is empty.
Functions ¶
func FindLocalEntryPoint ¶ added in v0.11.0
FindLocalEntryPoint resolves the entry point Rugo file within a local directory. Resolution order: <dirname>.rugo → <dirname>.rg → main.rugo → main.rg → sole Rugo file.
func FindRugoFile ¶ added in v0.12.0
FindRugoFile looks for a Rugo source file, preferring .rugo over .rg. Given a base path without extension, returns the path if found, empty string otherwise.
func IsRugoBenchFile ¶ added in v0.12.0
IsRugoBenchFile returns true if the filename is a Rugo benchmark file (_bench.rugo or _bench.rg).
func IsRugoFile ¶ added in v0.12.0
IsRugoFile returns true if the filename has a Rugo extension (.rugo or .rg).
func IsRugoTestFile ¶ added in v0.12.0
IsRugoTestFile returns true if the filename is a Rugo test file (_test.rugo or _test.rg).
func TrimRugoExt ¶ added in v0.12.0
TrimRugoExt removes the Rugo file extension (.rugo or .rg) from a filename.
func WalkExprs ¶ added in v0.15.0
WalkExprs traverses the entire AST and calls fn on every ast.Expr node. Returns true as soon as fn returns true for any expression.
func WalkStmts ¶ added in v0.15.0
WalkStmts traverses all statements in a ast.Program, calling fn for each. If fn returns false, children of that statement are not visited. Recurses into block bodies (ast.FuncDef, ast.TestDef, ast.BenchDef, ast.IfStmt, ast.WhileStmt, ast.ForStmt).
func WarnDeprecatedExt ¶ added in v0.12.0
func WarnDeprecatedExt(filename string)
WarnDeprecatedExt prints a deprecation warning to stderr if the file uses the old .rg extension.
Types ¶
type CompileResult ¶
type CompileResult struct {
GoSource string
Program *ast.Program
SourceFile string // original source filename
}
CompileResult holds the output of a compilation.
type Compiler ¶
type Compiler struct {
// BaseDir is the directory of the main source file (for resolving requires).
BaseDir string
// TestMode enables test harness generation (rats blocks are included).
// When false (default), rats blocks are silently skipped during codegen.
TestMode bool
// ModuleDir overrides the default module cache directory (~/.rugo/modules).
// Used for testing. When empty, the default is used.
ModuleDir string
// Frozen errors if the lock file is stale or a new dependency is resolved.
Frozen bool
// Resolver overrides the default remote resolver. When set, the compiler
// uses this resolver instead of creating one. Used by mod tidy to share
// a single resolver across multiple compilations.
Resolver *remote.Resolver
// contains filtered or unexported fields
}
Compiler orchestrates the full compilation pipeline.
func (*Compiler) Compile ¶
func (c *Compiler) Compile(filename string) (*CompileResult, error)
Compile reads a Rugo source file, resolves requires, and produces Go source.
func (*Compiler) ParseFile ¶ added in v0.15.0
ParseFile reads a Rugo source file and parses it into a ast.Program AST without compiling to Go. Useful for tooling such as linters, formatters, and refactoring tools that need AST access without full compilation.
func (*Compiler) ParseSource ¶ added in v0.15.0
ParseSource parses raw Rugo source code into a ast.Program AST without compiling to Go. The name parameter is used for error messages.
type FuncTypeInfo ¶
FuncTypeInfo holds the inferred signature for a function.
type RugoType ¶
type RugoType int
const ( // TypeUnknown means inference hasn't resolved the type yet. TypeUnknown RugoType = iota // TypeInt is an integer type (Go int). TypeInt // TypeFloat is a floating-point type (Go float64). TypeFloat // TypeString is a string type. TypeString // TypeBool is a boolean type. TypeBool // TypeNil is the nil literal type. TypeNil // TypeArray is []interface{} (element types not tracked). TypeArray // TypeHash is map[interface{}]interface{}. TypeHash // TypeDynamic means the type is explicitly unresolvable (mixed types, // external calls, etc.). Falls back to interface{} in codegen. TypeDynamic )
func (RugoType) IsResolved ¶
IsResolved returns true if the type is concrete (not unknown or dynamic).
type TypeInfo ¶
type TypeInfo struct {
// ExprTypes maps expressions to their inferred types.
ExprTypes map[ast.Expr]RugoType
// FuncTypes maps function names to their inferred signatures.
FuncTypes map[string]*FuncTypeInfo
// VarTypes maps (scope, variable name) to their final inferred type.
// Scope is the function name (or "" for top-level).
VarTypes map[string]map[string]RugoType
}
TypeInfo holds inferred type information for a program.
func Infer ¶ added in v0.15.0
Infer runs type inference on a parsed program, returning type annotations for expressions and function signatures. The inference is conservative: anything that can't be proven typed remains TypeDynamic (interface{}).