renderer

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 5 Imported by: 377

Documentation

Overview

Package renderer renders the given AST to certain formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Options       map[OptionName]interface{}
	NodeRenderers util.PrioritizedSlice
}

A Config struct is a data structure that holds configuration of the Renderer.

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config.

type NodeRenderer

type NodeRenderer interface {
	// RendererFuncs registers NodeRendererFuncs to given NodeRendererFuncRegisterer.
	RegisterFuncs(NodeRendererFuncRegisterer)
}

A NodeRenderer interface offers NodeRendererFuncs.

type NodeRendererFunc

type NodeRendererFunc func(writer util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error)

NodeRendererFunc is a function that renders a given node.

type NodeRendererFuncRegisterer

type NodeRendererFuncRegisterer interface {
	// Register registers given NodeRendererFunc to this object.
	Register(ast.NodeKind, NodeRendererFunc)
}

A NodeRendererFuncRegisterer registers given NodeRendererFunc to this object.

type Option

type Option interface {
	SetConfig(*Config)
}

An Option interface is a functional option type for the Renderer.

func WithNodeRenderers

func WithNodeRenderers(ps ...util.PrioritizedValue) Option

WithNodeRenderers is a functional option that allow you to add NodeRenderers to the renderer.

func WithOption

func WithOption(name OptionName, value interface{}) Option

WithOption is a functional option that allow you to set an arbitrary option to the parser.

type OptionName

type OptionName string

An OptionName is a name of the option.

type Renderer

type Renderer interface {
	Render(w io.Writer, source []byte, n ast.Node) error

	// AddOptions adds given option to this renderer.
	AddOptions(...Option)
}

A Renderer interface renders given AST node to given writer with given Renderer.

func NewRenderer

func NewRenderer(options ...Option) Renderer

NewRenderer returns a new Renderer with given options.

type SetOptioner

type SetOptioner interface {
	// SetOption sets given option to the object.
	// Unacceptable options may be passed.
	// Thus implementations must ignore unacceptable options.
	SetOption(name OptionName, value interface{})
}

A SetOptioner interface sets given option to the object.

Directories

Path Synopsis
Package html implements renderer that outputs HTMLs.
Package html implements renderer that outputs HTMLs.

Jump to

Keyboard shortcuts

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