Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.parser.impl.parserutils; |
| 18 | |
| 19 | import org.antlr.v4.runtime.BaseErrorListener; |
| 20 | import org.antlr.v4.runtime.RecognitionException; |
| 21 | import org.antlr.v4.runtime.Recognizer; |
| 22 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 23 | |
| 24 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame^] | 25 | * Represent the parse tree error listener. |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 26 | * By default, ANTLR sends all errors to standard error, this is changed by |
| 27 | * providing this new implementation of interface ANTLRErrorListener. The |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 28 | * interface has a syntaxError() method that applies to both lexer and parser. |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 29 | */ |
| 30 | public class ParseTreeErrorListener extends BaseErrorListener { |
| 31 | |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 32 | @Override |
| 33 | public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 34 | String msg, RecognitionException e) { |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 35 | |
| 36 | ParserException parserException = new ParserException(msg); |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 37 | parserException.setLine(line); |
| 38 | parserException.setCharPosition(charPositionInLine); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 39 | throw parserException; |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 40 | } |
| 41 | } |