parser

package
v0.0.0-...-586e974 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicError

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

func (*BasicError) Column

func (be *BasicError) Column() int

func (*BasicError) Description

func (be *BasicError) Description() string

func (*BasicError) Error

func (be *BasicError) Error() string

func (*BasicError) Line

func (be *BasicError) Line() int

type BasicReader

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

func (*BasicReader) Len

func (p *BasicReader) Len() int

func (*BasicReader) LineCol

func (p *BasicReader) LineCol(offset int) (line, column int)

func (*BasicReader) Pos

func (p *BasicReader) Pos() int

func (*BasicReader) Read

func (p *BasicReader) Read() rune

func (*BasicReader) Seek

func (p *BasicReader) Seek(n int)

func (*BasicReader) Substring

func (p *BasicReader) Substring(start, end int) string

func (*BasicReader) UnRead

func (p *BasicReader) UnRead()

type DataSource

type DataSource interface {
	// Returns the data between the start and end indices
	Data(start, end int) string
}

Generic DataSource interface

type Error

type Error interface {
	Line() int
	Column() int
	Description() string
	Error() string
}

func NewError

func NewError(line, column int, description string) Error

type Node

type Node struct {
	// The Range this node occupies, as referenced to the DataSource.
	Range text.Region
	// The Name of this node.
	Name string
	// The Children of this Node.
	Children []*Node
	// The DataSource to query when Node.Data is called.
	P DataSource
}

Node is the base structure used to represent a directed acyclic graph

func (*Node) Adjust

func (n *Node) Adjust(position, delta int)

Adjusts this node's range and that of its children at "position" by "delta".

func (*Node) Append

func (n *Node) Append(child *Node)

Append node "child" at the end of this node's Children slice.

func (*Node) Cleanup

func (n *Node) Cleanup(pos, end int) *Node

Cleanup is different from Discard in that it returns a new Node containing the Children whose Range are within the region of "pos" and "end".

The receiver Node "n" will be the same as if we had called n.Discard(pos).

Child-nodes starting after "end" will be in neither "n" nor the new returned Node.

func (*Node) Clone

func (n *Node) Clone() *Node

Clones this node-sub tree

func (*Node) Data

func (n *Node) Data() string

Queries the DataSource and returns the data for this Node's Range.

func (*Node) Discard

func (n *Node) Discard(pos int)

Discards child nodes whose Range starts after "pos"

func (*Node) Simplify

func (n *Node) Simplify()

Simplify this sub-tree by merging children into the parent where the parent only has a single child and the parent and child occupy the exact same Range.

func (*Node) String

func (n *Node) String() string

String-function to satisfy the fmt.Stringer interface. Returns an indented string representation of this node and its sub-tree.

To get the Data contained within this node, use #Data instead.

func (*Node) UpdateRange

func (n *Node) UpdateRange() text.Region

UpdateRange makes sure that all parent nodes ranges contain their children.

type Parser

type Parser interface {
	Parse() (*Node, error)
}

The Parser interface is responsible for creating a Node structure of a given text data.

type Reader

type Reader interface {
	Len() int
	Pos() int
	Read() rune
	UnRead()
	LineCol(offset int) (line, col int)
	Substring(start, end int) string
	Seek(offset int)
}

func NewReader

func NewReader(data string) Reader

type SyntaxHighlighter

type SyntaxHighlighter interface {
	// Adjust is called when the underlying text buffer changes at "position"
	// with a change of "delta" characters either being inserted or removed.
	//
	// See note above regarding "monkey patching".
	Adjust(position, delta int)

	// Returns the Region of the inner most Scope extent which contains "point".
	//
	// This method can be called a lot by plugins, and should therefore be as
	// fast as possible.
	ScopeExtent(point int) text.Region

	// Returns the full concatenated nested scope name of the scope(s) containing "point".
	//
	// This method can be called a lot by plugins, and should therefore be as
	// fast as possible.
	ScopeName(point int) string

	// Flatten creates a map where the key is the concatenated nested scope names
	// and the key is the render.ViewRegions associated with that key.
	//
	// This function is only called once by the View, which merges
	// the regions into its own region map and adjusts them as appropriate.
	Flatten() render.ViewRegionMap
}

The SyntaxHighlighter interface is responsible for identifying the extent and name of code scopes given a position in the code buffer this specific SyntaxHighlighter is responsible for.

It's expected that the syntax highlighter monkey patches its existing scope data rather than performing a full reparse when the underlying buffer changes.

This is because a full reparse, for which the Parser interface is responsible, will be going on in parallel in a separate thread and the "monkey patch" will allow some accuracy in the meantime until the Parse operation has finished.

func NewSyntaxHighlighter

func NewSyntaxHighlighter(p Parser) (SyntaxHighlighter, error)

Creates a new default implementation of SyntaxHighlighter operating on the AST created by "p"'s Parse().

Jump to

Keyboard shortcuts

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