codetree

package module
Version: v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 3 Imported by: 2

README

codetree

Godoc Report Tests Coverage Sponsor

Parses indented code (Python, Pug, Stylus, Pixy, codetree, etc.) and returns a tree structure.

Installation

go get github.com/aerogo/codetree

Usage

tree, err := codetree.New(reader)
defer tree.Close()

Input

parent1
	child1
	child2
	child3
		child3.1
		child3.2
	child4

parent2
	child1

Output

See CodeTree structure.

The root node always starts with Indent being -1.

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeTree

type CodeTree struct {
	Line     string
	Children []*CodeTree
	Parent   *CodeTree
	Indent   int
}

CodeTree represents a tree structure for whitespace-significant, indented code. Each line of code is parsed and the indentation level of the line is stored in Indent. The root node having Indent set to -1 contains child nodes that can contain child nodes themselves, recursively. Each line is saved without whitespace characters at the start of the string.

func New

func New(reader io.Reader) (*CodeTree, error)

New returns a tree structure if you feed it with indentantion based source code.

func (*CodeTree) Close

func (tree *CodeTree) Close()

Close sends the tree and all of its children back to the memory pool. The resources are therefore freed up and the tree object should not be used after the final Close() call anymore.

Source Files

Jump to

Keyboard shortcuts

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