compilercommon

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: BSD-3-Clause Imports: 4 Imported by: 21

Documentation

Overview

Package compilercommon defines common types and their functions shared across the compiler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeSummary

type CodeSummary struct {
	// Documentation is the documentation string for the code summary, if any.
	Documentation string

	// Code is the code-view of the summarized entity.
	Code string

	// HasDeclaredType returns whether the code summary's code entry already contains a type.
	HasDeclaredType bool
}

CodeSummary holds the code and optional documentation of a member, parameter or other entity in the compiler. Used by IDE tooling for human-readable summarization.

type InputSource

type InputSource string

InputSource represents the path of a source file.

func (InputSource) PositionForRunePosition

func (is InputSource) PositionForRunePosition(runePosition int, mapper PositionMapper) SourcePosition

PositionForRunePosition returns a source position over this source file.

func (InputSource) PositionFromLineAndColumn

func (is InputSource) PositionFromLineAndColumn(lineNumber int, columnPosition int, mapper PositionMapper) SourcePosition

PositionFromLineAndColumn returns a source position at the given line and column in this source file.

func (InputSource) RangeForLineAndColPositions

func (is InputSource) RangeForLineAndColPositions(start Position, end Position, mapper PositionMapper) SourceRange

RangeForLineAndColPositions returns a source range over this source file.

func (InputSource) RangeForRunePosition

func (is InputSource) RangeForRunePosition(runePosition int, mapper PositionMapper) SourceRange

RangeForRunePosition returns a source range over this source file.

func (InputSource) RangeForRunePositions

func (is InputSource) RangeForRunePositions(startRune int, endRune int, mapper PositionMapper) SourceRange

RangeForRunePositions returns a source range over this source file.

type LocalFilePositionMapper

type LocalFilePositionMapper struct{}

LocalFilePositionMapper is a struct which implements the PositionMapper interface over the local file system. Note that since accesses in this struct are *not* cached, this instance should *only* be used for testing.

func (LocalFilePositionMapper) LineAndColToRunePosition

func (pm LocalFilePositionMapper) LineAndColToRunePosition(lineNumber int, colPosition int, path InputSource, sourceOption SourceMappingOption) (int, error)

func (LocalFilePositionMapper) RunePositionToLineAndCol

func (pm LocalFilePositionMapper) RunePositionToLineAndCol(runePosition int, path InputSource, sourceOption SourceMappingOption) (int, int, error)

func (LocalFilePositionMapper) TextForLine

func (pm LocalFilePositionMapper) TextForLine(lineNumber int, path InputSource, sourceOption SourceMappingOption) (string, error)

type Position

type Position struct {
	// LineNumber is the 0-indexed line number.
	LineNumber int

	// ColumnPosition is the 0-indexed column position on the line.
	ColumnPosition int
}

Position represents a position in an arbitrary source file.

type PositionMapper

type PositionMapper interface {
	// RunePositionToLineAndCol converts the given 0-indexed rune position under the given source file
	// into a 0-indexed line number and column position.
	RunePositionToLineAndCol(runePosition int, path InputSource, sourceOption SourceMappingOption) (int, int, error)

	// LineAndColToRunePosition converts the given 0-indexed line number and column position under the
	// given source file into a 0-indexed rune position.
	LineAndColToRunePosition(lineNumber int, colPosition int, path InputSource, sourceOption SourceMappingOption) (int, error)

	// TextForLine returns the text for the specified line number.
	TextForLine(lineNumber int, path InputSource, sourceOption SourceMappingOption) (string, error)
}

PositionMapper defines an interface for converting rune position <-> line+col position under source files.

type SourceError

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

SourceError represents an error produced by a source file at a specific range.

func NewSourceError

func NewSourceError(sourceRange SourceRange, msg string) SourceError

NewSourceError returns a new SourceError for the given range and message.

func SourceErrorf

func SourceErrorf(sourceRange SourceRange, msg string, args ...interface{}) SourceError

SourceErrorf returns a new SourceError for the given range and message.

func (SourceError) Error

func (se SourceError) Error() string

func (SourceError) SourceRange

func (se SourceError) SourceRange() SourceRange

SourceRange returns the range of this error.

func (SourceError) String

func (se SourceError) String() string

type SourceMappingOption

type SourceMappingOption int

SourceMappingOption defines the options for whichn source to use when position mapping.

const (
	// SourceMapTracked indicates that position mapping should occur over the *tracked* source
	// contents. This is the default.
	SourceMapTracked SourceMappingOption = iota

	// SourceMapCurrent indicates that position mapping should occur over the *current* source
	// contents. This should only be used by tooling, and is likely to fail in certain cases
	// where positions have gotten desynced.
	SourceMapCurrent
)

type SourcePosition

type SourcePosition interface {
	// Source is the input source for this position.
	Source() InputSource

	// RunePosition returns the 0-indexed rune position in the source file.
	RunePosition() (int, error)

	// LineAndColumn returns the 0-indexed line number and column position in the source file.
	LineAndColumn() (int, int, error)

	// LineText returns the text of the line for this position.
	LineText() (string, error)

	// String returns a (somewhat) human-readable form of the position.
	String() string
}

SourcePosition represents a single position in a source file.

type SourcePositionMapper

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

SourcePositionMapper defines a helper struct for cached, faster lookup of rune position <-> (line, column) for a specific source file.

func CreateSourcePositionMapper

func CreateSourcePositionMapper(contents []byte) SourcePositionMapper

CreateSourcePositionMapper returns a source position mapper for the contents of a source file.

func EmptySourcePositionMapper added in v0.3.2

func EmptySourcePositionMapper() SourcePositionMapper

EmptySourcePositionMapper returns an empty source position mapper.

func (SourcePositionMapper) LineAndColToRunePosition

func (spm SourcePositionMapper) LineAndColToRunePosition(lineNumber int, colPosition int) (int, error)

LineAndColToRunePosition returns the rune position of the line number and column position in source.

func (SourcePositionMapper) RunePositionToLineAndCol

func (spm SourcePositionMapper) RunePositionToLineAndCol(runePosition int) (int, int, error)

RunePositionToLineAndCol returns the line number and column position of the rune position in source.

type SourceRange

type SourceRange interface {
	// Source is the input source for this range.
	Source() InputSource

	// Start is the starting position of the source range.
	Start() SourcePosition

	// End is the ending position (inclusive) of the source range. If the same as the Start,
	// this range represents a single position.
	End() SourcePosition

	// ContainsPosition returns true if the given range contains the given position.
	ContainsPosition(position SourcePosition) (bool, error)

	// AtStartPosition returns a SourceRange located only at the starting position of this range.
	AtStartPosition() SourceRange

	// String returns a (somewhat) human-readable form of the range.
	String() string
}

SourceRange represents a range inside a source file.

type SourceWarning

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

SourceWarning represents an warning produced by a source file at a specific range.

func NewSourceWarning

func NewSourceWarning(sourceRange SourceRange, msg string) SourceWarning

NewSourceWarning returns a new SourceWarning for the given range and message.

func SourceWarningf

func SourceWarningf(sourceRange SourceRange, msg string, args ...interface{}) SourceWarning

SourceWarningf returns a new SourceWarning for the given range and message.

func (SourceWarning) SourceRange

func (sw SourceWarning) SourceRange() SourceRange

SourceRange returns the range of this warning.

func (SourceWarning) String

func (sw SourceWarning) String() string

func (SourceWarning) Warning

func (sw SourceWarning) Warning() string

Warning returns the warning message.

Jump to

Keyboard shortcuts

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