use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class ProductionPart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
Production production = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(3);
list.add(production.getName());
list.add(production.getRule());
list.add(production.getTemplate());
return list;
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class AbstractPredictiveParser method wMatch.
protected int wMatch(Rule rule) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
String lookaheadMethodName = "match" + ((Production) rule).getName().getValue();
Method method = getClass().getMethod(lookaheadMethodName, new Class<?>[0]);
return (Integer) method.invoke(this, new Object[0]);
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class ParserTemplateFactory method createActiveRule.
protected ActiveRule createActiveRule(NonTerminal nt) {
Production p = getProduction(nt);
// FIXME mapping
ed = edEnum.valueOf(nt.getValue());
if (!ed.getEntityKind().isData())
builder.wEntity_(ed);
return new ActiveRule(p.getName(), p.getRule());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class GenericGrammarBasedValidatorVisitor method calculateDataTerminals.
private void calculateDataTerminals(Grammar grammar) {
this.dataTerminals = new HashMap<EntityDescriptor<?>, DataTerminal>();
// TODO ensure grammar normalized
Map<String, Rule> productions = new HashMap<String, Rule>();
IEntityIterator<Production> pi = IteratorFactory.<Production>childIterator();
pi.reset(grammar.getPhraseStructure());
for (Production p : pi) productions.put(p.getName().getValue(), p.getRule());
Map<String, Rule> lexicon = new HashMap<String, Rule>();
IEntityIterator<Production> li = IteratorFactory.<Production>childIterator();
li.reset(grammar.getLexicalStructure());
for (Production p : li) lexicon.put(p.getName().getValue(), p.getRule());
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(GrammarsUtils.getLanguageURI(grammar), false, null);
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
for (EntityDescriptor<?> ed : edEnum) if (EntityUtils.isData(ed)) {
Rule production = productions.get(ed.getName());
if (!ed.getDataKind().isEnumValue()) {
DataTerminal dataTerminal = Matcher.find(GrammarsEntityDescriptorEnum.DataTerminal, production, false);
if (dataTerminal == null) {
NonTerminal nonTerminal = Matcher.find(GrammarsEntityDescriptorEnum.NonTerminal, production, false);
dataTerminal = Matcher.find(GrammarsEntityDescriptorEnum.DataTerminal, lexicon.get(nonTerminal.getValue()), false);
}
dataTerminals.put(ed, EntityUtils.clone(dataTerminal));
}
}
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class GrammarsContentAssistVisitor method calculateAsNameValues.
public static Set<String> calculateAsNameValues(IEntity e) {
Grammar grammar = Matcher.findAncestor(Grammar, e);
if (grammar != null) {
Production production = Matcher.findAncestor(Production, e);
String entityName = production.getName().getValue();
ILanguageKit languageKit = getLanguageKitIfExists(grammar);
if (languageKit != null) {
EntityDescriptor<?> ed = languageKit.getEntityDescriptorEnum().valueOf(entityName);
if (ed != null) {
Set<String> names = new HashSet<String>();
for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) names.add(fd.getName());
return names;
}
}
}
return Collections.emptySet();
}
Aggregations