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

support for TokenStreamRewriter.getText(ParserRuleContext) #727

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions runtime/Java/src/org/antlr/v4/runtime/TokenStreamRewriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.runtime.tree.SyntaxTree;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -385,6 +386,16 @@ public String getText(Interval interval) {
return getText(DEFAULT_PROGRAM_NAME, interval);
}

/** Return the text associated with the tokens given by SyntaxTree
*/
public String getText(SyntaxTree ctx) {
return getText(DEFAULT_PROGRAM_NAME, ctx);
}

public String getText(String programName, SyntaxTree ctx) {
return getText(programName, ctx.getSourceInterval());
}

public String getText(String programName, Interval interval) {
List<RewriteOperation> rewrites = programs.get(programName);
int start = interval.a;
Expand Down