Public Member Functions | List of all members
ScannedTokens< TokenT > Class Template Reference

Encapsulation of a set of language tokens, source text, and start offsets. More...

#include <ScannedTokens.hpp>

Public Member Functions

std::string_view getText (unsigned int index)
 Get the text of the token with the specified index. More...
 
std::shared_ptr< const Resource::UrigetUri ()
 Get the input uri. More...
 
std::string && moveTextOut ()
 Move the input text string to its final destination. More...
 

Detailed Description

template<typename TokenT>
class Balau::Lang::ScannedTokens< TokenT >

Encapsulation of a set of language tokens, source text, and start offsets.

This is the data structure returned by the scanner. It is structured to use the minimum amount of memory necessary in order to hold information on the whole scanned source file.

The supplied scanned tokens MUST end in an EndOfFile token.

There are three APIs defined by external adaptor classes:

When used by a parser, the scanner API provides a traditional scanner API with infinite lookahead and putback. The whitespace policy may be set dynamically by pushing and popping whitespace modes during consummation of the tokens.

For other uses, the random access and iterative APIs may be used.

The data structure is not random access. The token code span and string information is constructed serially in the scanner API. This permits the data structure to be as small as possible.

If random access is required, the RandomAccessScannedTokens wrapper may be built. Note that the memory overhead of the RandomAccessScannedTokens wrapper is far greater than that of the ScannedTokens data structure.

The scanned token type TokenT must be an enum containing at least the following entries:

In addition to the LineBreak token, the CommentLine enum entry is also considered to end with a line break.

Template Parameters
TokenTthe language token enum type

Member Function Documentation

◆ getText()

std::string_view getText ( unsigned int  index)
inline

Get the text of the token with the specified index.

◆ getUri()

std::shared_ptr<const Resource::Uri> getUri ( )
inline

Get the input uri.

Returns
the input uri

◆ moveTextOut()

std::string&& moveTextOut ( )
inline

Move the input text string to its final destination.

The scanned tokens instance must not be used after the move is performed.

Returns
the input text string as an rvalue reference

The documentation for this class was generated from the following file: