Package sxir/pkg/runtime/input

import "syntaxir.dev/sxir/pkg/runtime/input"

Overview

Package input defines how a parse sees its input: the position unit of offsets, source locations, the text edits of a Document and the kinds of its change notifications.

Index

Types

type DocumentChangeKind source

type DocumentChangeKind string

DocumentChangeKind is the kind of a Document change notification.

const (
	// ChangeEdit is an accepted edit of the text.
	ChangeEdit DocumentChangeKind = "edit"
	// ChangeOutcome is the outcome of a parse compared with the previous one.
	ChangeOutcome DocumentChangeKind = "outcome"
	// ChangeFullRefresh tells consumers to rebuild from the latest snapshot instead of replaying
	// edits.
	ChangeFullRefresh DocumentChangeKind = "full-refresh"
)

type Location source

type Location struct {
	Pos  int `json:"pos"`
	Line int `json:"line"`
	Col  int `json:"col"`
}

Location is a position with its line and column.

func (Location) String source

func (l Location) String() string

String returns line:col, or "position N" when the line is unknown (Line is 0; see TraceEvent.LineCol).

type OutputChange source

type OutputChange string

OutputChange describes whether the whole result of a parse equals the previous one; it is not a minimal tree difference.

const (
	OutputUnchanged      OutputChange = "unchanged"
	OutputChanged        OutputChange = "changed"
	OutputMayHaveChanged OutputChange = "may-have-changed"
	OutputUnavailable    OutputChange = "unavailable"
)

type PositionUnit source

type PositionUnit int

PositionUnit is the unit of positions in the input.

const (
	// CodePoints counts positions in Unicode code points. It is the default.
	CodePoints PositionUnit = iota
	// Bytes counts positions in UTF-8 bytes.
	Bytes
)

func (PositionUnit) String source

func (u PositionUnit) String() string

String returns "codepoints" or "bytes".

type Span source

type Span struct{ Start, End int }

Span is a range [Start, End) of the input, in the position unit of the parse that produced it; End is exclusive. The typed values of a generated parser embed it to report the input they cover.

func (Span) Range source

func (s Span) Range() (start, end int)

Range returns the start and the end (exclusive) of the span.

type TextEdit source

type TextEdit struct {
	Start, End int
	Text       string
}

TextEdit replaces [Start, End) in the position unit of its base Document with Text.