Documentation
¶
Overview ¶
Package notebook reads the code cells of a Jupyter notebook (nbformat 4), so a model written in a notebook can be loaded where a model file can.
Index ¶
Constants ¶
const Ext = ".ipynb"
Ext is the file extension a notebook is named with.
const Language = "sysml"
Language is the kernelspec language a notebook must record to be loaded as a SysML model; a notebook recording none is taken to be one.
const SkipTag = "skip-load"
SkipTag marks a code cell a load passes over: scratch work, a demonstration, anything the notebook runs that another should not inherit.
Variables ¶
This section is empty.
Functions ¶
func BareExpression ¶ added in v0.12.0
BareExpression reports whether src reads as an expression the kernel answers rather than as a declaration it submits, and the expression it reads as: text that is no file but parses whole as one expression.
func IsNotebook ¶
IsNotebook reports whether path names a notebook, by its extension.
func NeedsContinuation ¶ added in v0.12.0
NeedsContinuation reports whether src is an unfinished submission: a brace, parenthesis or bracket it opens is not yet closed, or it ends inside a string, quoted name or comment, so the prompt reads another line before submitting it. Each counter clamps at 0 so a stray closer forces nothing.
Types ¶
type Cell ¶
type Cell struct {
// Index is the cell's 1-based position among the notebook's code cells,
// which is how a selection names it and how a diagnostic locates it.
Index int
Source string
Tags []string
}
Cell is one code cell of a notebook.
type FormatError ¶
FormatError is a file that is not a notebook a load can read, and why.
func (*FormatError) Error ¶
func (e *FormatError) Error() string
type LanguageError ¶
LanguageError is a notebook written for another kernel's language, which a load refuses rather than reading its cells as SysML.
func (*LanguageError) Error ¶
func (e *LanguageError) Error() string
type Notebook ¶
type Notebook struct {
Name string
Language string // kernelspec.language, else language_info.name; "" when neither is recorded
Cells []Cell
}
Notebook is what a load reads of a notebook: its code cells in notebook order, markdown and raw cells left out, and the language its kernel records.
type Selection ¶
type Selection struct {
// contains filtered or unexported fields
}
Selection picks the code cells of a notebook a load reads: by position among the code cells, 1-based, as `1,3-5`, or by a tag they carry, as `tag:model`. The zero Selection picks every cell.
func ParseSelection ¶
ParseSelection reads a selection as it is written after `--cells`.
func (Selection) Apply ¶
Apply picks the notebook's cells the selection names, in notebook order. A position past the notebook's code cells is an error naming how many there are; a tag no cell carries is an error naming the tag.
type Skipped ¶ added in v0.12.0
Skipped counts the lines of a cell Declarations blanked.
func Declarations ¶ added in v0.12.0
Declarations is the text of a cell as what it declares: its declarations where they stand, every `%` command line and expression line blank, so a position in the result is the same position in the cell.
type Statement ¶ added in v0.12.0
type Statement struct {
// Command is set when Text is a `%` command line.
Command bool
Text string
// Line is the line of the cell, counted from 1, that Text begins on.
Line int
}
Statement is one unit of a cell: a `%` command line, or a run of declaration or expression text the kernel submits whole.
func Statements ¶ added in v0.12.0
Statements splits a cell of input into what the kernel reads from it. A `%` line outside a continuation is a command; an expression that closes its brackets is answered on its own, as the prompt answers one line; declarations run together into one submission up to the next command or expression, so a cell may hold a whole model as a file does, blank lines included.