gleanerrors

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package gleanerrors contains types used to report errors from parsers generated by glean.

Although default error messages are provided, these will likely be unsatisfactory in practice. A program using a glean parser can likely produce better messages based on the context in which the parser is used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ambiguous

type Ambiguous struct {
	// The range in which the ambiguity occurs.
	Range

	// Two of the rules that could be applied in valid parses. Possibly identical.
	//
	// These rules will have the same target symbol, and will apply to the
	// subsequence of tokens inside the parser input; this subsequence may
	// be larger than indicated in Range.
	Rule1, Rule2 Rule
}

There were multiple matches of a symbol to a range of input tokens.

Only two matches are reported. It is possible for Rule1 and Rule2 to be identical, if a single rule can be applied in multiple ways.

func (Ambiguous) Error

func (e Ambiguous) Error() string

Default error message for Ambiguous.

type Location

type Location struct {
	// The index of the token within the slice given to the parser.
	Index int

	// The token itself.
	Token interface{}
}

Location identifies a single token in the input passed to a parse function.

func MakeLocation

func MakeLocation(tokens []interface{}, n int) Location

MakeLocation returns the Location for a specific token.

In edge cases, n might be -1 or len(tokens); if so, a nil token is used.

type NoInput

type NoInput struct{}

The tokens slice passed to a parse function had length 0.

func (NoInput) Error

func (_ NoInput) Error() string

Default error message for NoInput.

type Range

type Range struct {
	First, Last Location
}

Range indicates the position of an error that may span multiple tokens.

If the range is empty, Last.Index will be First.Index - 1; if this means Last.Index is -1, then Last.Token will be nil.

func MakeRange

func MakeRange(tokens []interface{}, first, last int) Range

MakeRange creates a Range from a list of input tokens and the position of the range.

type Rule

type Rule struct {
	Name   string
	Target string
	Items  []string
}

Rule represents a rule from the grammar being parsed.

type Unexpected

type Unexpected struct {
	// The token found in the input.
	Location
}

A token did not match any rule expected at its position in the input.

This is also returned when the parser input ends prematurely, without forming a valid match for the target symbol. In this case, Location.Index will be the length of the input, and Location.Token will be nil.

Currently, the list of symbols valid at this point in the input is not returned. This may or may not be added in future.

func (Unexpected) Error

func (e Unexpected) Error() string

Default error message for Unexpected.

Jump to

Keyboard shortcuts

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