common

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Overview

package common defines types common to parsing and other diagnostics.

package common defines elements common to parsing and other diagnostics.

package common defines types common to parsing and other diagnostics.

package common defines types common to parsing and other diagnostics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Location Location
	Source   Source
	Message  string
}

Error type which references a location within source and a message.

func (*Error) String

func (e *Error) String() string

Stringer implementation that places errors in context with the source.

type Errors

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

Errors type which contains a list of errors observed during parsing.

func NewErrors

func NewErrors() *Errors

Create a new instance of the Errors type.

func (*Errors) GetErrors

func (e *Errors) GetErrors() []Error

Return this list of observed errors.

func (*Errors) ReportError

func (e *Errors) ReportError(s Source, l Location, format string, args ...interface{})

Report an error at a source location.

func (*Errors) String

func (e *Errors) String() string

Convert the error set to a newline delimited string.

type Location

type Location interface {
	GetLine() int   // 1-based line number within source.
	GetColumn() int // 0-based column number within source.
}

Interface to represent a location within Source.

func NewLocation

func NewLocation(line int, column int) Location

Create a new location.

type RawLocation

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

Helper type to manually construct a location.

func (*RawLocation) GetColumn

func (l *RawLocation) GetColumn() int

func (*RawLocation) GetLine

func (l *RawLocation) GetLine() int

type Source

type Source interface {
	// The source content represented as a string, for example a single file,
	// textbox field, or url parameter.
	Content() string

	// Brief description of the source, such as a file name or ui element.
	Description() string

	// The character offsets at which lines occur. The zero-th entry should
	// refer to the break between the first and second line, or EOF if there
	// is only one line of source.
	LineOffsets() []int32

	// The raw character offset at which the a location exists given the
	// location line and column.
	// Returns the line offset and whether the location was found.
	CharacterOffset(location Location) (int32, bool)

	// Return a line of content from the source and whether the line was found.
	Snippet(line int) (string, bool)
}

Interface for filter source contents.

func NewStringSource

func NewStringSource(contents string, description string) Source

Return a new Source given the string contents and description.

type StringSource

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

StringSource type implementation of the Source interface.

func (*StringSource) CharacterOffset

func (s *StringSource) CharacterOffset(location Location) (int32, bool)

func (*StringSource) Content

func (s *StringSource) Content() string

func (*StringSource) Description

func (s *StringSource) Description() string

func (*StringSource) LineOffsets

func (s *StringSource) LineOffsets() []int32

func (*StringSource) Snippet

func (s *StringSource) Snippet(line int) (string, bool)

Jump to

Keyboard shortcuts

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