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.ReplaceOp; 8 9 import antlr.v4.runtime.RewriteOperation; 10 import std.conv; 11 import std.format; 12 import std.variant; 13 14 /** 15 * I'm going to try replacing range from x..y with (y-x)+1 ReplaceOp 16 * instructions. 17 */ 18 class ReplaceOp : RewriteOperation 19 { 20 21 public size_t lastIndex; 22 23 public this(size_t from, size_t to, Variant text) 24 { 25 super(from, text); 26 lastIndex = to; 27 } 28 29 /** 30 * @uml 31 * @override 32 */ 33 public override size_t execute(ref Variant buf) 34 { 35 Variant Null; 36 if (text !is Null) { 37 buf ~= text; 38 } 39 return lastIndex+1; 40 } 41 42 /** 43 * @uml 44 * @override 45 */ 46 public override string toString() 47 { 48 Variant Null; 49 if (text is Null) 50 { 51 return format("<DeleteOp@%s..%s>", tokens.get(to!int(index)), 52 tokens.get(to!int(lastIndex))); 53 } 54 return format("<ReplaceOp@%s..%s:\"%s\">", tokens.get(to!int(index)), 55 tokens.get(to!int(lastIndex)), text); 56 } 57 58 }