Class SourceDocumentPiece

Namespace
Pixie.Code
Assembly
Pixie.dll

Represents one piece of text in a PiecewiseSourceDocument.

public sealed class SourceDocumentPiece
Inheritance
SourceDocumentPiece
Inherited Members

Remarks

A piece can either expose text copied from an existing SourceSpan or literal generated text. Literal text may still have an anchor span so diagnostics in generated text can point back to the user-authored source that caused the text to exist.

Properties

Length

Gets the length of this piece in the assembled document.

public int Length { get; }

Property Value

int

The length of this piece.

Origin

Gets the source span this piece came from or is anchored to.

public SourceSpan Origin { get; }

Property Value

SourceSpan

The source span this piece came from or is anchored to.

ReadsFromOrigin

Gets a value indicating whether this piece reads its text from Origin instead of storing literal text.

public bool ReadsFromOrigin { get; }

Property Value

bool

true when text is read from the origin span.

Text

Gets the literal text for this piece, or null when this piece reads its text directly from Origin.

public string Text { get; }

Property Value

string

The literal text, or null.

Methods

FromSource(in SourceSpan)

Creates a piece whose text and source mapping both come from a source span.

public static SourceDocumentPiece FromSource(in SourceSpan origin)

Parameters

origin SourceSpan

The source span to copy into the assembled document.

Returns

SourceDocumentPiece

A source-backed piece.

FromText(string)

Creates a generated text piece with no known source provenance.

public static SourceDocumentPiece FromText(string text)

Parameters

text string

The generated text.

Returns

SourceDocumentPiece

A literal text piece.

FromText(string, in SourceSpan)

Creates a generated text piece anchored to a source span for diagnostics.

public static SourceDocumentPiece FromText(string text, in SourceSpan anchor)

Parameters

text string

The generated text.

anchor SourceSpan

The span that caused the generated text to exist.

Returns

SourceDocumentPiece

An anchored literal text piece.