1 /*
2  * Copyright (c) 2012-2019 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6 
7 module antlr.v4.runtime.RewriteOperation;
8 
9 import antlr.v4.runtime.TokenStreamRewriter;
10 import std.conv;
11 import std.format;
12 
13 /**
14  * TODO add class description
15  */
16 class RewriteOperation : TokenStreamRewriter
17 {
18 
19     /**
20      * What index into rewrites List are we?
21      */
22     public size_t instructionIndex;
23 
24     /**
25      * Token buffer index.
26      */
27     public size_t index;
28 
29     public string text;
30 
31     public this(size_t index)
32     {
33         this.index = index;
34     }
35 
36     public this(size_t index, string text)
37     {
38         this.index = index;
39         this.text = text;
40     }
41 
42     /**
43      * Execute the rewrite operation by possibly adding to the buffer.
44      *  Return the index of the next token to operate on.
45      */
46     public size_t execute(ref string buf)
47     {
48         return index;
49     }
50 
51     /**
52      * @uml
53      * @override
54      */
55     public override string toString()
56     {
57         import std.array : split;
58         auto opName = this.classinfo.name.split(".")[$-1];
59         return format("<%s@%s:\"%s\">", opName, tokens.get(to!int(index)), text);
60     }
61 
62 }