use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class TestsHelpers method createFilterRule.
public static FilterRule createFilterRule(Collection<IEntity> entities) {
// create the filter logic
QueriesEntityFactory qef = QueriesEntityFactory.instance;
Sequence sequence = qef.createSequence(0);
Iterator<IEntity> iterator = entities.iterator();
IEntity baseEntity = iterator.next();
while (iterator.hasNext()) updateFilterBody(baseEntity, iterator.next(), sequence);
if (sequence.wIsEmpty())
return createResolver(FilterRule);
// create the filter rule
TestsEntityFactory tef = TestsEntityFactory.instance;
FilterRule filterRule = tef.createFilterRule(tef.createDescription("Auto-generated filter rule"), createVariable(Name, "filterName"), sequence.wGetAdapter(Statement));
return filterRule;
}
use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class SemanticsInterpreterVisitor method visit.
@Override
public void visit(StructuredVariable entity) {
ActionsEntityFactory aef = ActionsEntityFactory.instance;
QueriesEntityFactory qef = QueriesEntityFactory.instance;
ActionCall actionCall = aef.createActionCall(aef.createLabel("whole:org.whole.lang.semantics:SemanticsActions:1.0.0#toVariableFlatName"), qef.createVariableRefStep("variable").wGetAdapter(ActionsEntityDescriptorEnum.SelectedEntities));
getBindings().wDef("variable", entity);
IEntity varNameEntity = BehaviorUtils.evaluate(actionCall, 0, getOperation());
if (isSelectedFeature(SemanticsUtils.USE_IDENTIFIER_SEMANTICS))
setResult(varNameEntity);
else {
IEntity varValue = BindingUtils.wGet(getBindings(), varNameEntity.wStringValue());
if (varValue == null)
throw new MissingVariableException(entity.toString()).withSourceEntity(entity).withBindings(getBindings());
setResult(varValue);
}
}
use of org.whole.lang.queries.factories.QueriesEntityFactory 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.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class ControlQueriesTest method testIf4.
@Test
public void testIf4() {
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("if4");
QueriesEntityFactory qef = QueriesEntityFactory.instance;
IEntity queryExp1 = qef.createDivision(qef.createIntLiteral(10), qef.createIntLiteral(8));
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, queryExp1, bm);
assertTrue(iterator.hasNext());
IEntity exp1 = iterator.next();
assertSame(queryExp1.wGet(0), exp1);
assertTrue(bm.wIsSet("a"));
assertFalse(bm.wIsSet("b"));
assertFalse(bm.wIsSet("exp1"));
assertFalse(bm.wIsSet("exp2"));
assertTrue(iterator.hasNext());
IEntity exp2 = iterator.next();
assertSame(queryExp1.wGet(1), exp2);
assertFalse(bm.wIsSet("a"));
assertTrue(bm.wIsSet("b"));
assertFalse(bm.wIsSet("exp1"));
assertFalse(bm.wIsSet("exp2"));
assertFalse(iterator.hasNext());
}
use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class ControlQueriesTest method testQueryDecl9.
@Test
public void testQueryDecl9() {
QueriesEntityFactory qef = QueriesEntityFactory.instance;
IEntity queryExp1 = qef.createAddition(qef.createAddition(qef.createIntLiteral(10), qef.createIntLiteral(8)), qef.createAddition(qef.createIntLiteral(2), qef.createIntLiteral(1)));
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("queryDecl9");
assertTrue(Matcher.match(queryExp1, BehaviorUtils.evaluateFirstResult(query, queryExp1)));
}
Aggregations