Goose  Artifact [d90098e2d6]

Artifact d90098e2d68dc0497099053c6b1e6571b4999386e24f1a859110b20b329c46b9:

  • File bs/lex/lookahead.cpp — part of check-in [23e0cd5dc7] at 2019-02-18 21:54:23 on branch trunk — Parser:
    • Make the resolver skip newlines by default, and provide an additional "raw" api to retrieve unresolved tokens without skipping newlines.
    • Parsing rules now only return a bool to indicate whether they were successful, and can push any number of values themselves as needed.
    • Stop trying to shoehorn implicit separators in the pratt parser. Instead, use the pratt parser only for expressions, and use a different parsing loop for sequences of expressions (ie for brace blocks and top level).
    (user: achavasse size: 658)

#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];
}