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

getText method with arguments not always works correctly #1238

Closed
KvanTTT opened this issue Jul 29, 2016 · 3 comments
Closed

getText method with arguments not always works correctly #1238

KvanTTT opened this issue Jul 29, 2016 · 3 comments

Comments

@KvanTTT
Copy link
Member

KvanTTT commented Jul 29, 2016

I created CommonTokenStream from list of tokens by the following way:

List<? extends Token> preprocessorTokens = (List<Token>)lexer.getAllTokens();
ListTokenSource codeTokenSource = new ListTokenSource(tokens);
CommonTokenStream tokensStream = new CommonTokenStream(codeTokenSource);

After it I tried to call method getText(context) for RuleContext but it returned a wrong result:

tokensStream.getText(context); // returns incorrect text, only text of first token
tokensStream.getText();             // returns correct text of all tokens

If fill() method was called before getText methods, these methods return a correct text:

tokensStream.fill();
tokensStream.getText(context); // returns correct text of tokens from context
tokensStream.getText();             // returns correct text of all tokens
@sharwell
Copy link
Member

On a complete side note, you have an invalid cast in there. Your first line should actually be this:

List<? extends Token> preprocessorTokens = lexer.getAllTokens();

@KvanTTT
Copy link
Member Author

KvanTTT commented Jul 29, 2016

Thank you! I'm familiar with Java not very good :)

@sharwell
Copy link
Member

No problem, thanks for taking time to follow up on the Java side of this issue!

@KvanTTT KvanTTT changed the title GetText method with arguments not always works correctly getText method with arguments not always works correctly Aug 3, 2016
@parrt parrt added this to the 4.6 milestone Nov 25, 2016
@parrt parrt closed this as completed in c695ed2 Nov 25, 2016
janyou added a commit to janyou/antlr4 that referenced this issue Dec 14, 2016
parrt added a commit that referenced this issue Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants