Goose  Artifact [5135ca6ff2]

Artifact 5135ca6ff2c6afd7038a65aeda235904b8f1b42a4b47c9eda710aec1fc485b23:

  • File bs/lex/vectoradapter.inl — part of check-in [af650a9e95] at 2019-09-22 14:37:55 on branch trunk — Project renaming. (user: achavasse size: 1073)

#ifndef GOOSE_LEX_VECTORADAPTER_INL
#define GOOSE_LEX_VECTORADAPTER_INL

namespace goose::lex
{
    template< typename V >
    bool VectorAdapter< V >::eos() const
    {
        return m_index >= m_vector.size();
    }

    template< typename V >
    optional< TermLoc > VectorAdapter< V >::consume()
    {
        if( eos() )
            return nullopt;

        return m_vector[m_index++];
    }

    template< typename V >
    optional< TermLoc > VectorAdapter< V >::lookAhead( size_t distance )
    {
        if( ( m_index + distance ) >= m_vector.size() )
            return nullopt;

        return m_vector[m_index + distance];
    }

    // This is a bit approximative, might have to figure out a way to improve this.
    // Especially since almost all non top-level code is parsed through a vector adapter.
    template< typename V >
    uint32_t VectorAdapter< V >::getCurrentLocation()
    {
        if( m_vector.empty() )
            return 0;

        if( eos() )
            return m_vector.back().second;

        return lookAhead()->second;
    }
}

#endif