1 2 /* 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.commons.jexl3.parser; 19 20 /** 21 * This exception is thrown when parse errors are encountered. 22 */ 23 public class ParseException extends Exception implements JavaccError { 24 /** 25 * The version identifier. 26 */ 27 private static final long serialVersionUID = 1L; 28 /** 29 * Last correct input before error occurs. 30 */ 31 private String after = ""; 32 /** 33 * Error line. 34 */ 35 private int line = -1; 36 /** 37 * Error column. 38 */ 39 private int column = -1; 40 41 /** 42 * This constructor is used by the method "generateParseException" 43 * in the generated parser. Calling this constructor generates 44 * a new object of this type with the fields "currentToken", 45 * "expectedTokenSequences", and "tokenImage" set. 46 * @param currentToken This is the last token that has been consumed successfully. If 47 * this object has been created due to a parse error, the token 48 * following this token will (therefore) be the first error token. 49 * @param expectedTokenSequences Each entry in this array is an array of integers. Each array 50 * of integers represents a sequence of tokens (by their ordinal 51 * values) that is expected at this point of the parse. 52 * @param tokenImage This is a reference to the "tokenImage" array of the generated 53 * parser within which the parse error occurred. This array is 54 * defined in the generated ...Constants interface. 55 */ 56 public ParseException(final Token currentToken, final int[][] expectedTokenSequences, final String[] tokenImage) { 57 super("parse error"); 58 final Token tok = currentToken.next; 59 after = tok.image; 60 line = tok.beginLine; 61 column = tok.beginColumn; 62 } 63 64 /** 65 * Default ctor. 66 */ 67 public ParseException() { 68 } 69 70 /** Constructor with message. */ 71 public ParseException(final String message) { 72 super(message); 73 } 74 75 @Override 76 public int getLine() { 77 return line; 78 } 79 80 @Override 81 public int getColumn() { 82 return column; 83 } 84 85 @Override 86 public String getAfter() { 87 return after; 88 } 89 }