1 /* 2 * Copyright (c) 2012-2017 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.LexerNoViableAltException; 8 9 import antlr.v4.runtime.CharStream; 10 import antlr.v4.runtime.Lexer; 11 import antlr.v4.runtime.RecognitionException; 12 import antlr.v4.runtime.atn.ATNConfigSet; 13 import antlr.v4.runtime.atn.LexerATNSimulator; 14 import antlr.v4.runtime.misc.Interval; 15 import antlr.v4.runtime.misc.Utils; 16 import std.format; 17 18 /** 19 * TODO add class description 20 */ 21 class LexerNoViableAltException : RecognitionException 22 { 23 24 /** 25 * Matching attempted at what input index? 26 */ 27 private int startIndex; 28 29 /** 30 * Which configurations did we try at input.index() that couldn't match input.LA(1)? 31 */ 32 private ATNConfigSet deadEndConfigs; 33 34 public this(Lexer lexer, CharStream input, int startIndex, ATNConfigSet deadEndConfigs) 35 { 36 super(lexer, input, null); 37 this.startIndex = startIndex; 38 this.deadEndConfigs = deadEndConfigs; 39 } 40 41 public int getStartIndex() 42 { 43 return startIndex; 44 } 45 46 public ATNConfigSet getDeadEndConfigs() 47 { 48 return deadEndConfigs; 49 } 50 51 /** 52 * @uml 53 * @override 54 */ 55 public override CharStream getInputStream() 56 { 57 return cast(CharStream)super.getInputStream; 58 } 59 60 /** 61 * @uml 62 * @override 63 */ 64 public override string toString() 65 { 66 string symbol = ""; 67 if (startIndex >= 0 && startIndex < getInputStream().size) { 68 symbol = getInputStream().getText(Interval.of(startIndex,startIndex)); 69 symbol = Utils.escapeWhitespace(symbol, false); 70 } 71 72 return format("%s('%s')", "LexerNoViableAltException", symbol); 73 } 74 75 }