use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplate1.
@Test
public void testSelectTemplate1() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar model = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
PathExpression query = (PathExpression) tm.create("selectTemplate1");
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
Feature f = (Feature) tuple.wGet(0);
As e = (As) tuple.wGet(1);
assertEquals(e.getName().getValue(), f.getName().wStringValue());
assertEquals(e.getRule().wStringValue(), f.getType().wStringValue());
}
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTuple1.
@Test
public void testSelectTuple1() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("selectTuple1");
int count = 0;
for (IEntity t : BehaviorUtils.compileAndLazyEvaluate(pe1, g)) {
NonTerminal name = (NonTerminal) t.wGet(0);
Rule rule = (Rule) t.wGet(1);
Production prod = (Production) t.wGet(2);
assertEquals(name, prod.getName());
assertSame(rule, prod.getRule());
assertEquals(g.getName(), t.wGet(3));
count++;
}
assertEquals(g.getPhraseStructure().wSize(), count);
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testPrune.
@Test
public void testPrune() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> i1 = IteratorFactory.<IEntity>descendantOrSelfIterator();
i1.reset(g);
IEntityIterator<IEntity> i2 = IteratorFactory.<IEntity>descendantOrSelfIterator();
i2.reset(g);
for (IEntity e : i1) {
assertSame(e, i2.next());
IEntityIterator<IEntity> i12 = i1.clone();
i12.prune();
}
assertSame(i1.hasNext(), i2.hasNext());
i1 = IteratorFactory.<IEntity>descendantOrSelfIterator();
i1.reset(g);
for (IEntity e : i1) {
IEntityIterator<IEntity> i3 = IteratorFactory.<IEntity>followingSiblingIterator();
i3.reset(e);
if (i3.hasNext()) {
IEntityIterator<IEntity> i12 = i1.clone();
i12.prune();
IEntity e1 = i12.next();
IEntity e2 = i3.next();
assertSame(e1, e2);
}
}
}
use of org.whole.lang.grammars.model.Grammar 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.Grammar 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());
}
Aggregations