gadbridge

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gadbridge exposes Gad's format, diagnose and run capabilities behind a small, JSON-friendly API. It is the shared core used by both the HTTP server (web/server) and the WebAssembly module (web/wasm), so the editor integration behaves identically regardless of backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalSource

func EvalSource(prelude, expr, render string) string

EvalSource builds a runnable script that evaluates expr (rendered by render, "str" or "repr") in the context of an optional prelude. Top-level `return` statements in the prelude are dropped so the file's definitions stay in scope but the file's own return value does not short-circuit the evaluation. An unparseable prelude is used as-is so the compile error surfaces.

Types

type Diagnostic

type Diagnostic struct {
	Line     int      `json:"line"`
	Column   int      `json:"column"`
	Message  string   `json:"message"`
	Severity Severity `json:"severity"`
}

Diagnostic is a positioned message for the editor. Lines and columns are 1-based, matching Gad's parser positions.

func Diagnose

func Diagnose(src string) []Diagnostic

Diagnose returns the syntax and compile diagnostics for src (empty when the source is valid).

func ErrorDiagnostics

func ErrorDiagnostics(err error) []Diagnostic

ErrorDiagnostics converts a Gad parse/compile/runtime error into positioned diagnostics, for callers (such as the IDE backend) that run Gad with custom options but still want editor-friendly error positions.

type DocComment

type DocComment struct {
	Line    int    `json:"line"`
	Kind    string `json:"kind"`
	Title   string `json:"title"`
	Content string `json:"content"`
}

DocComment is one rendered doc comment (`///`, `/**` or `/***`) from a source file: its 1-based start line, kind, the following code line as a title (when any) and the Markdown content.

func DocComments

func DocComments(src string) []DocComment

DocComments extracts the doc comments from src, in source order. A parse error yields whatever comments were collected before it (best effort), so the panel still shows docs for a file being edited.

type FormatResult

type FormatResult struct {
	OK          bool         `json:"ok"`
	Source      string       `json:"source"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

FormatResult is the outcome of formatting a source.

func Format

func Format(src string) FormatResult

Format formats src with the canonical formatter, preserving comments and doc comments. On a parse error the source is returned unchanged together with the diagnostics.

func Transpile

func Transpile(src string, mixed bool, opts *node.TranspileOptions) FormatResult

Transpile rewrites a Gad source into plain Gad with template text and `{%= … %}` expressions turned into write(...) calls, using the default gad.TranspileOptions unless overridden. When mixed is set the source is parsed in mixed (template) mode — the form used for `.gadt` files. On a parse error the source is returned unchanged with the diagnostics. Mirrors Format.

type InspectEntry

type InspectEntry struct {
	Key        string `json:"key"`        // display key (dict key / array index)
	Accessor   string `json:"accessor"`   // Gad index suffix to reach it from the parent (`["a"]`, `[0]`)
	Type       string `json:"type"`       // child type name
	Value      string `json:"value"`      // child str(), truncated
	Expandable bool   `json:"expandable"` // child is itself a container
}

InspectEntry is one child of an inspected container value.

type InspectResult

type InspectResult struct {
	Type       string         `json:"type"`
	Value      string         `json:"value"`
	Expandable bool           `json:"expandable"`
	Entries    []InspectEntry `json:"entries"`
}

InspectResult describes a value for the tree navigator: its type, rendered value and (for containers) its immediate children.

func InspectObject

func InspectObject(vm *gad.VM, obj gad.Object) InspectResult

InspectObject describes obj for the tree navigator. When obj is a container (any ItemsGetter: dict, array, keyValueArray, module namespace, …) its immediate children are enumerated with a Gad accessor so the caller can drill in by appending the accessor to the parent expression.

type RunResult

type RunResult struct {
	OK          bool         `json:"ok"`
	Stdout      string       `json:"stdout"`
	Stderr      string       `json:"stderr"`
	Result      string       `json:"result"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

RunResult is the outcome of compiling and executing a source.

func Run

func Run(src string) RunResult

Run compiles and executes src, capturing stdout/stderr and the return value.

type Severity

type Severity string

Severity classifies a diagnostic.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
)

Jump to

Keyboard shortcuts

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