Esempio n. 1
0
/*!
 * \brief
 * Change to a new input stream, remembering the old one.
 * 
 * \param lexer
 * Pointer to the lexer instance to switch input streams for.
 * 
 * \param input
 * New input stream to install as the current one.
 * 
 * Switches the current character input stream to 
 * a new one, saving the old one, which we will revert to at the end of this 
 * new one.
 */
void Lexer::pushCharStream(CharStreamPtr input)
{
    // We have a stack, so we can save the current input stream
    // into it.
    //
    RecognizerSharedState::StreamState save = { input_->mark(), charStream() };
    state_->streams.push(save);

    // And now we can install this new one
    //
    setCharStream(input);
}
Esempio n. 2
0
ANTLR3_API pANTLR3_LEXER
antlr3LexerNewStream(ANTLR3_UINT32 sizeHint, pANTLR3_INPUT_STREAM input, pANTLR3_RECOGNIZER_SHARED_STATE state)
{
    pANTLR3_LEXER   lexer;

    // Create a basic lexer first
    //
    lexer   = antlr3LexerNew(sizeHint, state);

    if	(lexer != NULL) 
    {
		// Install the input stream and reset the lexer
		//
		setCharStream(lexer, input);
    }

    return  lexer;
}
Esempio n. 3
0
/*!
 * \brief
 * Stops using the current input stream and reverts to any prior
 * input stream on the stack.
 * 
 * \param lexer
 * Description of parameter lexer.
 * 
 * Pointer to a function that abandons the current input stream, whether it
 * is empty or not and reverts to the previous stacked input stream.
 *
 * \remark
 * The function fails silently if there are no prior input streams.
 */
void Lexer::popCharStream()
{
    // If we do not have a stream stack or we are already at the
    // stack bottom, then do nothing.
    //
    if	(!state_->streams.empty())
    {
        // We just leave the current stream to its fate, we do not close
        // it or anything as we do not know what the programmer intended
        // for it. This method can always be overridden of course.
        // So just find out what was currently saved on the stack and use
        // that now, then pop it from the stack.
        //
        auto save = state_->streams.top();
        state_->streams.pop();

        // Now install the stream as the current one.
        //
        setCharStream(save.stream);
        save.marker->rewind();
    }
}
Esempio n. 4
0
Lexer::Lexer(CharStreamPtr input, RecognizerSharedStatePtr state)
: Lexer(state)
{
    setCharStream(std::move(input));
}