SourceReader Class
Definition
A forward-only reader over the characters of a TextFile that tracks the current line and column, for use when lexing the file into Tokens. Lines are terminated by "\n", "\r\n" or a lone "\r", matching Lines.
public sealed class SourceReader
View source
Constructors
Properties
| Name |
Description |
AtEnd |
Returns true if the reader is at the end of the file, false otherwise. |
ColumnIndex |
Zero based index of the column of the current position in the file. |
Current |
The character at the current position, or the NUL character '\0' if the reader is at the end of the file. |
File |
The TextFile being read. |
Index |
The index of the current position in the file. |
LineIndex |
Zero based index of the line of the current position in the file. |
Methods
| Name |
Description |
Advance() |
Advances the reader one character. Does nothing if the reader is at the end of the file. |
Advance(Int32) |
Advances the reader the specified number of characters, stopping at the end of the file if it is reached first. |
AdvanceWhile(Func<Char, Boolean>) |
Advances the reader while the specified predicate returns true for the current character, stopping at the end of the file if it is reached first. |
CreateToken<TKind>(TKind, SourceMark) |
Creates a Token<TKind> of the specified kind from the specified SourceMark up to the current position. |
Mark() |
Creates a SourceMark for the current position, typically to mark the start of a token before scanning to its end. |
Peek(Int32) |
Returns the character at the specified offset from the current position, or the NUL character '\0' if the offset is outside the file. |
ReadToken<TKind>(TKind, Int32) |
Creates a Token<TKind> of the specified kind and length starting at the current position, advancing the reader over it. Stops at the end of the file if it is reached first, shortening the token accordingly. |