Package eu.bitfish.jcf.parser.antlr4

Source Code of eu.bitfish.jcf.parser.antlr4.ANTLR4Parser

/*
* This file is part of JCF.

* JCF is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JCF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with JCF.  If not, see <http://www.gnu.org/licenses/>.
*/
package eu.bitfish.jcf.parser.antlr4;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenStream;

import eu.bitfish.jcf.common.expression.AbstractExpression;
import eu.bitfish.jcf.parser.AbstractParser;
import eu.bitfish.jcf.parser.antlr4.error.ExceptionErrorStrategy;
import eu.bitfish.jcf.parser.antlr4.generated.jcfLexer;
import eu.bitfish.jcf.parser.antlr4.generated.jcfParser;
import eu.bitfish.jcf.parser.exception.ParsingException;

/**
* ANTLR4 parser implementation.
*
* @author Michael Sieber
*
*/
public class ANTLR4Parser extends AbstractParser {

  @Override
  protected AbstractExpression doParse(String query) throws ParsingException {
    CharStream charStream = new ANTLRInputStream(query);
    jcfLexer lexer = new jcfLexer(charStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    jcfParser parser = new jcfParser(tokens);
    parser.setErrorHandler(new ExceptionErrorStrategy());
    parser.query();

    return parser.root;
  }

}
TOP

Related Classes of eu.bitfish.jcf.parser.antlr4.ANTLR4Parser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.