1 /*
2 * CSVeed (https://github.com/42BV/CSVeed)
3 *
4 * Copyright 2013-2023 CSVeed.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of The Apache Software License,
8 * Version 2.0 which accompanies this distribution, and is available at
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 */
11 package org.csveed.token;
12
13 /**
14 * The Class ParseException.
15 */
16 public class ParseException extends Exception {
17
18 /** The Constant serialVersionUID. */
19 private static final long serialVersionUID = 1L;
20
21 /** The state. */
22 private final ParseState state;
23
24 /** The symbol. */
25 private final EncounteredSymbol symbol;
26
27 /** The symbol character. */
28 private final int symbolCharacter;
29
30 /**
31 * Instantiates a new parses the exception.
32 *
33 * @param state
34 * the state
35 * @param symbolCharacter
36 * the symbol character
37 * @param symbol
38 * the symbol
39 */
40 public ParseException(ParseState state, int symbolCharacter, EncounteredSymbol symbol) {
41 this.state = state;
42 this.symbolCharacter = symbolCharacter;
43 this.symbol = symbol;
44 }
45
46 /**
47 * Gets the state.
48 *
49 * @return the state
50 */
51 public ParseState getState() {
52 return state;
53 }
54
55 /**
56 * Gets the symbol.
57 *
58 * @return the symbol
59 */
60 public EncounteredSymbol getSymbol() {
61 return symbol;
62 }
63
64 /**
65 * Gets the symbol character.
66 *
67 * @return the symbol character
68 */
69 public int getSymbolCharacter() {
70 return symbolCharacter;
71 }
72
73 @Override
74 public String getMessage() {
75 return "Illegal state transition: Parsing symbol " + getSymbol() + " [" + getSymbolCharacter() + "] in state "
76 + getState();
77 }
78
79 }