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 * https://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 * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may subsequently be initialized by a call to
43 * {@link #initCause}.
44 */
45 public ParseException() {
46 }
47
48 /**
49 * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to
50 * {@link #initCause}.
51 *
52 * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
53 */
54 public ParseException(final String message) {
55 super(message);
56 }
57
58 /**
59 * This constructor is used by the method "generateParseException"
60 * in the generated parser. Calling this constructor generates
61 * a new object of this type with the fields "currentToken",
62 * "expectedTokenSequences", and "tokenImage" set.
63 * @param currentToken This is the last token that has been consumed successfully. If
64 * this object has been created due to a parse error, the token
65 * following this token will (therefore) be the first error token.
66 * @param expectedTokenSequences Each entry in this array is an array of integers. Each array
67 * of integers represents a sequence of tokens (by their ordinal
68 * values) that is expected at this point of the parse.
69 * @param tokenImage This is a reference to the "tokenImage" array of the generated
70 * parser within which the parse error occurred. This array is
71 * defined in the generated ...Constants interface.
72 */
73 public ParseException(final Token currentToken, final int[][] expectedTokenSequences, final String[] tokenImage) {
74 super("parse error");
75 final Token tok = currentToken.next;
76 after = tok.image;
77 line = tok.beginLine;
78 column = tok.beginColumn;
79 }
80
81 @Override
82 public String getAfter() {
83 return after;
84 }
85
86 @Override
87 public int getColumn() {
88 return column;
89 }
90
91 @Override
92 public int getLine() {
93 return line;
94 }
95 }