コード例 #1
0
static  pANTLR3_STRING    toString		(pANTLR3_COMMON_TOKEN token)
{
    pANTLR3_STRING  text;
    pANTLR3_STRING  outtext;

    text    =	token->getText(token);
    
    if	(text == NULL)
    {
		return NULL;
    }

	if	(text->factory == NULL)
	{
		return text;		// This usally means it is the EOF token
	}

    /* A new empty string to assemble all the stuff in
     */
    outtext = text->factory->newRaw(text->factory);

    /* Now we use our handy dandy string utility to assemble the
     * the reporting string
     * return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]";
     */
    outtext->append8(outtext, "[Index: ");
    outtext->addi   (outtext, (ANTLR3_INT32)token->getTokenIndex(token));
    outtext->append8(outtext, " (Start: ");
    outtext->addi   (outtext, (ANTLR3_INT32)token->getStartIndex(token));
    outtext->append8(outtext, "-Stop: ");
    outtext->addi   (outtext, (ANTLR3_INT32)token->getStopIndex(token));
    outtext->append8(outtext, ") ='");
    outtext->appendS(outtext, text);
    outtext->append8(outtext, "', type<");
    outtext->addi   (outtext, token->type);
    outtext->append8(outtext, "> ");

    if	(token->getChannel(token) > ANTLR3_TOKEN_DEFAULT_CHANNEL)
    {
		outtext->append8(outtext, "(channel = ");
		outtext->addi	(outtext, (ANTLR3_INT32)token->getChannel(token));
		outtext->append8(outtext, ") ");
    }

    outtext->append8(outtext, "Line: ");
    outtext->addi   (outtext, (ANTLR3_INT32)token->getLine(token));
    outtext->append8(outtext, " LinePos:");
    outtext->addi   (outtext, token->getCharPositionInLine(token));
    outtext->addc   (outtext, ']');

    return  outtext;
}
コード例 #2
0
ファイル: antlr3commontoken.c プロジェクト: UIKit0/mclab
static  pANTLR3_STRING  getText			(pANTLR3_COMMON_TOKEN token)
{
    if	(token->text != NULL)
    {
	return	token->text;
    }
    if (token->type == ANTLR3_TOKEN_EOF)
    {
	token->setText8(token, (pANTLR3_UINT8)"<EOF>");
	return	token->text;
    }
    if	(token->input != NULL)
    {
	return	token->input->substr(	token->input, 
					token->getStartIndex(token), 
 					token->getStopIndex(token));
    }

    /* Nothing to return
     */
    return NULL;
}
コード例 #3
0
ファイル: mcmt_state.cpp プロジェクト: benjaminfjones/sally
string mcmt_state::token_text(pANTLR3_COMMON_TOKEN token) {
  ANTLR3_MARKER start = token->getStartIndex(token);
  size_t size = token->getStopIndex(token) - start + 1;
  return string((const char*) start, size);
}
コード例 #4
0
static  pANTLR3_STRING  getText                 (pANTLR3_COMMON_TOKEN token)
{
        switch (token->textState)
        {
                case ANTLR3_TEXT_STRING:

                        // Someone already created a string for this token, so we just
                        // use it.
                        //
                        return  token->tokText.text;
                        break;

                case ANTLR3_TEXT_CHARP:

                        // We had a straight text pointer installed, now we
                        // must convert it to a string. Note we have to do this here
                        // or otherwise setText8() will just install the same char*
                        //
                        if      (token->strFactory != NULL)
                        {
                                token->tokText.text     = token->strFactory->newStr8(token->strFactory, (pANTLR3_UINT8)token->tokText.chars);
                                token->textState        = ANTLR3_TEXT_STRING;
                                return token->tokText.text;
                        }
                        else
                        {
                                // We cannot do anything here
                                //
                                return NULL;
                        }
                        break;

                default:

                        // EOF is a special case
                        //
                        if (token->type == ANTLR3_TOKEN_EOF)
                        {
                                token->tokText.text                             = token->strFactory->newStr8(token->strFactory, (pANTLR3_UINT8)"<EOF>");
                                token->textState                                = ANTLR3_TEXT_STRING;
                                token->tokText.text->factory    = token->strFactory;
                                return token->tokText.text;
                        }


                        // We had nothing installed in the token, create a new string
                        // from the input stream
                        //

                        if      (token->input != NULL)
                        {

                                return  token->input->substr(   token->input,
                                                                                                token->getStartIndex(token),
                                                                                                token->stop
                                                                                        );
                        }

                        // Nothing to return, there is no input stream
                        //
                        return NULL;
                        break;
        }
}