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

A ScannedTokens adaptor that provides a traditional scanner API. More...

#include <ScannedTokens.hpp>

Collaboration diagram for ScannerApiScannedTokens< TokenT >:
[legend]

Classes

class  Marker
 A position marker that can be obtained at any point during parsing, in order to put back multiple tokens. More...
 

Public Member Functions

 ScannerApiScannedTokens (ScannedTokens< TokenT > &&scannedTokens_) noexcept
 Create a scanner API scanned tokens instance. More...
 
void consume ()
 Consume the current token. More...
 
bool currentIsBlank () const
 Is the next token a blank? More...
 
bool currentIsLineBreak () const
 Is the next token line break? More...
 
bool currentIsWhitespace () const
 Is the next token whitespace? More...
 
void expect (const TokenT token, std::string_view errorMessage)
 Expect the supplied token. More...
 
template<template< typename ... > class ContainerT, typename ... ArgT, typename ReportT >
bool expect (const TokenT token, ContainerT< ReportT, ArgT ... > &container, const size_t maxErrorCount, const std::function< ReportT(const TokenT &, const CodeSpan &, size_t)> &errorReport)
 Expect the supplied token. More...
 
void expect (const std::vector< TokenT > &tokens, std::string_view errorMessage)
 Expect one of the supplied tokens. More...
 
template<template< typename ... > class TokenContainerT, template< typename ... > class ContainerT, typename ... TokenArgT, typename ... ArgT, typename ReportT >
bool expect (const TokenContainerT< TokenT, TokenArgT ... > &tokens, ContainerT< ReportT, ArgT ... > &container, const size_t maxErrorCount, const std::function< ReportT(const TokenContainerT< TokenT, TokenArgT ... > &, const CodeSpan &, size_t)> &errorReport)
 Expect one of the supplied tokens. More...
 
ScannedToken< TokenT > get ()
 Get the current token. More...
 
CodeSpan getCurrentCodeSpan () const
 Get the code span of the current token. More...
 
std::shared_ptr< const Resource::UrigetUri ()
 Move the input uri to its final destination. More...
 
bool isBlank (const Marker &marker) const
 Is the marked token a blank? More...
 
bool isLineBreak (const Marker &marker) const
 Is the marked token line break? More...
 
bool isWhitespace (const Marker &marker) const
 Is the marked token whitespace? More...
 
std::string && moveTextOut ()
 Move the input text string to its final destination. More...
 
void popWhitespaceMode ()
 Pop the top of the whitespace mode stack. More...
 
void pushWhitespaceMode (WhitespaceMode newMode)
 Push the supplied whitespace mode onto the whitespace mode stack. More...
 
void putBack ()
 Put back the current token. More...
 
void reset ()
 Rest the scanner API state to the beginning of the scanned tokens. More...
 
size_t size () const
 Get the number of tokens. More...
 

Detailed Description

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

A ScannedTokens adaptor that provides a traditional scanner API.

Constructor & Destructor Documentation

◆ ScannerApiScannedTokens()

ScannerApiScannedTokens ( ScannedTokens< TokenT > &&  scannedTokens_)
inlineexplicitnoexcept

Create a scanner API scanned tokens instance.

Member Function Documentation

◆ consume()

void consume ( )
inline

Consume the current token.

If the current token is EndOfFile, then no action is taken.

◆ currentIsBlank()

bool currentIsBlank ( ) const
inline

Is the next token a blank?

◆ currentIsLineBreak()

bool currentIsLineBreak ( ) const
inline

Is the next token line break?

◆ currentIsWhitespace()

bool currentIsWhitespace ( ) const
inline

Is the next token whitespace?

◆ expect() [1/4]

void expect ( const TokenT  token,
std::string_view  errorMessage 
)
inline

Expect the supplied token.

Throws a syntax error exception with the supplied error message if the supplied token does not match the current token.

Parameters
tokenthe expected token
errorMessagean error message to pass to the exception
Exceptions
SyntaxErrorExceptionif the token was not found

◆ expect() [2/4]

bool expect ( const TokenT  token,
ContainerT< ReportT, ArgT ... > &  container,
const size_t  maxErrorCount,
const std::function< ReportT(const TokenT &, const CodeSpan &, size_t)> &  errorReport 
)
inline

Expect the supplied token.

Adds an error report to the supplied error report container and returns false if the supplied token does not match the current token.

The current error count is also passed to the error report generation function in order to allow a generic report to be generated when the container contains the maximum number of errors.

Parameters
tokenthe expected token
containerthe error report container to add the error report to
maxErrorCountthe maximum number of errors that the container is allowed to have
errorReporta function that generates the error report
Returns
true if the expected token was matched, false otherwise

◆ expect() [3/4]

void expect ( const std::vector< TokenT > &  tokens,
std::string_view  errorMessage 
)
inline

Expect one of the supplied tokens.

Throws a syntax error exception with the supplied error message if none of the supplied tokens match the current token.

Exceptions
SyntaxErrorExceptionif one of the tokens was not found

◆ expect() [4/4]

bool expect ( const TokenContainerT< TokenT, TokenArgT ... > &  tokens,
ContainerT< ReportT, ArgT ... > &  container,
const size_t  maxErrorCount,
const std::function< ReportT(const TokenContainerT< TokenT, TokenArgT ... > &, const CodeSpan &, size_t)> &  errorReport 
)
inline

Expect one of the supplied tokens.

Adds an error report to the supplied error report container and returns false if none of the supplied tokens match the current token.

The current error count is also passed to the error report generation function in order to allow a generic report to be generated when the container contains the maximum number of errors.

Parameters
tokenthe expected token
containerthe error report container to add the error report to
maxErrorCountthe maximum number of errors that the container is allowed to have
errorReporta function that generates the error report
Returns
true if one of the expected tokens was matched, false otherwise

◆ get()

ScannedToken<TokenT> get ( )
inline

Get the current token.

Depending on the whitespace mode, this may skip over whitespace and/or line break tokens.

◆ getCurrentCodeSpan()

CodeSpan getCurrentCodeSpan ( ) const
inline

Get the code span of the current token.

◆ getUri()

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

Move the input uri to its final destination.

Returns
the input uri rvalue reference

◆ isBlank()

bool isBlank ( const Marker marker) const
inline

Is the marked token a blank?

◆ isLineBreak()

bool isLineBreak ( const Marker marker) const
inline

Is the marked token line break?

◆ isWhitespace()

bool isWhitespace ( const Marker marker) const
inline

Is the marked token whitespace?

◆ 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

◆ popWhitespaceMode()

void popWhitespaceMode ( )
inline

Pop the top of the whitespace mode stack.

◆ pushWhitespaceMode()

void pushWhitespaceMode ( WhitespaceMode  newMode)
inline

Push the supplied whitespace mode onto the whitespace mode stack.

◆ putBack()

void putBack ( )
inline

Put back the current token.

Depending on the whitespace mode, this may also reverse skip whitespace and/or line break tokens.

◆ reset()

void reset ( )
inline

Rest the scanner API state to the beginning of the scanned tokens.

◆ size()

size_t size ( ) const
inline

Get the number of tokens.


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