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