Help us shape the future of Go! Take the 2026 Go Developer Survey

gen

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package gen turns a notebook's code cells into a Go program: the worker the kernel compiles and drives.

Each cell becomes a function. The names a cell defines at its top level become package-level variables — so every cell, and every function, can read them, and their values outlive the call — which needs their types: gen type-checks the cells one by one in dependency order to learn them. The cells' own text is kept, edited in place (":=" becomes "= ", a final expression is wrapped in a call that shows it), under //line directives that point back into the notebook, so the compiler's errors and a panic's stack name the notebook's lines.

Index

Constants

View Source
const RuntimePath = "github.com/go-notebook/notebook/runtime"

RuntimePath is the import path of the package the program links.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code struct {
	Source string
	Line   int
}

Code is one code cell: its source and the 1-based line of the notebook where that source starts.

type Diag

type Diag struct {
	Cell      int // -1 when it is not inside a cell
	Line, Col int // in the notebook
	Msg       string
}

Diag is a problem in the notebook, at a cell and a position in it.

func (Diag) String

func (d Diag) String() string

type Program

type Program struct {
	Source []byte
	Vars   []Var
	Graph  *analysis.Graph
	// Imports maps every package the program imports (but the runtime) to
	// the name it is imported under.
	Imports map[string]string
	// Diags are the notebook's errors. A program with diagnostics is still
	// returned, but will not compile.
	Diags []Diag
}

Program is a generated worker.

func Generate

func Generate(path string, cells []Code, imp types.Importer) *Program

Generate builds the program for a notebook's code cells. path is the notebook's file name, used in //line directives; imp resolves the packages the cells import.

type Var

type Var struct {
	Name string
	Type string // Go syntax, qualified with the program's import names
	Cell int
}

Var is a notebook variable as the program declares it.

Jump to

Keyboard shortcuts

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