Search in sources :

Example 1 with NonTerminal

use of org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal 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)1 Grammar (org.whole.lang.grammars.model.Grammar)1 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Grammar (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar)1 NonTerminal (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal)1 IEntity (org.whole.lang.model.IEntity)1 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)1 Path (org.whole.lang.queries.model.Path)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1