module volta.token.source

Code Map

module volta.token.source;


alias Mark = size_t;

//! Class for handling reading of Volt source code.
class Source
{
public:
	source: string;
	loc: Location;
	eof: bool;
	errSink: ErrorSink;


public:
	//! Sets the source to string and the current location and validate it as a
	//! utf8 source.
	this(s: string, filename: string, errSink: ErrorSink) { }
	//! Copy contructor, same as dup.
	this(src: Source) { }
	//! Validate that the current start of source has a valid utf8 BOM.
	fn checkBOM() { }
	//! Set the loc to newFilename(line:1).
	fn changeCurrentLocation(newFilename: string, newLine: u32) { }
	//! Used to skip the first script line in D sources.
	fn skipScriptLine() { }
	//! 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() { }
	fn decodeChar() dchar { }
	fn decodeChar(index: size_t) dchar { }
	//! Get the next unicode character.
	fn next() dchar { }
	//! Returns the current utf8 char.
	fn current() dchar { }
	//! 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 { }
	//! Returns a index for the current loc.
	fn save() Mark { }
	//! Get a slice from the current token to mark. mark must before current
	//! token.
	fn sliceFrom(mark: Mark) string { }
	//! Synchronise this source with a duplicated one.
	fn sync(src: Source) { }
}
class Source

Class for handling reading of Volt source code.

Upon loading or getting source the ctor will validate the source code to make sure that it is Utf-8 and the BOM is valid.

this(s: string, filename: string, errSink: ErrorSink)

Sets the source to string and the current location and validate it as a utf8 source.

Side-effects: Puts all the other fields into known good states.

Throws: UtfException if the source is not valid utf8.

this(src: Source)

Copy contructor, same as dup.

fn checkBOM()

Validate that the current start of source has a valid utf8 BOM.

Side-effects: source advanced to after valid utf8 BOM if found.

Throws: CompilerPanic if source if BOM is not valid.

fn changeCurrentLocation(newFilename: string, newLine: u32)

Set the loc to newFilename(line:1).

fn skipScriptLine()

Used to skip the first script line in D sources.

Side-effects: @arg

See also

  • next

fn skipWhitespace()

Used to skip whitespace in the source file, as defined by watt.text.ascii.isWhite.

Side-effects: @arg

See also

  • next

fn skipEndOfLine()

Skips till character after next end of line or eof.

Side-effects: @arg

See also

  • next

fn next() dchar

Get the next unicode character.

Side-effects: eof set to true if we have reached the EOF. mChar is set to the returned character if not at EOF. mIndex advanced to the end of the given character. loc updated to the current position if not at EOF.

Throws: UtfException if the source is not valid utf8.

Returns: Returns next unicode char or dchar.init at EOF.

fn current() dchar

Returns the current utf8 char.

Side-effects: None.

fn lookahead(n: size_t, lookaheadEOF: bool) dchar

Return the unicode character n chars forwards. lookaheadEOF set to true if we reached EOF, otherwise false.

Throws: UtfException if the source is not valid utf8.

Side-effects: None.

Returns: Unicode char at n or dchar.init at EOF.

fn save() Mark

Returns a index for the current loc.

Side-effects: None.

fn sliceFrom(mark: Mark) string

Get a slice from the current token to mark. mark must before current token.

Side-effects: None.

fn sync(src: Source)

Synchronise this source with a duplicated one.

Throws: CompilerPanic if the source file is not the same for both sources.

Side-effects: None.