lingo

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2018 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WasOk

func WasOk(_ interface{}, err error) bool

WasOk is a helper function called by generated parser code. It is used to abandon the value result, and return true if there was no error. This is used in cases where the sub-parser is optional and the result is not needed.

func WasScannerError

func WasScannerError(v interface{}) error

Types

type Marker

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

Marker is a stored point in a scanner that can be reset to.

type Node

type Node struct {
	Start    int
	End      int
	Object   interface{}
	Parent   *Node
	Children []*Node
}

Node is the form used when Records are reconstituted into a

func (*Node) Format

func (n *Node) Format(f fmt.State, _ rune)

Format implements fmt.Formatter to print the leaf nodes in depth first order.

type Record

type Record struct {
	Start  int
	End    int
	Object interface{}
}

Record is an entry in a Records list that holds a parse result along with its scan stream bounds.

type Records

type Records []Record

Records is a list of Record objects that represent the ordered sequence of parse results.

func (Records) Format

func (r Records) Format(f fmt.State, _ rune)

Format implements fmt.Formatter to print the full record list.

func (Records) ToCST

func (r Records) ToCST() *Node

ToCST converts from a record list to a node span tree.

type Scanner

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

Scanner is a basic implementation of the functions used by generated parsers. It expects a the full byte slice of the source file.

func NewByteScanner

func NewByteScanner(ctx context.Context, name string, input []byte, records *Records) *Scanner

NewByteScanner builds a scanner over an input byte slice. If records is nil, the cst will not be maintained, otherwise it will be filled in with the parse Record list.

func NewStringScanner

func NewStringScanner(ctx context.Context, name string, input string, records *Records) *Scanner

NewStringScanner builds a scanner over an input string. If records is nil, the cst will not be maintained, otherwise it will be filled in with the parse Record list.

func (*Scanner) EOF

func (s *Scanner) EOF() bool

EOF returns true if the scanner has run out of input.

func (*Scanner) Error

func (s *Scanner) Error(err error, msg string) error

Error wraps an error and message into a new error that knows the scanner stream position.

func (*Scanner) Literal

func (s *Scanner) Literal(str string) (string, error)

Rune is a parser for a literal string. If literal string is next in the stream, the string will be consumed an error will be nil. Otherwise an error will be returned and the value will be the empty string.

func (*Scanner) Mark

func (s *Scanner) Mark() Marker

Mark returns a new marker for the current scan position and state.

func (*Scanner) MustProgress

func (s *Scanner) MustProgress(m Marker) (Marker, error)

MustProgress panics if the marker does not move forwards. Used to catch when the grammar is broken.

func (*Scanner) Pattern

func (s *Scanner) Pattern(re *regexp.Regexp) (string, error)

Pattern is a parser for a regular expression. If the pattern matches the start of the stream, the matching string will be consumed and returned. Otherwise an error will be returned and the value will be the empty string.

func (*Scanner) PreMark

func (s *Scanner) PreMark() Marker

PreMark returns an invalid marker, used for before the start sentinels.

func (*Scanner) Register

func (s *Scanner) Register(start Marker, object interface{})

Register adds a node to the cst from the start marker to the current position.

func (*Scanner) Reset

func (s *Scanner) Reset(start Marker)

Reset puts the scanner back in the state it was when the start Marker was taken.

func (*Scanner) Rune

func (s *Scanner) Rune(r rune) (rune, error)

Rune is a parser for a single rune. If the next rune in the stream is a match, the rune will be consumed an error will be nil. Otherwise an error will be returned. In either case, the requested rune is returned as the value.

func (*Scanner) SetSkip

func (s *Scanner) SetSkip(skipper Skipper) Skipper

SetSkip sets the skip function and returns the old one.

func (*Scanner) Skip

func (s *Scanner) Skip()

Skip invokes the current skip function if one is set.

func (*Scanner) Trace

func (s *Scanner) Trace(msg string)

Trace writes a message to the context at info level

func (*Scanner) Watermark

func (s *Scanner) Watermark() error

Watermark returns the error that was generatd furthest into the parse stream. This is normally included in errors automatically, and often indicates the point where the best match failed, and thus the actual error in the source.

type Skipper

type Skipper func(*Scanner)

Directories

Path Synopsis
examples
Package generator provides the functionality used by the lingo command to add generated parser functionality based on syntactically correct go code.
Package generator provides the functionality used by the lingo command to add generated parser functionality based on syntactically correct go code.

Jump to

Keyboard shortcuts

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