- catOpText
Variant catOpText(Variant a, Variant b)
Undocumented in source. Be warned that the author may not have intended to support it.
- deleteProgram
void deleteProgram()
Undocumented in source. Be warned that the author may not have intended to support it.
- deleteProgram
void deleteProgram(string programName)
Reset the program so that no instructions exist
- deleteT
void deleteT(size_t index)
Delete token (can not use delete as identifier)
- deleteT
void deleteT(size_t from, size_t to)
Undocumented in source. Be warned that the author may not have intended to support it.
- deleteT
void deleteT(Token indexT)
Undocumented in source. Be warned that the author may not have intended to support it.
- deleteT
void deleteT(Token from, Token to)
Undocumented in source. Be warned that the author may not have intended to support it.
- deleteT
void deleteT(string programName, size_t from, size_t to)
Undocumented in source. Be warned that the author may not have intended to support it.
- deleteT
void deleteT(string programName, Token from, Token to)
Undocumented in source. Be warned that the author may not have intended to support it.
- getKindOfOps
auto getKindOfOps(RewriteOperation[] rewrites, size_t before)
Undocumented in source. Be warned that the author may not have intended to support it.
- getLastRewriteTokenIndex
size_t getLastRewriteTokenIndex()
Undocumented in source. Be warned that the author may not have intended to support it.
- getText
Variant getText()
Return the text from the original tokens altered per the
instructions given to this rewriter.
- getText
Variant getText(string programName)
Return the text from the original tokens altered per the
instructions given to this rewriter in programName.
- getText
Variant 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.
The interval refers to the indexes in the original token stream.
We do not alter the token stream in any way, so the indexes
and intervals are still consistent. Includes any operations done
to the first and last token in the interval. So, if you did an
insertBefore on the first token, you would get that insertion.
The same is true if you do an insertAfter the stop token.
- getText
Variant getText(string programName, Interval interval)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertAfter
void insertAfter(Token t, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertAfter
void insertAfter(int index, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertAfter
void insertAfter(string programName, Token t, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertAfter
void insertAfter(string programName, int index, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertBefore
void insertBefore(Token t, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertBefore
void insertBefore(size_t index, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertBefore
void insertBefore(string programName, Token t, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- insertBefore
void insertBefore(string programName, size_t index, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- reduceToSingleOperationPerIndex
RewriteOperation[size_t] reduceToSingleOperationPerIndex(RewriteOperation[] rewrites)
We need to combine operations and report invalid operations (like
overlapping replaces that are not completed nested). Inserts to
same index need to be combined etc.
- replace
void replace(size_t index, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- replace
void replace(size_t from, size_t to, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- replace
void replace(Token indexT, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- replace
void replace(Token from, Token to, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- replace
void replace(string programName, size_t from, size_t to, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- replace
void replace(string programName, Token from, Token to, Variant text)
Undocumented in source. Be warned that the author may not have intended to support it.
- rollback
void rollback(int instructionIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
- rollback
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. UNTESTED!
Useful for rewriting out a buffered input token stream after doing some augmentation or other manipulations on it.
You can insert stuff, replace, and delete chunks. Note that the operations are done lazily--only if you convert the buffer to a {@link String} with {@link TokenStream#getText()}. This is very efficient because you are not moving data around all the time. As the buffer of tokens is converted to strings, the {@link #getText()} method(s) scan the input token stream and check to see if there is an operation at the current index. If so, the operation is done and then normal {@link String} rendering continues on the buffer. This is like having multiple Turing machine instruction streams (programs) operating on a single input tape.
This rewriter makes no modifications to the token stream. It does not ask the stream to fill itself up nor does it advance the input cursor. The token stream {@link TokenStream#index()} will return the same value before and after any {@link #getText()} call.
The rewriter only works on tokens that you have in the buffer and ignores the current input cursor. If you are buffering tokens on-demand, calling {@link #getText()} halfway through the input will only do rewrites for those tokens in the first half of the file.
Since the operations are done lazily at {@link #getText}-time, operations do not screw up the token index values. That is, an insert operation at token index {@code i} does not change the index values for tokens {@code i}+1..n-1.
Because operations never actually alter the buffer, you may always get the original token stream back without undoing anything. Since the instructions are queued up, you can easily simulate transactions and roll back any changes if there is an error just by removing instructions. For example,