Search in sources :

Example 1 with Production

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) Production(org.whole.lang.grammars.model.Production) ArrayList(java.util.ArrayList)

Example 2 with Production

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]);
}
Also used : Production(org.whole.lang.grammars.model.Production) Method(java.lang.reflect.Method)

Example 3 with Production

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());
}
Also used : Production(org.whole.lang.grammars.model.Production)

Example 4 with Production

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));
        }
    }
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) GrammarsEntityDescriptorEnum(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum) HashMap(java.util.HashMap) NonTerminal(org.whole.lang.grammars.model.NonTerminal) ILanguageKit(org.whole.lang.reflect.ILanguageKit) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) Production(org.whole.lang.grammars.model.Production) DataTerminal(org.whole.lang.grammars.model.DataTerminal) Rule(org.whole.lang.grammars.model.Rule)

Example 5 with Production

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();
}
Also used : FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) Production(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Production) Production(org.whole.lang.grammars.model.Production) Grammar(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar) Grammar(org.whole.lang.grammars.model.Grammar) ILanguageKit(org.whole.lang.reflect.ILanguageKit) HashSet(java.util.HashSet)

Aggregations

Production (org.whole.lang.grammars.model.Production)55 Grammar (org.whole.lang.grammars.model.Grammar)43 Test (org.junit.Test)41 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)41 ITemplateManager (org.whole.lang.templates.ITemplateManager)26 PathExpression (org.whole.lang.queries.model.PathExpression)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 IEntity (org.whole.lang.model.IEntity)18 IBindingManager (org.whole.lang.bindings.IBindingManager)14 Productions (org.whole.lang.grammars.model.Productions)13 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 Rule (org.whole.lang.grammars.model.Rule)3 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)3 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Category (org.junit.experimental.categories.Category)1