Documentation
¶
Overview ¶
Package parse is the engine-neutral M parse substrate: it runs the tree-sitter-m grammar through a pure-Go WASM runtime (wazero) with no CGO, exposing a small Tree/Node API that fmt/lint/lsp build on (spec §4).
The grammar (tree-sitter-m) is C compiled to WASM; the mainstream Go tree-sitter binding is CGO, which would kill the CGO_ENABLED=0 static-binary premise. Embedding the grammar WASM and driving it via wazero keeps the whole binary static and lets the Go and TypeScript tiers share one grammar artifact. The .wasm bundles the tree-sitter runtime + the M grammar + a thin C shim (see ../wasm); build it with ../wasm/build.sh.
.mac is parsed as M, mechanically the same as .m; non-MUMPS .mac constructs (embedded SQL, preprocessor, ObjectScript) are out of scope (spec §4/§13).
Index ¶
- func GrammarHash() string
- type Capture
- type Match
- type Node
- func (n Node) Child(i uint32) Node
- func (n Node) ChildCount() uint32
- func (n Node) EndByte() uint32
- func (n Node) EndPoint() Point
- func (n Node) FieldNameForChild(i uint32) string
- func (n Node) HasError() bool
- func (n Node) IsError() bool
- func (n Node) IsMissing() bool
- func (n Node) IsNamed() bool
- func (n Node) IsNull() bool
- func (n Node) NamedChild(i uint32) Node
- func (n Node) NamedChildCount() uint32
- func (n Node) SExpr() string
- func (n Node) StartByte() uint32
- func (n Node) StartPoint() Point
- func (n Node) Symbol() uint16
- func (n Node) Text() []byte
- func (n Node) Type() string
- type Parser
- type Point
- type Query
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GrammarHash ¶
func GrammarHash() string
GrammarHash is the sha256 of the embedded grammar WASM, printed by the consumer's --version for the pin/mirror audit trail (spec §4).
Types ¶
type Match ¶
Match is one match of a query pattern: the pattern's index plus its captures in capture order.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a handle to a node in a Tree. It is a value type but refers back to the owning Tree; it stays valid until the Tree is closed.
func (Node) ChildCount ¶
ChildCount is the number of children (named and anonymous tokens).
func (Node) FieldNameForChild ¶
FieldNameForChild is the grammar field name (e.g. "name") under which child i sits, or "" if the child is not in a field.
func (Node) HasError ¶
HasError reports whether the node or any descendant is an error/missing node.
func (Node) IsNamed ¶
IsNamed reports whether the node is a named (rule) node vs. an anonymous token.
func (Node) IsNull ¶
IsNull reports whether the handle is the tree-sitter null node (e.g. an out-of-range Child index).
func (Node) NamedChild ¶
NamedChild returns the i-th named child (skips anonymous tokens).
func (Node) NamedChildCount ¶
NamedChildCount is the number of named (rule) children, skipping tokens.
func (Node) StartPoint ¶
StartPoint is the node's start position as a row/column point.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser owns one wazero instance of the grammar WASM. Parse and the Node/Tree accessors funnel through it; wazero modules are not reentrant, so every WASM-touching operation holds mu. Construct with New; release with Close. One Parser can produce many Trees sequentially.
func New ¶
New instantiates the embedded grammar WASM in a fresh wazero runtime (pure-Go, CGO_ENABLED=0). The ctx is retained for subsequent WASM calls.
func (*Parser) GrammarABIVersion ¶
GrammarABIVersion is the tree-sitter language ABI version of the embedded grammar.
func (*Parser) NewQuery ¶
NewQuery compiles a tree-sitter query against the M grammar. A compile error is returned with its kind and byte offset.
func (*Parser) Parse ¶
Parse parses src as a fresh M document and returns its syntax tree. A tree with syntax errors is returned normally (inspect via Node.HasError); only a total grammar failure yields an error. The caller should Close the Tree.
func (*Parser) SymbolCount ¶
SymbolCount is the number of grammar symbols (rules + tokens).
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a compiled tree-sitter query against the M grammar. Compile one with Parser.NewQuery, run it over a Node with Matches, and Close it when done. Queries use tree-sitter's S-expression pattern syntax with @captures, e.g.
(command (command_keyword) @kw)
This is the substrate lint/lsp build their rules on (spec §4/§6).
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a parsed syntax tree. It owns the WASM-side tree plus every node handle produced from it; Close frees them all. A Tree is valid only while its Parser is open, and is not safe for concurrent use.