blob: af81d6f0a1c2028f6b58b282a8b1739030400367 [file] [log] [blame]
Gaurav Agrawal88897632016-02-12 18:37:50 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawal88897632016-02-12 18:37:50 +05303 *
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/**
Bharat saraswald9822e92016-04-05 15:13:44 +053025 * Represent the parse tree error listener.
Gaurav Agrawal88897632016-02-12 18:37:50 +053026 * By default, ANTLR sends all errors to standard error, this is changed by
27 * providing this new implementation of interface ANTLRErrorListener. The
Vinod Kumar S71cba682016-02-25 15:52:16 +053028 * interface has a syntaxError() method that applies to both lexer and parser.
Gaurav Agrawal88897632016-02-12 18:37:50 +053029 */
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,
Vinod Kumar S71cba682016-02-25 15:52:16 +053034 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}