Goose  lookahead.cpp at [9089b014a2]

File bs/lex/lookahead.cpp artifact d90098e2d6 part of check-in 9089b014a2


#include "lex.h"

using namespace empathy;
using namespace empathy::lex;

bool Lexer::eos() const
{
    return m_input.eof() && m_lookAheadCache.empty();
}

optional< Term > Lexer::consume()
{
    if( m_lookAheadCache.empty() )
        return readToken();

    auto tok = move( m_lookAheadCache.front() );
    m_lookAheadCache.pop_front();
    return tok;
}

optional< Term > Lexer::lookAhead( size_t distance )
{
    while( m_lookAheadCache.size() < ( distance + 1 ) )
    {
        auto tok = readToken();
        if( !tok )
            return nullopt;
        m_lookAheadCache.emplace_back( move( *tok ) );
    }

    return m_lookAheadCache[distance];
}