org.modelcc.language.metamodel.SimpleLanguageElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ModelCC Show documentation
Show all versions of ModelCC Show documentation
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.List;
import org.modelcc.AssociativityType;
import org.modelcc.lexer.recognizer.PatternRecognizer;
import org.modelcc.metamodel.Evaluator;
/**
* Simple language element.
*
* @author Luis Quesada ([email protected]) & Fernando Berzal ([email protected])
*/
public final class SimpleLanguageElement extends LanguageElement implements Serializable
{
/**
* Pattern.
*/
private PatternRecognizer pattern;
/**
* Value field.
*/
private String valueField;
/**
* 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 constraintMethods the constraint checking methods
* @param pattern the pattern
* @param valueField the value field
* @param evaluator The evaluator
*/
public SimpleLanguageElement (
Class elementClass,
AssociativityType associativity,
List prefix,
List suffix,
List separator,
String setupMethod,
List constraintMethods,
PatternRecognizer pattern,
String valueField,
Evaluator evaluator)
{
super(elementClass,associativity,prefix,suffix,separator,setupMethod,constraintMethods,evaluator);
this.pattern = pattern;
this.valueField = valueField;
}
// Pattern recognizer
public PatternRecognizer getPatternRecognizer()
{
return pattern;
}
public void setPatternRecognizer(PatternRecognizer pattern)
{
this.pattern = pattern;
}
// Value field
public String getValueField()
{
return valueField;
}
// Matches empty string?
private Boolean canBeEmpty;
public boolean matchesEmptyString()
{
if (canBeEmpty==null)
canBeEmpty = ( getPatternRecognizer().read("")!=null );
return canBeEmpty;
}
}