workspace

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package workspace is an in-memory cross-routine index of M source: every routine's labels (declarations) and outbound call sites (references). It is the substrate the cross-routine lint rules need (M-XINDX-007 call-to-undefined -routine, 008 call-to-undefined-label, 049 label-never-referenced) — the single-file linter has no other way to resolve LABEL^ROUTINE across files. Faithful port of the Python tool's m_cli.workspace.WorkspaceIndex.

Routine identity comes from the file base name (upper-cased), matching ydb's resolution — not the first-label-equals-routine convention, which not every codebase follows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UsesRuntimeLabelLookup

func UsesRuntimeLabelLookup(src []byte) bool

UsesRuntimeLabelLookup is a coarse, conservative check: if any marker is present, the routine's label graph may be dynamic, so M-XINDX-049 skips it.

Types

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index holds labels keyed by routine and references keyed by target.

func New

func New() *Index

func (*Index) AddFile

func (i *Index) AddFile(routine string, root parse.Node)

AddFile indexes one parsed file's labels + references. routine is the file base name (without extension); it is upper-cased internally.

func (*Index) HasRoutine

func (i *Index) HasRoutine(routine string) bool

HasRoutine reports whether any label is indexed for routine (case-insensitive).

func (*Index) Lookup

func (i *Index) Lookup(routine, label string) bool

Lookup reports whether LABEL^ROUTINE resolves. label "" means the routine entry (resolves iff the routine has any label, per M semantics).

func (*Index) ReferencesTo

func (i *Index) ReferencesTo(routine, label string) int

ReferencesTo counts indexed call sites whose target matches (routine, label).

type Label

type Label struct {
	Routine string // upper-case routine name
	Name    string // original-case label
	Line    int    // 1-based
}

Label is one labeled entry point.

func Labels

func Labels(root parse.Node) []Label

Labels returns each top-level line's first label.

type Reference

type Reference struct {
	TargetRoutine string // upper
	TargetLabel   string // upper, "" when only ^ROUTINE was written
	Line          int    // 1-based
	Col           int    // 0-based
	EndCol        int    // 0-based exclusive
}

Reference is one outbound call site. TargetLabel is "" for `^ROUTINE` / `$$^ROUTINE` forms that name no label. Positions are 0-based columns.

func References

func References(root parse.Node, routine string) []Reference

References extracts every cross-routine call site: entry_reference / extrinsic_function nodes (via the call-header regex) plus bare-label DO/GOTO/JOB arguments (which target a label in the current routine).

Jump to

Keyboard shortcuts

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