god::scanner#

Note

Declared in <god/scanner.hpp>

class scanner#

A scanning tokenizer operating on raw string input, produing a tokenstream

Members

std::deque<std::string> lines#

A list of strings derived from raw input.

position cursor#

A moving positional marker for determining token boundaries.

Constructors

inline scanner(std::deque<std::string> *plines)#

Main constructor for the scanner class.

Parameters:

plines – A pointer to a deque of strings

inline scanner(std::deque<std::string> &plines)#

Alternative constructor for the scanner class.

Parameters:

plines – A reference to a deque of strings

Methods

bool finished() const noexcept#

Check if we are at the end of input.

Returns:

True when we are at the end of input, false otherwise

bool eol() const noexcept#

Check if we are at the end of a line.

Returns:

True when we are at the end of a line, false otherwise

bool eol(std::size_t n) const noexcept#

Check if an index is at the end of a line.

Parameters:

n – The index to check

Returns:

True if the index is at the end of a line, false otherwise

char now()#

Get the current character.

Returns:

The character under the scanners’ cursor

void advance_line()#

Move the cursor ahead one line.

void advance()#

Move the cursor ahead one column.

void advance(std::size_t amount)#

Move the cursor ahead a specific number of columns.

Parameters:

amount – The number of colums to advance

char peek()#

Get the next character.

Returns:

The character under the cursors’ next column

std::vector<char> peek(std::size_t amount)#

Get a specific number of characters ahead of the cursor.

Parameters:

amount – The amount of characters to get

Returns:

A vector containing the characters

std::expected<bool, encoding_error> validate()#

Check if the input is valid UTF-8.

Returns:

True when successful, an encoding_error otherwise

std::expected<tokenstream, scan_error> scan()#

Scan the input lines.

Returns:

The resulting tokenstream or a scan_error