Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nyh opened this issue Apr 30, 2023 · 0 comments
Open

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

nyh opened this issue Apr 30, 2023 · 0 comments

Comments

@nyh
Copy link

nyh commented Apr 30, 2023

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant