common

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: Apache-2.0 Imports: 5 Imported by: 58

Documentation

Overview

Package common defines types and utilities common to expression parsing, checking, and interpretation

Index

Constants

This section is empty.

Variables

View Source
var (

	// NoLocation is a particular illegal location.
	NoLocation = &SourceLocation{-1, -1}
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Location Location
	Message  string
}

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

func (*Error) ToDisplayString

func (e *Error) ToDisplayString(source Source) string

ToDisplayString decorates the error message with the source location.

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(source Source) *Errors

NewErrors creates a new instance of the Errors type.

func (*Errors) GetErrors

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

GetErrors returns the list of observed errors.

func (*Errors) ReportError

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

ReportError records an error at a source location.

func (*Errors) ToDisplayString

func (e *Errors) ToDisplayString() string

ToDisplayString returns the error set to a newline delimited string.

type Location

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

Location interface to represent a location within Source.

func NewLocation

func NewLocation(line, column int) Location

NewLocation creates a new location.

type Source

type Source interface {
	// Content returns the source content represented as a string.
	// Examples contents are the single file contents, textbox field,
	// or url parameter.
	Content() string

	// Description gives a brief description of the source.
	// Example descriptions are a file name or ui element.
	Description() string

	// LineOffsets gives 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

	// LocationOffset translates a Location to an offset.
	// Given the line and column of the Location returns the
	// Location's character offset in the Source, and a bool
	// indicating whether the Location was found.
	LocationOffset(location Location) (int32, bool)

	// OffsetLocation translates a character offset to a Location, or
	// false if the conversion was not feasible.
	OffsetLocation(offset int32) (Location, bool)

	// Snippet returns a line of content and whether the line was found.
	Snippet(line int) (string, bool)

	// IDOffset returns the raw character offset of an expression within
	// the source, or false if the expression cannot be found.
	IDOffset(exprID int64) (int32, bool)

	// IDLocation returns a Location for the given expression id,
	// or false if one cannot be found.  It behaves as the obvious
	// composition of IdOffset() and OffsetLocation().
	IDLocation(exprID int64) (Location, bool)
}

Source interface for filter source contents.

func NewInfoSource

func NewInfoSource(info *exprpb.SourceInfo) Source

NewInfoSource creates a new Source from a SourceInfo.

func NewStringSource

func NewStringSource(contents string, description string) Source

NewStringSource creates a new Source from the given contents and description.

func NewTextSource

func NewTextSource(text string) Source

NewTextSource creates a new Source from the input text string.

type SourceLocation

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

SourceLocation helper type to manually construct a location.

func (*SourceLocation) Column

func (l *SourceLocation) Column() int

Column returns the 0-based column number of the location.

func (*SourceLocation) Line

func (l *SourceLocation) Line() int

Line returns the 1-based line of the location.

Directories

Path Synopsis
Package debug provides tools to print a parsed expression graph and adorn each expression element with additional metadata.
Package debug provides tools to print a parsed expression graph and adorn each expression element with additional metadata.
Package operators defines the internal function names of operators.
Package operators defines the internal function names of operators.
Package overloads defines the internal overload identifiers for function and operator overloads.
Package overloads defines the internal overload identifiers for function and operator overloads.
Package packages defines types for interpreting qualified names.
Package packages defines types for interpreting qualified names.
Package types contains the types, traits, and utilities common to all components of expression handling.
Package types contains the types, traits, and utilities common to all components of expression handling.
pb
Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup.
Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup.
ref
Package ref contains the reference interfaces used throughout the types components.
Package ref contains the reference interfaces used throughout the types components.
traits
Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch.
Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch.

Jump to

Keyboard shortcuts

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