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 import std.variant; 13 14 /** 15 * TODO add class description 16 */ 17 class RewriteOperation : TokenStreamRewriter 18 { 19 20 /** 21 * What index into rewrites List are we? 22 */ 23 public size_t instructionIndex; 24 25 /** 26 * Token buffer index. 27 */ 28 public size_t index; 29 30 public Variant text; 31 32 public this(size_t index) 33 { 34 this.index = index; 35 } 36 37 public this(size_t index, Variant text) 38 { 39 this.index = index; 40 this.text = text; 41 } 42 43 /** 44 * Execute the rewrite operation by possibly adding to the buffer. 45 * Return the index of the next token to operate on. 46 */ 47 public size_t execute(ref Variant buf) 48 { 49 return index; 50 } 51 52 /** 53 * @uml 54 * @override 55 */ 56 public override string toString() 57 { 58 import std.array : split; 59 auto opName = this.classinfo.name.split(".")[$-1]; 60 return format("<%s@%s:\"%s\">", opName, tokens.get(to!int(index)), text); 61 } 62 63 }