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

org.modelcc.language.metamodel.LanguageElement 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.metamodel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.modelcc.AssociativityType;
import org.modelcc.SeparatorPolicy;
import org.modelcc.lexer.recognizer.PatternRecognizer;
import org.modelcc.metamodel.Evaluator;
import org.modelcc.metamodel.ModelElement;

/**
 * Language model element.
 * 
 * @author Luis Quesada ([email protected]) & Fernando Berzal ([email protected])
 */
public class LanguageElement extends ModelElement implements Serializable 
{
    /**
     * Prefix.
     */
    private List prefix;

    /**
     * Suffix.
     */
    private List suffix;

    /**
     * Separator.
     */
    private List separator;

    /**
     * Associativity type.
     */
    private AssociativityType associativity;

    /**
     * Setup method.
     */
    private String setupMethod;

    /**
     * Constraint methods.
     */
    private List constraintMethods;


    /**
     * Positions.
     */
    private Map positions;
    
    /** 
     * Evaluator.
     */
    private Evaluator evaluator;
    
    /**
     * Constructor.
     * @param elementClass the element class
     * @param associativity the associativity
     * @param prefix the prefix
     * @param suffix the suffix
     * @param separator the default separator
     * @param setupMethod the setup method
     * @param constraintMethod the constraint methods
     * @param evaluator the evaluator
     */
    public LanguageElement(
    		Class elementClass,
    		AssociativityType associativity,
    		List prefix,
    		List suffix,
    		List separator,
    		String setupMethod,
    		List constraintMethods,
    		Evaluator evaluator) 
    {
    	super(elementClass);
    	
        this.prefix = prefix;
        if (prefix == null)
            this.prefix = new ArrayList();
        this.suffix = suffix;
        if (suffix == null)
            this.suffix = new ArrayList();
        this.separator = separator;
        if (separator == null)
            this.separator = new ArrayList();
        
        this.associativity = associativity;

        this.setupMethod = setupMethod;
        this.constraintMethods = constraintMethods;
        
        this.evaluator = evaluator;
    }


    // Delimiters
    
    public List getPrefix() {
        return Collections.unmodifiableList(prefix);
    }

    public List getSuffix() {
        return Collections.unmodifiableList(suffix);
    }

    public List getSeparator() {
        return Collections.unmodifiableList(separator);
    }

    public void setPrefix(List prefix) {
		this.prefix = prefix;
	}

	public void setSuffix(List suffix) {
		this.suffix = suffix;
	}

	public void setSeparator(List separator) {
		this.separator = separator;
	}

	// Setup method
	
    public String getSetupMethod() {
        return setupMethod;
    }

    // Constraint method
    
    public List getConstraintMethods() {
        return Collections.unmodifiableList(constraintMethods);
    }

    // Associativity 
    
    public AssociativityType getAssociativity() {
        return associativity;
    }

    public void setAssociativity(AssociativityType associativity) {
		this.associativity = associativity;
	}

    // Position information
    
	public Map getPositions() {
		return Collections.unmodifiableMap(positions);
	}

	public void setPositions(Map positions) {
		this.positions = positions;
	}
	
	public void setPosition(LanguageMember thisMember,LanguageMember otherMember,int[] position,SeparatorPolicy separatorPolicy) {
		positions.put(thisMember,new MemberPositionMetadata(otherMember,position,separatorPolicy));
	}

	// Evaluator
	
    public Evaluator getEvaluator() {
    	return evaluator;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy