Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | List of all members
Loyc.Syntax.SourceFileWithLineRemaps Class Reference

An wrapper around ISourceFile that applies line remapping information (if the source file uses it). More...


Source file:
Inheritance diagram for Loyc.Syntax.SourceFileWithLineRemaps:
Loyc.WrapperBase< ISourceFile > Loyc.Syntax.ISourceFile Loyc.Syntax.IIndexPositionMapper Loyc.Syntax.IIndexToLine Loyc.Syntax.IHasFileName

Remarks

An wrapper around ISourceFile that applies line remapping information (if the source file uses it).

A preprocessor that supports #line may wrap the original ISourceFile in one of these, even when the source file doesn't use #line.

Call Remaps.AddRemap() and, optionally, Remaps.EndRemap(), to add each mapping.

ISourceFile includes IIndexPositionMapper which allows reverse-mapping from line/position back to index. However, a position derived from #line information may be ambiguous (does not always have a unique reverse mapping), and I'd rather avoid the work of reverse mapping anyway. So this class does not perform reverse mapping, but forward mappings return SourcePosAndIndex which are automatically recognized by LineToIndex which thereby recovers the original index.

Properties

LineRemapper Remaps [get]
 
ICharSource Text [get]
 
string FileName [get]
 
- Properties inherited from Loyc.Syntax.ISourceFile
ICharSource Text [get]
 
- Properties inherited from Loyc.Syntax.IHasFileName
string FileName [get]
 

Public Member Functions

 SourceFileWithLineRemaps (ISourceFile original)
 
int LineToIndex (int lineNo)
 Returns the index in a source file of the beginning of the specified line, where the first line is number 1, not 0. More...
 
int LineToIndex (ILineAndColumn pos)
 
ILineColumnFile IndexToLine (int index)
 Returns the position in a source file of the specified index. More...
 
- Public Member Functions inherited from Loyc.WrapperBase< ISourceFile >
override bool Equals (object obj)
 Returns true iff the parameter 'obj' is a wrapper around the same object that this object wraps. More...
 
override int GetHashCode ()
 Returns the hashcode of the wrapped object. More...
 
override string ToString ()
 Returns ToString() of the wrapped object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Loyc.WrapperBase< ISourceFile >
 WrapperBase (T wrappedObject)
 
- Protected fields inherited from Loyc.WrapperBase< ISourceFile >
_obj
 
- Protected static fields inherited from Loyc.WrapperBase< ISourceFile >
static readonly EqualityComparer< T > TComp
 

Member Function Documentation

◆ IndexToLine()

ILineColumnFile Loyc.Syntax.SourceFileWithLineRemaps.IndexToLine ( int  index)
inline

Returns the position in a source file of the specified index.

If index is negative, this should return a SourcePos where Line and PosInLine are zero (signifying an unknown location). If index is beyond the end of the file, this should retun the final position in the file.

Implements Loyc.Syntax.IIndexToLine.

References Loyc.Syntax.LineRemapper.Remap().

◆ LineToIndex()

int Loyc.Syntax.SourceFileWithLineRemaps.LineToIndex ( int  lineNo)
inline

Returns the index in a source file of the beginning of the specified line, where the first line is number 1, not 0.

If lineNo is zero, this method should return -1 (signifying an unknown location). If lineNo is larger than the largest line number, this method should return the index of end-of-file.

Implements Loyc.Syntax.IIndexPositionMapper.