memo

package
v0.0.0-...-7534ea8 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capture

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

func NewCaptureDummy

func NewCaptureDummy(start, length int, children []*Capture) *Capture

func NewCaptureNode

func NewCaptureNode(id int, start, length int, children []*Capture) *Capture

func (*Capture) Child

func (c *Capture) Child(n int) *Capture

func (*Capture) ChildIterator

func (c *Capture) ChildIterator(start int) func() *Capture

func (*Capture) Dummy

func (c *Capture) Dummy() bool

func (*Capture) End

func (c *Capture) End() int

func (*Capture) Id

func (c *Capture) Id() int

func (*Capture) Len

func (c *Capture) Len() int

func (*Capture) NumChildren

func (c *Capture) NumChildren() int

func (*Capture) Start

func (c *Capture) Start() int

func (*Capture) String

func (c *Capture) String() string

String returns a readable string representation of this node, showing the ID of this node and its children.

type Edit

type Edit struct {
	Start, End int
	Len        int
}

An Edit represents a modification to the subject string where the interval [Start, End) is modified to be Len bytes. If Len = 0, this is equivalent to deleting the interval, and if Start = End this is an insertion.

type Entry

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

An Entry represents a memoized parse result. It stores the non-terminal memoized, the start position of the parse result, the length, and the number of characters examined to make the parse determination. If the length is -1, the non-terminal failed to match at this location (but still may have examined a non-zero number of characters).

func (*Entry) Captures

func (e *Entry) Captures() []*Capture

Captures returns the captures that occurred within this memoized parse result.

func (*Entry) Count

func (e *Entry) Count() int

func (*Entry) Examined

func (e *Entry) Examined() int

func (*Entry) Length

func (e *Entry) Length() int

Length returns the number of characters memoized by this entry.

func (*Entry) Pos

func (e *Entry) Pos() int

Pos returns this entry's starting position.

type NoneTable

type NoneTable struct{}

NoneTable implements a memoization table that does nothing.

func (NoneTable) AllValues

func (t NoneTable) AllValues() []*Entry

func (NoneTable) ApplyEdit

func (t NoneTable) ApplyEdit(e Edit)

func (NoneTable) Get

func (t NoneTable) Get(id, pos int) (*Entry, bool)

Get always returns 'not found'

func (NoneTable) Overlaps

func (t NoneTable) Overlaps(low, high int) []*Entry

func (NoneTable) Put

func (t NoneTable) Put(id, start, length, examined, count int, captures []*Capture)

func (NoneTable) Size

func (t NoneTable) Size() int

type Table

type Table interface {
	// Get returns the entry associated with the given position and ID. If
	// there are multiple entries with the same ID at that position, the
	// largest entry is returned (determined by matched length).
	Get(id, pos int) (*Entry, bool)

	// Put adds a new entry to the table.
	Put(id, start, length, examined, count int, captures []*Capture)

	// ApplyEdit updates the table as necessary when an edit occurs. This
	// operation invalidates all entries within the range of the edit and
	// shifts entries that are to the right of the edit as necessary.
	ApplyEdit(Edit)

	AllValues() []*Entry

	// Size returns the number of entries in the table.
	Size() int
}

A Table is an interface for a memoization table data structure. The memoization table tracks memoized parse results corresponding to a non-terminal parsed at a certain location. The table interface defines the ApplyEdit function which is crucial for incremental parsing.

type TreeTable

type TreeTable struct {
	interval.Map
	// contains filtered or unexported fields
}

TreeTable implements a memoization table using an interval tree (augmented to support efficient shifting).

func NewTreeTable

func NewTreeTable(threshold int) *TreeTable

func (*TreeTable) AllValues

func (t *TreeTable) AllValues() []*Entry

func (*TreeTable) ApplyEdit

func (t *TreeTable) ApplyEdit(e Edit)

func (*TreeTable) Get

func (t *TreeTable) Get(id, pos int) (*Entry, bool)

func (*TreeTable) Put

func (t *TreeTable) Put(id, start, length, examined, count int, captures []*Capture)

Directories

Path Synopsis
lazy
Package lazy provides an interval tree backed by an AVL tree.
Package lazy provides an interval tree backed by an AVL tree.
lazylog
Package lazylog provides an interval tree backed by an AVL tree.
Package lazylog provides an interval tree backed by an AVL tree.

Jump to

Keyboard shortcuts

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