indenttree

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package indenttree implements a simple text processor which parses a hierarchy defined using indentation; see Parse.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node in a hierarchy returned by Parse.

func Parse

func Parse(input string) ([]Node, error)

Parse a multi-line input string into trees of nodes. For example:

a
 a1
  a11
 a2
b
 b1

is parsed into two Nodes (a and b). Node a has two children (a1, a2), and a2 has one child (a11); node b has one child (b1).

The indentation level is arbitrary but it must be consistent. across nodes. For example, the following is not valid:

a
 a1
b
  b1

Tabs cannot be used for indentation (they can cause confusion if editor settings vary). Nodes cannot be skipped, for example the following is not valid:

a
  a1
    a11
b
    b12

func (*Node) Children

func (n *Node) Children() []Node

Children returns the child nodes, if any.

func (*Node) Value

func (n *Node) Value() string

Value returns the contents of the line for this node (without the indentation).

Jump to

Keyboard shortcuts

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