blob: a507e3a54474ac65c83a65555024f70ae9fb3d94 [file] [log] [blame]
Gaurav Agrawal88897632016-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
27 * interface has a syntaxError() method that applies to both lexer and
28 * parser.
29 */
30public class ParseTreeErrorListener extends BaseErrorListener {
31
Gaurav Agrawal88897632016-02-12 18:37:50 +053032 @Override
33 public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
34 String msg, RecognitionException e) {
Gaurav Agrawala04483c2016-02-13 14:23:40 +053035
36 ParserException parserException = new ParserException(msg);
Gaurav Agrawal88897632016-02-12 18:37:50 +053037 parserException.setLine(line);
38 parserException.setCharPosition(charPositionInLine);
Gaurav Agrawala04483c2016-02-13 14:23:40 +053039 throw parserException;
Gaurav Agrawal88897632016-02-12 18:37:50 +053040 }
41}