func (tsr *TokenStreamRewriter) Rollback(program_name string, instruction_index int){
	is, ok  := tsr.programs[program_name]
	if ok{
		tsr.programs[program_name] = is[Min_Token_Index:instruction_index]
	}
}
Rollback the instruction stream for a program so that
the indicated instruction (via instructionIndex) is no
longer in the stream. UNTESTED!
package antlr
import (
"bytes"
"fmt"
)
const(
	Default_Program_Name = "default"
	Program_Init_Size = 100
	Min_Token_Index = 0
)
type RewriteOperation interface {
	Execute(buffer *bytes.Buffer)	int
	String()			string
	GetInstructionIndex()		int
	GetIndex()			int
	GetText()			string
	GetOpName()			string
	GetTokens()			TokenStream
	SetInstructionIndex(val int)
	SetIndex(int)
	SetText(string)
	SetOpName(string)
	SetTokens(TokenStream)
}
type BaseRewriteOperation struct {
	instruction_index		int
	index				int
	text				string
	op_name				string
	tokens				TokenStream
}
func (op *BaseRewriteOperation)GetInstructionIndex() int{
	return op.instruction_index
}
func (op *BaseRewriteOperation)GetIndex() int{
	return op.index
}
func (op *BaseRewriteOperation)GetText() string{
	return op.text
}
func (op *BaseRewriteOperation)GetOpName() string{
	return op.op_name
}
func (op *BaseRewriteOperation)GetTokens() TokenStream{
	return op.tokens
}
func (op *BaseRewriteOperation)SetInstructionIndex(val int){
	op.instruction_index = val
}
func (op *BaseRewriteOperation)SetIndex(val int) {
	op.index = val
}
func (op *BaseRewriteOperation)SetText(val string){
	op.text = val
}
func (op *BaseRewriteOperation)SetOpName(val string){
	op.op_name = val
}
func (op *BaseRewriteOperation)SetTokens(val TokenStream)  {
	op.tokens = val
}
func (op *BaseRewriteOperation) Execute(buffer *bytes.Buffer) int{
	return op.index
}
func (op *BaseRewriteOperation) String() string  {
	return fmt.Sprintf("<%s@%d:\"%s\">",
		op.op_name,
		op.tokens.Get(op.GetIndex()),
		op.text,
	)
}
type InsertBeforeOp struct {
	BaseRewriteOperation
}
func NewInsertBeforeOp(index int, text string, stream TokenStream) *InsertBeforeOp{
	return &InsertBeforeOp{BaseRewriteOperation:BaseRewriteOperation{
		index:index,
		text:text,
		op_name:"InsertBeforeOp",
		tokens:stream,
	}}
}
func (op *InsertBeforeOp) Execute(buffer *bytes.Buffer) int{
	buffer.WriteString(op.text)
	if op.tokens.Get(op.index).GetTokenType() != TokenEOF{
		buffer.WriteString(op.tokens.Get(op.index).GetText())
	}
	return op.index+1
}
func (op *InsertBeforeOp) String() string {
	return op.BaseRewriteOperation.String()
}
type InsertAfterOp struct {
	BaseRewriteOperation
}
func NewInsertAfterOp(index int, text string, stream TokenStream) *InsertAfterOp{
	return &InsertAfterOp{BaseRewriteOperation:BaseRewriteOperation{
		index:index+1,
		text:text,
		tokens:stream,
	}}
}
func (op *InsertAfterOp) Execute(buffer *bytes.Buffer) int {
	buffer.WriteString(op.text)
	if op.tokens.Get(op.index).GetTokenType() != TokenEOF{
		buffer.WriteString(op.tokens.Get(op.index).GetText())
	}
	return op.index+1
}
func (op *InsertAfterOp) String() string {
	return op.BaseRewriteOperation.String()
}
type ReplaceOp struct{
	BaseRewriteOperation
	LastIndex int
}
func NewReplaceOp(from, to int, text string, stream TokenStream)*ReplaceOp {
	return &ReplaceOp{
		BaseRewriteOperation:BaseRewriteOperation{
			index:from,
			text:text,
			op_name:"ReplaceOp",
			tokens:stream,
		},
		LastIndex:to,
	}
}
func (op *ReplaceOp)Execute(buffer *bytes.Buffer) int{
	if op.text != ""{
		buffer.WriteString(op.text)
	}
	return op.LastIndex +1
}
func (op *ReplaceOp) String() string {
	if op.text == "" {
		return fmt.Sprintf("<DeleteOP@%d..%d>",
			op.tokens.Get(op.index), op.tokens.Get(op.LastIndex))
	}
	return fmt.Sprintf("<ReplaceOp@%d..%d:\"%s\">",
		op.tokens.Get(op.index), op.tokens.Get(op.LastIndex), op.text)
}
type TokenStreamRewriter struct {
	tokens						TokenStream
	programs					map[string][]RewriteOperation
	last_rewrite_token_indexes	map[string]int
}
func NewTokenStreamRewriter(tokens TokenStream) *TokenStreamRewriter{
	return &TokenStreamRewriter{
		tokens:						tokens,
		programs:					map[string][]RewriteOperation{
			Default_Program_Name:make([]RewriteOperation,0, Program_Init_Size),
		},
		last_rewrite_token_indexes:	map[string]int{},
	}
}
func (tsr *TokenStreamRewriter) GetTokenStream() TokenStream{
	return tsr.tokens
}