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

org.modelcc.language.syntax.ParserMetadata 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.language.syntax;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.modelcc.IModel;
import org.modelcc.language.metamodel.LanguageModel;

/**
 * Parser metadata.
 * 
 * @author Luis Quesada ([email protected]) & Fernando Berzal ([email protected])
 */
public final class ParserMetadata implements Serializable 
{
	/**
	 * Language model.
	 */
	private LanguageModel model;
	
	/**
	 * Object builder
	 */
	private ObjectBuilder builder;
	
    /**
     * Object map.
     */ 
    private Map map;

    /**
     * Key map.
     */
    private Map> keys;
   
    /**
     * Lazy references.
     */
    private Set lazyReferences;
    
    /**
     * Use map
     */
    private Map> used;
    
    /**
     * Constructor.
     */
    public ParserMetadata (LanguageModel model) 
    {
    	this.model = model;
    	this.builder = new ObjectBuilder(model);
        this.keys = new HashMap>();
        this.map = new HashMap();
        this.lazyReferences = new HashSet();
        this.used = null;
    }

    // Getters
    
    public LanguageModel getModel ()
    {
    	return model;
    }
    
    public void add (IModel element)
    {
    	Map idmap = getKeys(element.getClass());
    	
        ObjectWrapper wrapper = ObjectWrapper.createKeyWrapper(element, getModel(), getMap());
        
        if (!idmap.containsKey(wrapper)) {
        	idmap.put(wrapper, element);
        	map.put(element, wrapper);
        }
    }
    
    public void addReference (Object obj, Symbol t)
    {
		Map idmap = getKeys(obj.getClass());
		
		ObjectWrapper kw = ObjectWrapper.createKeyWrapper(obj, getModel(), getMap());

		if (idmap.containsKey(kw)) {
		    t.setUserData(idmap.get(kw));
		} else {
		    getLazyReferences().add(t);
		}
    }
    
    public Map> getKeys() 
    {
        return keys;
    }

    public Map getKeys (Class c) 
    {
        Map idmap = keys.get(c);

        if (idmap == null) {
            idmap = new HashMap();
            keys.put(c,idmap);
        }
    	
        return idmap;
    }
    
    
    public Map getMap() 
    {
        return map;
    }

    public Set getLazyReferences() 
    {
        return lazyReferences;
    }    
    
    // Use map

    public Map> getUsed ()
    {
    	return used;
    }
    
    public void setUsed (Map> used)
    {
    	this.used = used;
    }
    
    // Builder
    
    public ObjectBuilder getBuilder ()
    {
    	return builder;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy