Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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 | /** |
| 25 | * By default, ANTLR sends all errors to standard error, this is changed by |
| 26 | * providing this new implementation of interface ANTLRErrorListener. The |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 27 | * interface has a syntaxError() method that applies to both lexer and parser. |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 28 | */ |
| 29 | public class ParseTreeErrorListener extends BaseErrorListener { |
| 30 | |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 31 | @Override |
| 32 | public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, |
Vinod Kumar S | 48848f7 | 2016-02-25 15:52:16 +0530 | [diff] [blame] | 33 | String msg, RecognitionException e) { |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 34 | |
| 35 | ParserException parserException = new ParserException(msg); |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 36 | parserException.setLine(line); |
| 37 | parserException.setCharPosition(charPositionInLine); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 38 | throw parserException; |
Gaurav Agrawal | 91c6961 | 2016-02-12 18:37:50 +0530 | [diff] [blame] | 39 | } |
| 40 | } |