blob: 71f99fe703c856a7a9815d18f55ca5362878f9e6 [file] [log] [blame]
Gaurav Agrawal91c69612016-02-12 18:37:50 +05301/*
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
17package org.onosproject.yangutils.parser.impl.parserutils;
18
19import org.antlr.v4.runtime.BaseErrorListener;
20import org.antlr.v4.runtime.RecognitionException;
21import org.antlr.v4.runtime.Recognizer;
22import 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 S48848f72016-02-25 15:52:16 +053027 * interface has a syntaxError() method that applies to both lexer and parser.
Gaurav Agrawal91c69612016-02-12 18:37:50 +053028 */
29public class ParseTreeErrorListener extends BaseErrorListener {
30
Gaurav Agrawal91c69612016-02-12 18:37:50 +053031 @Override
32 public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
Vinod Kumar S48848f72016-02-25 15:52:16 +053033 String msg, RecognitionException e) {
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +053034
35 ParserException parserException = new ParserException(msg);
Gaurav Agrawal91c69612016-02-12 18:37:50 +053036 parserException.setLine(line);
37 parserException.setCharPosition(charPositionInLine);
Gaurav Agrawal2737d2a2016-02-13 14:23:40 +053038 throw parserException;
Gaurav Agrawal91c69612016-02-12 18:37:50 +053039 }
40}