Documentation ¶
Overview ¶
Package diag contains building blocks for formatting and processing diagnostic information.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ContextBodyStartMarker = "\033[1;4m" ContextBodyEndMarker = "\033[m" )
Variables controlling the style used in *Context.Show. Can be overridden in tests.
Functions ¶
func PackErrors ¶ added in v0.20.0
PackErrors packs multiple instances of Error with the same tag into one error:
Types ¶
type Context ¶
type Context struct { Name string Ranging // 1-based line and column numbers of the start position. StartLine, StartCol int // 1-based line and column numbers of the end position, inclusive. Note that // if the range is zero-width, EndCol will be StartCol - 1. EndLine, EndCol int // The relevant text, text before its the first line and the text after its // last line. Body, Head, Tail string }
Context stores information derived from a range in some text. It is used for errors that point to a part of the source code, including parse errors, compilation errors and a single traceback entry in an exception.
Context values should only be constructed using NewContext.
func NewContext ¶
NewContext creates a new Context.
type Error ¶
type Error[T ErrorTag] struct { Message string Context Context // Indicates whether the error may be caused by partial input. More // formally, this field should be true iff there exists a string x such that // appending it to the input eliminates the error. Partial bool }
Error represents an error with context that can be showed.
func UnpackErrors ¶ added in v0.20.0
UnpackErrors returns the constituent Error instances in an error if it is built from PackErrors. Otherwise it returns nil.
type ErrorTag ¶ added in v0.20.0
type ErrorTag interface {
ErrorTag() string
}
ErrorTag is used to parameterize Error into different concrete types. The ErrorTag method is called with a zero receiver, and its return value is used in Error.Error and Error.Show.
type RangeError ¶ added in v0.20.0
RangeError combines error with Ranger.
type Ranger ¶
type Ranger interface { // Range returns the range associated with the value. Range() Ranging }
Ranger wraps the Range method.
type Ranging ¶
Ranging represents a range [From, To) within an indexable sequence. Structs can embed Ranging to satisfy the Ranger interface.
Ideally, this type would be called Range. However, doing that means structs embedding this type will have Range as a field instead of a method, thus not implementing the Ranger interface.
func MixedRanging ¶
MixedRanging returns a Ranging from the start position of a to the end position of b.
func PointRanging ¶
PointRanging returns a zero-width Ranging at the given point.