Skip to content

C++ runtime: Incorrect token string inserted for missing token #218

Open
@nyh

Description

@nyh

The ScyllaDB project uses Antlr3 with the C++ runtime.
In scylladb/scylladb#1703 it was noted that ugly error messages are reported. Particularly strange is:

line 1:20 missing K_VIEW at '<missing '

Forget for a moment why ScyllaDB even tries to print this token (it shouldn't!) but the fact that any token is being printed as <missing appears to be a simple Antlr3 bug:
/usr/include/antlr3parser.inl has in Parser<ImplTraits>::getMissingSymbol() the following code:

        // Create the token text that shows it has been inserted
        //
        token->setText("<missing ");
        text = token->getText();

        if      (!text.empty())
        {
                text.append((const char *) this->get_rec()->get_state()->get_tokenName(expectedTokenType) );
                text.append(">");
        }

Note how this code modifies the variable "text", which is a copy of the text in the token, and not the text in the token... Unfortunately, this isn't Java - when getText() returns a string (see /usr/include/antlr3commontoken.hpp) it is a copy, not a reference, and modifying it doesn't modify the token object.

Correct code would probably look something like this (untested):

StringType text("< missing");
text.append((const char *) this->get_rec()->get_state()->get_tokenName(expectedTokenType) );
text.append(">");
token->setText(text);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions