A class for dealing with a file from the perspective of a compiler.
Code Map
//! A class for dealing with a file from the perspective of a compiler.
module watt.text.source;
//! A container for iterating over UTF-8 source code.
class Source
{
public:
alias eof = empty;
public:
//! The location of the current character front.
loc: Location;
public:
//! Sets this Source to s and the current location and validate it as a
//! utf8 source.
this(s: string, filename: string) { }
//! Have we reached EOF, if we have current = dchar.default.
fn empty() dchar { }
//! Returns the current utf8 char.
fn front() dchar { }
//! Returns the following utf8 char after front.
fn following() dchar { }
//! Advance the source one character.
fn popFront() { }
//! Advance the source n character.
fn popFrontN(n: size_t) { }
//! Used to skip whitespace in the source file, as defined by
//! watt.text.ascii.isWhite.
fn skipWhitespace() { }
//! Skips till character after next end of line or eof.
fn skipEndOfLine() { }
//! Return the unicode character n chars forwards. lookaheadEOF set to true
//! if we reached EOF, otherwise false.
fn lookahead(n: size_t, lookaheadEOF: bool) dchar { }
//! Return the index of the current character.
fn save() size_t { }
//! Slices the source from the given mark to (but not including) the
//! current character. Use save for indicies.
fn sliceFrom(mark: size_t) string { }
//! Slice the source from a to b.
fn slice(a: size_t, b: size_t) string { }
}
//! A simple container for iterating over UTF-8 source code.
struct SimpleSource
{
public:
alias eof = empty;
public:
//! Have we reached EOF, if we have front = dchar.default.
empty: bool;
public:
//! Setup this simple source and return the full source.
fn source(src: string) string { }
//! Return the full source.
fn source() string { }
//! Returns the current utf8 char.
fn front() dchar { }
//! Returns the following utf8 char after front.
fn following() dchar { }
//! Advance the source one character.
fn popFront() { }
//! Advance the source n character.
fn popFrontN(n: size_t) { }
//! Return the unicode character n chars forwards. lookaheadEOF set to true
//! if we reached EOF, otherwise false.
fn lookahead(n: size_t, lookaheadEmpty: bool) dchar { }
//! Used to skip whitespace in the source file, as defined by
//! watt.text.ascii.isWhite.
fn skipWhitespace() { }
//! Return the index of the current character.
fn save() size_t { }
//! Slices the source from the given mark to (but not including) the
//! current character. Use save for indicies.
fn sliceFrom(mark: size_t) string { }
//! Slices two points.
fn slice(a: size_t, b: size_t) string { }
//! Decodes a single utf8 code point at index in the given source.
fn decodeChar(index: size_t) dchar { }
}
//! Struct representing a location in a source file.
struct Location
{
public:
//! The file from pointed to this locatiom.
filename: string;
//! Line number starting at 1.
line: size_t;
//! Column starting at 1.
column: size_t;
//! Length in characers.
length: size_t;
public:
//! Format into a location string.
fn toString() string { }
//! Difference between two locations. end - begin == begin ... end
fn opSub(begin: Location) Location { }
//! See difference.
fn spanTo(end: Location) { }
public:
//! Difference between two locations. end - begin == begin ... end
static fn difference(end: Location, begin: Location, _default: Location) Location { }
}
A container for iterating over UTF-8 source code.
Assumes the given source is valid UTF-8.
The location of the current character front
.
See also
-
empty.
Sets this Source to s
and the current location
and validate it as a utf8 source.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
Puts all the other fields into known good states.
Have we reached EOF, if we have current = dchar.default.
Returns the current utf8 char.
Side-Effects
-
None.
Returns the following utf8 char after front.
Side-Effects
-
None.
Advance the source one character.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
eof
set to true if we have reached the EOF. -
mSrc.mChar
is set to the returned character if not at EOF. -
mSrc.mNextIndex
advanced to the end of the given character. -
mSrc.mLastIndex
points to the index of the current character.
Advance the source n character.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
eof
set to true if we have reached the EOF. -
mSrc.mChar
is set to the current character if not at EOF. -
mSrc.mNextIndex
advanced to the end of the given character. -
mSrc.mLastIndex
points to the index of the current character.
Used to skip whitespace in the source file, as defined by watt.text.ascii.isWhite.
Side-Effects
-
See popFront.
Return the unicode character n
chars forwards.
lookaheadEOF
set to true if we reached EOF, otherwise false.
If n
is 0
, this is the same as calling front
.
Return
Unicode char at n
or dchar.default
at EOF.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
None.
Return the index of the current character.
Side-Effects
-
None.
Slices the source from the given mark to (but not including) the
current character. Use save
for indicies.
Side-Effects
-
None.
Slice the source from a
to b
.
A simple container for iterating over UTF-8 source code.
Assumes the given source is valid UTF-8.
See also
-
empty.
Have we reached EOF, if we have front = dchar.default.
Setup this simple source and return the full source.
Return the full source.
Returns the current utf8 char.
Side-Effects
-
None.
Returns the following utf8 char after front.
Side-Effects
-
None.
Advance the source one character.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
eof
set to true if we have reached the EOF. -
mChar
is set to the current character if not at EOF. -
mNextIndex
advanced to the end of the given character. -
mLastIndex
points to the index of the current character.
Advance the source n character.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
eof
set to true if we have reached the EOF. -
mChar
is set to the current character if not at EOF. -
mNextIndex
advanced to the end of the given character. -
mLastIndex
points to the index of the current character.
Return the unicode character n
chars forwards.
lookaheadEOF
set to true if we reached EOF, otherwise false.
If n
is 0
, this is the same as calling front
.
Return
Unicode char at n
or dchar.default
at empty.
Throws
-
UtfException if the source is not valid utf8.
Side-Effects
-
None.
Used to skip whitespace in the source file, as defined by watt.text.ascii.isWhite.
Side-Effects
-
See popFront.
Return the index of the current character.
Side-Effects
-
None.
Slices the source from the given mark to (but not including) the
current character. Use save
for indicies.
Side-Effects
-
None.
Slices two points.
Decodes a single utf8 code point at index in the given source.
Return
Unicode char at index
or dchar.default
if out of bound.
Side-Effects
-
None.
Struct representing a location in a source file.
Useful for error messages.
The file from pointed to this locatiom.
Line number starting at 1.
Column starting at 1.
Length in characers.
Format into a location
string.
Difference between two locations. end - begin == begin ... end
See also
-
watt.text.source.Location.difference
Difference between two locations. end - begin == begin ... end
On mismatch of filename or if begin is after end _default is returned.
See difference.