Search in sources :

Example 1 with Grammar

use of org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar 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)

Example 2 with Grammar

use of org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar in project whole by wholeplatform.

the class GrammarsContentAssistVisitor method calculateNonTerminalValues.

public static Set<String> calculateNonTerminalValues(IEntity e) {
    Grammar grammar = Matcher.findAncestor(Grammar, e);
    if (grammar != null) {
        Set<String> names = new HashSet<String>();
        IEntity parent = e.wGetParent();
        ILanguageKit languageKit = getLanguageKitIfExists(grammar);
        if (languageKit != null) {
            if (!grammar.getLexicalStructure().equals(parent.wGetParent()))
                names.addAll(languageKit.getEntityDescriptorEnum().names());
            if (!parent.wGetFeatureDescriptor(e).equals(name)) {
                QueriesEntityFactory qef = QueriesEntityFactory.instance;
                Path allTokenNames = qef.createPath(qef.createSequence(qef.createFeatureStep("lexicalStructure"), qef.createFeatureStep("phraseStructure")), qef.createChildStep(), qef.createFilter(qef.createFeatureStep("name"), qef.createKindTest(KindTestEnum.IMPL)));
                for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(allTokenNames, grammar)) names.add(nt.getValue());
            }
        } else {
            AbstractPatternFilterIterator<NonTerminal> i = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(NonTerminal);
            i.reset(grammar);
            for (NonTerminal nt : i) if (EntityUtils.isNotResolver(nt))
                names.add(nt.getValue());
        }
        return names;
    }
    return Collections.emptySet();
}
Also used : Path(org.whole.lang.queries.model.Path) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) NonTerminal(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal) NonTerminal(org.whole.lang.grammars.model.NonTerminal) 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

HashSet (java.util.HashSet)2 Grammar (org.whole.lang.grammars.model.Grammar)2 Grammar (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Production (org.whole.lang.grammars.model.Production)1 NonTerminal (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal)1 Production (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Production)1 IEntity (org.whole.lang.model.IEntity)1 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)1 Path (org.whole.lang.queries.model.Path)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1