Class SourceDocument
Represents a source text buffer that can be consumed by a lexer or parser.
public abstract class SourceDocument
- Inheritance
-
SourceDocument
- Derived
- Inherited Members
Remarks
A source document may be an original user-authored file or a derived view such as preprocessed text. SourceSpan values store offsets relative to this document's text, while document implementations decide how those offsets resolve back to original source coordinates for diagnostics.
Public position lookup returns diagnostic coordinates. For mapped documents, those coordinates may come from an original document rather than from this document's own text.
Constructors
SourceDocument()
protected SourceDocument()
Properties
Identifier
Gets the document's identifier. This is typically a path.
public abstract string Identifier { get; }
Property Value
- string
The document's identifier.
Length
Gets the document's length, in characters.
public abstract int Length { get; }
Property Value
- int
The document's length.
Methods
GetPosition(int)
Gets the diagnostic display position that corresponds to a particular offset in this document.
public abstract LineAndColumnPosition GetPosition(int offset)
Parameters
offsetintThe offset to a character in the document.
Returns
- LineAndColumnPosition
A diagnostic display position.
GetText(int, int)
Gets a span of text in the document.
public virtual string GetText(int offset, int length)
Parameters
Returns
- string
A span of text.
Open(int)
Opens this source document at the given offset.
public abstract TextReader Open(int offset)
Parameters
offsetintThe offset to open the source document at.
Returns
- TextReader
A text reader.
ResolveSpan(int, int)
Resolves a span in this document to its original source coverage.
public abstract ResolvedSourceSpan ResolveSpan(int start, int length)
Parameters
startintThe zero-based start offset within this document.
lengthintThe span length within this document.
Returns
- ResolvedSourceSpan
The resolved original source coverage.