diag

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package diag contains building blocks for formatting and processing diagnostic information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Complain

func Complain(msg string)

Complain prints a message to stderr in bold and red, adding a trailing newline.

func Complainf

func Complainf(format string, args ...interface{})

Complainf is like Complain, but accepts a format string and arguments.

func PPrintError

func PPrintError(err error)

PPrintError pretty-prints an error. It uses the PPrint method if the error implements PPrinter, and uses Complain to print the error message otherwise.

Types

type Context

type Context struct {
	Name   string
	Source string
	Ranging
	// contains filtered or unexported fields
}

Context is a range of text in a source code. It is typically used for errors that can be associated with a part of the source code, like parse errors and a traceback entry.

func NewContext

func NewContext(name, source string, from, to int) *Context

NewContext creates a new Context.

func (*Context) PPrint

func (c *Context) PPrint(sourceIndent string) string

PPrint pretty-prints a SourceContext.

func (*Context) PPrintCompact

func (c *Context) PPrintCompact(sourceIndent string) string

PPrintCompact pretty-prints a SourceContext, with no line break between the source position range description and relevant source excerpt.

type Error

type Error struct {
	Type    string
	Message string
	Context Context
}

Error represents an error with context that can be pretty-printed.

func (*Error) Error

func (e *Error) Error() string

Error returns a plain text representation of the error.

func (*Error) PPrint

func (e *Error) PPrint(indent string) string

PPrint pretty-prints the error.

func (*Error) Range

func (e *Error) Range() Ranging

Range returns the range of the error.

type Ranger

type Ranger interface {
	// Range returns the range associated with the value.
	Range() Ranging
}

Ranger wraps the Range method.

type Ranging

type Ranging struct {
	From int
	To   int
}

Ranging represents a range [From, To) within an indexable sequence. Structs can embed Ranging to satisfy the Ranger interface.

func (Ranging) Range

func (r Ranging) Range() Ranging

Range returns the Ranging itself.

Jump to

Keyboard shortcuts

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