match

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

match provides a query language for matching nodes in a larkdown.Tree

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyNode

type AnyNode struct {
	BaseNode
}

Matches any node. Useful as a fallback for index matches.

func (AnyNode) Match

func (m AnyNode) Match(node ast.Node, index int, source []byte) bool

func (AnyNode) String

func (m AnyNode) String() string

type BaseNode added in v0.0.1

type BaseNode struct{}

BaseNode partially implements Node, for simpler matchers.

func (BaseNode) EndMatch added in v0.0.1

func (m BaseNode) EndMatch(node ast.Node) bool

func (BaseNode) IsFlatBranch added in v0.0.1

func (m BaseNode) IsFlatBranch() bool

func (BaseNode) NextNode added in v0.0.1

func (m BaseNode) NextNode(self ast.Node) ast.Node

type Branch

type Branch struct {
	// The heading level to match, or 0 to match any level.
	Level int
	// The heading name to match, or empty to match any name.
	Name []byte
	// If true, the name is matched case-insensitively.
	CaseInsensitive bool
}

Branch matches a heading by level and name, and returns its siblings until the next heading of the same or higher level.

func (Branch) EndMatch added in v0.0.1

func (m Branch) EndMatch(node ast.Node) bool

A heading branch ends when the next heading is of the same or higher level.

func (Branch) IsFlatBranch added in v0.0.1

func (m Branch) IsFlatBranch() bool

Headings are branches whose children are siblings until the next heading.

func (Branch) Match

func (m Branch) Match(node ast.Node, index int, source []byte) bool

Match a heading by level and name.

func (Branch) NextNode added in v0.0.1

func (m Branch) NextNode(self ast.Node) ast.Node

For headings, the next node is the next sibling.

func (Branch) String

func (m Branch) String() string

type Heading added in v0.0.3

type Heading struct {
	BaseNode

	// The heading level to match, or 0 to match any level.
	Level int
	// The heading name to match, or empty to match any name.
	Name []byte
	// If true, the name is matched case-insensitively.
	CaseInsensitive bool
}

Heading matches a heading by level, to get the title contents directly.

func (Heading) Match added in v0.0.3

func (m Heading) Match(node ast.Node, index int, source []byte) bool

Match matches a heading by level and name.

func (Heading) String added in v0.0.3

func (m Heading) String() string

String prints the heading matcher for debugging.

type Index

type Index struct {
	Index int
	Node  Node
}

Wraps another query, only when it's the nth child of the parent.

func (Index) EndMatch added in v0.0.1

func (m Index) EndMatch(node ast.Node) bool

func (Index) IsFlatBranch added in v0.0.1

func (m Index) IsFlatBranch() bool

func (Index) Match

func (m Index) Match(node ast.Node, index int, source []byte) bool

func (Index) NextNode added in v0.0.1

func (m Index) NextNode(self ast.Node) ast.Node

func (Index) String

func (m Index) String() string

type List

type List struct {
	BaseNode
}

Matches an ordered or unordered list.

func (List) Match

func (m List) Match(node ast.Node, index int, source []byte) bool

Matches List nodes.

func (List) String

func (m List) String() string

type Node

type Node interface {
	// Returns true if the node matches the query.
	Match(node ast.Node, index int, source []byte) (ok bool)
	// Returns true if the node is the end of a flat branch.
	// This is used by headings to note when another heading ends the branch.
	EndMatch(node ast.Node) bool
	// Show the matcher as a string in error messages.
	String() string
	// Returns the next node to match, which usually a child, or for headings a sibling.
	NextNode(self ast.Node) ast.Node
	// True for nodes whose children are actually siblings.
	IsFlatBranch() bool
}

Interface for a node matcher.

type NodeOfKind added in v0.0.1

type NodeOfKind struct {
	BaseNode
	Kind ast.NodeKind
}

Matches against a specific node kind. Used for matching arbitrary nodes, including custom ones.

func (NodeOfKind) Match added in v0.0.1

func (m NodeOfKind) Match(node ast.Node, index int, source []byte) bool

func (NodeOfKind) String added in v0.0.1

func (m NodeOfKind) String() string

type Table added in v0.0.7

type Table struct {
	BaseNode
}

Table matches a table that wraps rows and cells.

func (Table) Match added in v0.0.7

func (m Table) Match(node ast.Node, index int, source []byte) bool

func (Table) String added in v0.0.7

func (m Table) String() string

type Tag added in v0.0.1

type Tag struct {
	BaseNode
}

Matches go.abhg.dev/goldmark/hashtag #tag nodes.

func (Tag) Match added in v0.0.1

func (m Tag) Match(node ast.Node, index int, source []byte) bool

func (Tag) String added in v0.0.1

func (m Tag) String() string

Jump to

Keyboard shortcuts

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