use of org.whole.lang.grammars.model.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();
}
use of org.whole.lang.grammars.model.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();
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class ControlQueriesTest method testCall4.
@Test
public void testCall4() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call4");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
assertEquals("IContent", ((Production) p).getName().getValue());
count++;
}
assertEquals(1, count);
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class ControlQueriesTest method testCall6.
@Test
public void testCall6() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call6");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
assertEquals("IContent", ((Production) p).getName().getValue());
count++;
}
assertEquals(1, count);
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class ControlQueriesTest method testCall3.
@Test
public void testCall3() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call3");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
assertEquals("IContent", ((Production) p).getName().getValue());
count++;
}
assertEquals(1, count);
}
Aggregations