ast

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 0 Imported by: 1

Documentation

Overview

Package ast defines the abstract syntax tree node types used by parsers. It provides a common Node interface that all AST nodes implement, allowing uniform traversal of syntax trees.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(node Node, fn WalkFunc) error

Walk traverses the AST starting from the given node, calling fn for each node in depth-first pre-order (parent before children). The depth parameter indicates how deep in the tree the current node is (0 for the root). If fn returns an error, walking stops and that error is returned.

Types

type Kind

type Kind uint

Kind identifies the type of an AST node. Each node in the syntax tree has a Kind that describes what it represents, such as a document, paragraph, heading, or inline formatting like emphasis.

const (
	Any Kind = iota
	Attr
	Block
	BlockList
	Ident
	Label
	List
	Map
	Ref
	String

	// Markdown kinds
	Document
	Paragraph
	Heading
	CodeBlock
	Blockquote
	ListItem
	Text
	Emphasis       // *italic* or _italic_
	Strong         // **bold** or __bold__
	Strikethrough  // ~~deleted~~
	Code           // `code`
	Link           // [text](url)
	Image          // ![alt](url)
	HorizontalRule // --- or *** or ___
	LineBreak
)

func (Kind) String

func (k Kind) String() string

type Node

type Node interface {
	// Kind returns the type of this node (e.g., Document, Paragraph, Text).
	Kind() Kind

	// Children returns the immediate child nodes of this node.
	// Leaf nodes (like Text) return nil.
	Children() []Node
}

Node is the interface implemented by all AST nodes. It provides methods for inspecting the node's type and accessing child nodes.

type WalkFunc

type WalkFunc func(node Node, depth int) error

WalkFunc is the function signature for the callback used by Walk. It receives the current node and its depth in the tree (0 for root). Return an error to stop walking, or nil to continue.

Jump to

Keyboard shortcuts

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