use of org.whole.lang.grammars.model.Productions in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testProduct4.
@Test
public void testProduct4() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
PathExpression pe1 = (PathExpression) tm.create("testProduct4");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
int count = 0;
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
Production p = (Production) productions.wGet(count++);
Assert.assertSame(p.getName(), bm.wGet("name"));
Assert.assertSame(p.getRule(), bm.wGet("rule"));
Assert.assertSame(p.getName(), tuple.wGet(0));
Assert.assertSame(p.getRule(), tuple.wGet(1));
}
Assert.assertEquals(g.getPhraseStructure().wSize(), count);
}
use of org.whole.lang.grammars.model.Productions in project whole by wholeplatform.
the class IteratorFactoryTest method testTopDownIterator.
@Test
public void testTopDownIterator() throws Exception {
Grammar g = new TestXmlGrammar().create();
final Productions productions = g.getPhraseStructure();
final IEntityIterator<IEntity> ci = IteratorFactory.<IEntity>descendantOrSelfIterator();
ci.reset(productions);
IVisitor v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {
public void visit(IEntity entity) {
if (ci.hasNext())
assertSame(entity, ci.next());
else
fail();
}
}, false);
v.visit(productions);
final IEntityIterator<IEntity> ci2 = IteratorFactory.<IEntity>descendantOrSelfScannerIterator();
ci2.reset(productions);
v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {
public void visit(IEntity entity) {
if (EntityUtils.isResolver(entity))
return;
if (ci2.hasNext())
assertSame(entity, ci2.next());
else
fail();
}
}, false);
v.visit(productions);
final IEntityIterator<IEntity> ci3 = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci3.reset(productions);
v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {
public void visit(IEntity entity) {
if (!Matcher.match(GrammarsEntityDescriptorEnum.Production, entity))
return;
if (ci3.hasNext())
assertSame(entity, ci3.next());
else
fail();
}
}, false);
v.visit(productions);
IEntity artifactsModel = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
Set<Type> typeSet = new HashSet<Type>();
IEntityIterator<Type> ci4 = IteratorFactory.<Type>descendantOrSelfMatcherIterator().withPattern(ModelsEntityFactory.instance.createSimpleName("Atifacts"));
ci4.reset(artifactsModel);
while (ci4.hasNext()) assertTrue(typeSet.add(ci4.next()));
}
use of org.whole.lang.grammars.model.Productions in project whole by wholeplatform.
the class IteratorFactoryTest method testChildReverseIteratorRemove.
@Test
public void testChildReverseIteratorRemove() {
Grammar g = new TestXmlGrammar().create();
Productions productions = EntityUtils.clone(g.getPhraseStructure());
IEntityIterator<Production> ci = IteratorFactory.<Production>childReverseIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(productions.wSize() - 1), p);
ci.remove();
}
assertEquals(0, productions.wSize());
productions = EntityUtils.clone(g.getPhraseStructure());
ci = IteratorFactory.<Production>childReverseScannerIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(productions.wSize() - 1), p);
ci.remove();
}
assertEquals(0, productions.wSize());
productions = EntityUtils.clone(g.getPhraseStructure());
ci = IteratorFactory.<Production>childReverseMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(productions.wSize() - 1), p);
ci.remove();
}
assertEquals(0, productions.wSize());
}
use of org.whole.lang.grammars.model.Productions in project whole by wholeplatform.
the class IteratorFactoryTest method testChildIteratorRemove.
@Test
public void testChildIteratorRemove() {
Grammar g = new TestXmlGrammar().create();
Productions productions = EntityUtils.clone(g.getPhraseStructure());
IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(0), p);
ci.remove();
}
assertEquals(0, productions.wSize());
productions = EntityUtils.clone(g.getPhraseStructure());
ci = IteratorFactory.<Production>childScannerIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(0), p);
ci.remove();
}
assertEquals(0, productions.wSize());
productions = EntityUtils.clone(g.getPhraseStructure());
ci = IteratorFactory.<Production>childMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(0), p);
ci.remove();
}
assertEquals(0, productions.wSize());
}
use of org.whole.lang.grammars.model.Productions in project whole by wholeplatform.
the class IteratorFactoryTest method testFilterByIndexIterator.
@Test
public void testFilterByIndexIterator() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
Production p = (Production) productions.wGet(1);
IEntityIterator<?> i = IteratorFactory.filterByIndexIterator(IteratorFactory.followingSiblingIterator(), 0);
i.reset(p);
assertSingleton(i, productions.wGet(2));
i = IteratorFactory.filterByIndexIterator(IteratorFactory.followingSiblingIterator(), 1);
i.reset(p);
assertSingleton(i, productions.wGet(3));
i = IteratorFactory.filterByIndexIterator(IteratorFactory.ancestorOrSelfIterator(), 2);
i.reset(p);
assertSingleton(i, productions.wGetParent());
i = IteratorFactory.filterByIndexIterator(IteratorFactory.descendantOrSelfIterator(), 1);
i.reset(p);
assertSingleton(i, p.getName());
}
Aggregations