cst

package
v1.7.0-dev-20191011 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2019 License: Apache-2.0 Imports: 5 Imported by: 96

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	NodeBase
	// Children is the slice of child nodes for this Branch.
	Children []Node
}

Branch is a CST node that can have children.

func (*Branch) First

func (n *Branch) First() Node

First returns the first child of the branch, or nil if the branch has no children.

func (*Branch) Last

func (n *Branch) Last() Node

Last returns the last child of the branch, or nil if the branch has no children.

func (*Branch) Tok

func (n *Branch) Tok() Token

Tok returns the underlying token of this node.

func (*Branch) Write

func (n *Branch) Write(w io.Writer) error

Write writes the branch node to the writer w.

type Fragment

type Fragment interface {
	// Tok returns the underlying token of this fragment.
	Tok() Token
	// Write is used to write the underlying token out to the writer.
	Write(io.Writer) error
}

Fragment is a component of a cst that is backed by a token. This includes Nodes and all forms of space and comment.

type Leaf

type Leaf struct {
	Token
	NodeBase
}

Leaf nodes are part of the cst that cannot have child nodes, they represent a single token from the input.

func (*Leaf) Write

func (n *Leaf) Write(w io.Writer) error

Write writes the leaf node to the writer w.

type Node

type Node interface {
	Fragment
	// Parent returns the Branch that this node is under.
	Parent() *Branch
	// SetParent replaces the Branch that this node is under.
	SetParent(*Branch)
	// Prefix returns the set of skippable fragments associated with this Node
	// that precede it in the stream. Association is defined by the Skip function
	// in use.
	Prefix() Separator
	// AddPrefix adds more fragments to the Prefix list.
	AddPrefix(Separator)
	// Suffix returns the set of skippable fragments associated with this Node
	// that follow it in the stream. Association is defined by the Skip function
	// in use, the default is until the end of the line.
	Suffix() Separator
	// AddSuffix adds more fragments to the Suffix list.
	AddSuffix(Separator)
}

Node is a Fragment in a cst that represents unskipped tokens.

type NodeBase

type NodeBase struct {
	Branch *Branch
	Pre    Separator
	Post   Separator
}

NodeBase implements the non-fragment parts of the Node interface. NodeBase is intended to be used as an anonymous field of types that implement the Node interface.

func (*NodeBase) AddPrefix

func (n *NodeBase) AddPrefix(s Separator)

AddPrefix adds more fragments to the Prefix list.

func (*NodeBase) AddSuffix

func (n *NodeBase) AddSuffix(s Separator)

AddSuffix adds more fragments to the Suffix list.

func (*NodeBase) Parent

func (n *NodeBase) Parent() *Branch

Parent returns the Branch that this node is under.

func (*NodeBase) Prefix

func (n *NodeBase) Prefix() Separator

Prefix returns the set of skippable fragments associated with this Node that precede it in the stream. Association is defined by the Skip function in use.

func (*NodeBase) SetParent

func (n *NodeBase) SetParent(parent *Branch)

SetParent replaces the Branch that this node is under.

func (*NodeBase) Suffix

func (n *NodeBase) Suffix() Separator

Suffix returns the set of skippable fragments associated with this Node that follow it in the stream. Association is defined by the Skip function in use, the default is until the end of the line.

type Separator

type Separator []Fragment

Separator is a list type to manage fragments that were skipped.

func (Separator) Write

func (s Separator) Write(w io.Writer) error

Write is used to write the list of separators to the writer.

type Source

type Source struct {
	Filename string // The path which was used to load the source (if any).
	Runes    []rune // The full content of the source file.
}

Source represents a source file.

func (Source) RelativeFilename

func (s Source) RelativeFilename() string

RelativeFilename returns the filename relative to the current working directory.

type Token

type Token struct {
	Source *Source // The source object this token is from (including the full rune array).
	Start  int     // The start of the token in the full rune array.
	End    int     // One past the end of the token.
}

A Token represents the smallest consumed unit input.

func (Token) At

func (t Token) At() string

At returns the token's location in the form: filename:line:column

func (Token) Cursor

func (t Token) Cursor() (line int, column int)

Cursor is used to calculate the line and column of the start of the token. It may be very expensive to call, and is intended to be used sparingly in producing human readable error messages only.

func (Token) Format

func (t Token) Format(f fmt.State, c rune)

Format implements fmt.Formatter writing the start end and value of the token.

func (Token) Len

func (t Token) Len() int

Len returns the length of the token in runes.

func (Token) Less

func (t Token) Less(rhs Token) bool

Less returns true if t comes before rhs when considering source files and offsets within the same file.

func (Token) String

func (t Token) String() string

String returns the string form of the rune range the token represents.

func (Token) Tok

func (t Token) Tok() Token

Tok returns t.

func (Token) Write

func (t Token) Write(w io.Writer) error

Write writes the token to the writer.

Jump to

Keyboard shortcuts

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