001 002 /* 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.commons.jexl2.parser; 019 020 /** 021 * This exception is thrown when parse errors are encountered. 022 */ 023 public class ParseException extends Exception { 024 /** 025 * The version identifier. 026 */ 027 private static final long serialVersionUID = 1L; 028 /** 029 * Last correct input before error occurs. 030 */ 031 private String after = ""; 032 /** 033 * Error line. 034 */ 035 private int line = -1; 036 /** 037 * Error column. 038 */ 039 private int column = -1; 040 041 /** 042 * Gets the line number. 043 * @return line number. 044 */ 045 public int getLine() { 046 return line; 047 } 048 049 /** 050 * Gets the column number. 051 * @return the column. 052 */ 053 public int getColumn() { 054 return column; 055 } 056 057 /** 058 * Gets the last correct input. 059 * @return the string after which the error occured 060 */ 061 public String getAfter() { 062 return after; 063 } 064 065 /** 066 * This constructor is used by the method "generateParseException" 067 * in the generated parser. Calling this constructor generates 068 * a new object of this type with the fields "currentToken", 069 * "expectedTokenSequences", and "tokenImage" set. 070 * @param currentToken This is the last token that has been consumed successfully. If 071 * this object has been created due to a parse error, the token 072 * followng this token will (therefore) be the first error token. 073 * @param expectedTokenSequences Each entry in this array is an array of integers. Each array 074 * of integers represents a sequence of tokens (by their ordinal 075 * values) that is expected at this point of the parse. 076 * @param tokenImage This is a reference to the "tokenImage" array of the generated 077 * parser within which the parse error occurred. This array is 078 * defined in the generated ...Constants interface. 079 */ 080 public ParseException(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage) { 081 super("parse error"); 082 Token tok = currentToken.next; 083 after = tok.image; 084 line = tok.beginLine; 085 column = tok.beginColumn; 086 } 087 088 /** 089 * Default ctor. 090 */ 091 public ParseException() { 092 super(); 093 } 094 095 /** Constructor with message. */ 096 public ParseException(String message) { 097 super(message); 098 } 099 }