Struct SourceSpan

Namespace
Pixie.Code
Assembly
Pixie.dll

Represents a source span backed by a document-relative character offset and length.

public readonly struct SourceSpan
Inherited Members

Remarks

Start and Length are relative to the owning SourceDocument's text. The owning document may be original source text or a derived source view such as preprocessed text.

Line, column, file name, and original source spans are resolved on demand through the owning document. This keeps tokens compact while allowing mapped documents to report diagnostics against user-authored source.

An unknown location is represented by the default value (i.e., a null document). Use Unknown to obtain one explicitly.

Constructors

SourceSpan(SourceDocument, int, int)

Creates a source span from a document, a start offset and a span length.

public SourceSpan(SourceDocument document, int start, int length)

Parameters

document SourceDocument

The source document this span is a part of.

start int

The offset of the first character in the span.

length int

The number of characters in the span.

Properties

Document

Gets the document to which this span of source code refers.

public SourceDocument Document { get; }

Property Value

SourceDocument

The source document.

End

Gets the exclusive end offset of this span.

public int End { get; }

Property Value

int

The exclusive end offset of this span.

IsKnown

Gets a value indicating whether this span is backed by a source document.

public bool IsKnown { get; }

Property Value

bool

true if this span is known; otherwise, false.

Length

Gets this span's length, in characters.

public int Length { get; }

Property Value

int

The length of this span.

Position

Gets the diagnostic display position of the span start.

public LineAndColumnPosition Position { get; }

Property Value

LineAndColumnPosition

The diagnostic display position.

Start

Gets the offset of the first character in this span.

public int Start { get; }

Property Value

int

The offset of the first character in this span.

Text

Gets this span's contents as text.

public string Text { get; }

Property Value

string

The span's contents.

Unknown

Gets an unknown source span.

public static SourceSpan Unknown { get; }

Property Value

SourceSpan

Methods

Merge(SourceSpan, SourceSpan)

Merges two source spans into a single span that covers both.

public static SourceSpan Merge(SourceSpan first, SourceSpan second)

Parameters

first SourceSpan

The first span.

second SourceSpan

The second span.

Returns

SourceSpan

The merged source span.

Resolve()

Resolves this span to original source coverage.

public ResolvedSourceSpan Resolve()

Returns

ResolvedSourceSpan

The resolved original source coverage.