All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.modelcc.parser.ParserFactory Maven / Gradle / Ivy

Go to download

ModelCC is a model-based parser generator (a.k.a. compiler compiler) that decouples language specification from language processing, avoiding some of the problems caused by grammar-driven parser generators. ModelCC receives a conceptual model as input, along with constraints that annotate it. It is then able to create a parser for the desired textual language and the generated parser fully automates the instantiation of the language conceptual model. ModelCC also includes a built-in reference resolution mechanism that results in abstract syntax graphs, rather than mere abstract syntax trees.

The newest version!
/*
 * ModelCC, distributed under ModelCC Shared Software License, www.modelcc.org
 */


package org.modelcc.parser;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.modelcc.metamodel.Model;
import org.modelcc.lexer.Lexer;
import org.modelcc.lexer.recognizer.PatternRecognizer;
import org.modelcc.lexer.recognizer.regexp.RegExpPatternRecognizer;
import org.modelcc.lexer.recognizer.regexp.RegExps;
import org.modelcc.parser.fence.FenceParserFactory;

/**
 * ModelCC Parser Generator: Generic interface for parsers.
 * 
 * @author Luis Quesada ([email protected]) & Fernando Berzal ([email protected])
 */
public abstract class ParserFactory implements Serializable 
{

	public abstract Parser createParser (Model m) throws ParserException;
	
    public abstract Parser createParser (Model m, Lexer lexer) throws ParserException;

    public abstract Parser createParser (Model m, Model skip) throws ParserException;
	
    public abstract Parser createParser (Model m, Set skip) throws ParserException;

    /**
     * Current parser factory
     */
    private static ParserFactory factory = new FenceParserFactory();

	
	public static ParserFactory getParserFactory ()
	{
		return ParserFactory.factory;
	}

	public static void setParserFactory (ParserFactory factory)
	{
		ParserFactory.factory = factory;
	}
	


    public final static Set WHITESPACE = new HashSet(Arrays.asList(new RegExpPatternRecognizer(RegExps.WHITESPACE)));

    /**
     * Creates a parser (convenience method)
     * @param m the model
     * @return the parser
     * @throws ParserException
     */
    public static Parser create (Model m) throws ParserException 
    {
        return factory.createParser(m);
    }

    /**
     * Creates a parser (convenience method)
     * @param m the model
     * @param lexer the lexer
     * @return the parser
     * @throws ParserException
     */
    public static Parser create (Model m, Lexer lexer) throws ParserException 
    {
    	return factory.createParser(m,lexer);
    }

    /**
     * Creates a parser (convenience method)
     * @param m the model
     * @param skip the skip model
     * @return the parser
     * @throws ParserException
     */
    public static Parser create (Model m, Model skip) throws ParserException 
    {
    	return factory.createParser(m,skip);
    }

    /**
     * Creates a parser (convenience method)
     * @param m the model
     * @param skip the skip set
     * @return the parser
     * @throws ParserException
     */
    public static Parser create (Model m, Set skip) throws ParserException 
    {
    	return factory.createParser(m,skip);
    }
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy