transpiler

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package transpiler implements a source-to-source compiler for translating Gno code into Go code.

Index

Constants

View Source
const ImportPrefix = "github.com/gnolang/gno"

ImportPrefix is the import path to the root of the gno repository, which should be used to create go import paths.

Variables

This section is empty.

Functions

func PackageDirLocation

func PackageDirLocation(s string) string

PackageDirLocation provides the supposed directory of the package, relative to the root dir.

TODO(morgan): move out, this should go in a "resolver" package.

func TranspileImportPath

func TranspileImportPath(s string) string

TranspileImportPath takes an import path s, and converts it into the full import path relative to the Gno repository.

func TranspiledFilenameAndTags

func TranspiledFilenameAndTags(gnoFilePath string) (targetFilename, tags string)

TranspiledFilenameAndTags returns the filename and tags for transpiled files.

Types

type ImportResolver

type ImportResolver func(importPath string) (relPath string, ok bool)

ImportResolver maps a Gno import path to its location relative to the gno repo root. ok=false means the import is unresolvable.

func DefaultResolver

func DefaultResolver(rootDir string) ImportResolver

DefaultResolver returns "examples/<path>" for non-stdlibs and "gnovm/stdlibs/<path>" for stdlibs. When rootDir is non-empty it also checks the resolved path exists on disk.

type Result

type Result struct {
	Imports    []*ast.ImportSpec
	Translated string
	File       *ast.File
}

Result is returned by Transpile, returning the file's imports and output out the transpilation.

func Transpile

func Transpile(source, tags, filename string) (*Result, error)

Transpile performs transpilation on the given source code. tags can be used to specify build tags; filename helps generate useful error messages and discriminate between test and normal source files. Equivalent to TranspileWithResolver with a nil resolver.

func TranspileWithResolver

func TranspileWithResolver(source, tags, filename string, resolver ImportResolver) (*Result, error)

TranspileWithResolver is like Transpile but uses the supplied resolver for import lookups. A nil resolver falls back to DefaultResolver.

Jump to

Keyboard shortcuts

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