public class TokenStreamRewriter extends Object
Modifier and Type | Class and Description |
---|---|
class |
TokenStreamRewriter.RewriteOperation |
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PROGRAM_NAME |
protected Map<String,Integer> |
lastRewriteTokenIndexes
Map String (program name) -> Integer index
|
static int |
MIN_TOKEN_INDEX |
static int |
PROGRAM_INIT_SIZE |
protected Map<String,List<TokenStreamRewriter.RewriteOperation>> |
programs
You may have multiple, named streams of rewrite operations.
|
protected TokenStream |
tokens
Our source stream
|
Constructor and Description |
---|
TokenStreamRewriter(TokenStream tokens) |
Modifier and Type | Method and Description |
---|---|
protected String |
catOpText(Object a,
Object b) |
void |
delete(int index) |
void |
delete(int from,
int to) |
void |
delete(String programName,
int from,
int to) |
void |
delete(String programName,
Token from,
Token to) |
void |
delete(Token indexT) |
void |
delete(Token from,
Token to) |
void |
deleteProgram() |
void |
deleteProgram(String programName)
Reset the program so that no instructions exist
|
protected <T extends TokenStreamRewriter.RewriteOperation> |
getKindOfOps(List<? extends TokenStreamRewriter.RewriteOperation> rewrites,
Class<T> kind,
int before)
Get all operations before an index of a particular kind
|
int |
getLastRewriteTokenIndex() |
protected int |
getLastRewriteTokenIndex(String programName) |
protected List<TokenStreamRewriter.RewriteOperation> |
getProgram(String name) |
String |
getText()
Return the text from the original tokens altered per the
instructions given to this rewriter.
|
String |
getText(Interval interval)
Return the text associated with the tokens in the interval from the
original token stream but with the alterations given to this rewriter.
|
String |
getText(String programName,
Interval interval) |
TokenStream |
getTokenStream() |
void |
insertAfter(int index,
Object text) |
void |
insertAfter(String programName,
int index,
Object text) |
void |
insertAfter(String programName,
Token t,
Object text) |
void |
insertAfter(Token t,
Object text) |
void |
insertBefore(int index,
Object text) |
void |
insertBefore(String programName,
int index,
Object text) |
void |
insertBefore(String programName,
Token t,
Object text) |
void |
insertBefore(Token t,
Object text) |
protected Map<Integer,TokenStreamRewriter.RewriteOperation> |
reduceToSingleOperationPerIndex(List<TokenStreamRewriter.RewriteOperation> rewrites)
We need to combine operations and report invalid operations (like
overlapping replaces that are not completed nested).
|
void |
replace(int from,
int to,
Object text) |
void |
replace(int index,
Object text) |
void |
replace(String programName,
int from,
int to,
Object text) |
void |
replace(String programName,
Token from,
Token to,
Object text) |
void |
replace(Token indexT,
Object text) |
void |
replace(Token from,
Token to,
Object text) |
void |
rollback(int instructionIndex) |
void |
rollback(String programName,
int instructionIndex)
Rollback the instruction stream for a program so that
the indicated instruction (via instructionIndex) is no
longer in the stream.
|
protected void |
setLastRewriteTokenIndex(String programName,
int i) |
public static final String DEFAULT_PROGRAM_NAME
public static final int PROGRAM_INIT_SIZE
public static final int MIN_TOKEN_INDEX
protected final TokenStream tokens
protected final Map<String,List<TokenStreamRewriter.RewriteOperation>> programs
public TokenStreamRewriter(TokenStream tokens)
public final TokenStream getTokenStream()
public void rollback(int instructionIndex)
public void rollback(String programName, int instructionIndex)
public void deleteProgram()
public void deleteProgram(String programName)
public void insertAfter(int index, Object text)
public void insertBefore(int index, Object text)
public void replace(int index, Object text)
public void replace(int from, int to, Object text)
public void delete(int index)
public void delete(int from, int to)
public void delete(Token indexT)
public void delete(String programName, int from, int to)
public int getLastRewriteTokenIndex()
protected int getLastRewriteTokenIndex(String programName)
protected void setLastRewriteTokenIndex(String programName, int i)
protected List<TokenStreamRewriter.RewriteOperation> getProgram(String name)
public String getText()
public String getText(Interval interval)
protected Map<Integer,TokenStreamRewriter.RewriteOperation> reduceToSingleOperationPerIndex(List<TokenStreamRewriter.RewriteOperation> rewrites)
protected <T extends TokenStreamRewriter.RewriteOperation> List<? extends T> getKindOfOps(List<? extends TokenStreamRewriter.RewriteOperation> rewrites, Class<T> kind, int before)
Copyright © 1992-2013 ANTLR. All Rights Reserved.