ast

package
v0.0.0-...-de5ff62 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block []Node

Block is the top most unit in a TextML document, it's an alias to a slice of [Node]s for easy construction.

func Compile

func Compile(block *parser.Block) Block

Compile a *parser.Block into a Block instance (for now just strips token information).

func (Block) FirstElement

func (b Block) FirstElement() *ElementNode

FirstElement returns the first ast.ElementNode in this block or nil otherwise.

func (Block) TextContent

func (b Block) TextContent() string

TextContent concatenates all ast.TextNode text in this block (for now [ast.ElementNode]s are skipped)

func (Block) Walk

func (b Block) Walk(visitFunc func(Node) error) error

WalkNodes walks the AST using depth-first pre-order traversal (first the visit the node itself and then all its children). The traversal finishes if the visit function returns a non nil error.

func (Block) WalkTypes

func (b Block) WalkTypes(
	visitElemFunc func(*ElementNode) error,
	visitTextFunc func(*TextNode) error,
) error

WalkTypes calls the right visit function based on node type. For traversal information see ast.Walk.

type ElementNode

type ElementNode struct {
	Name      string
	Arguments []Block
}

ElementNode represents an element node with its block arguments

func (*ElementNode) MarshalJSON

func (n *ElementNode) MarshalJSON() ([]byte, error)

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node is an abstract syntax tree representation of the TextML without the parsing information and mostly used during transformations.

type TextNode

type TextNode struct {
	Text string
}

TextNode represents a text node

func (*TextNode) MarshalJSON

func (n *TextNode) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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