use of org.whole.lang.grammars.model.Grammar 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.Grammar 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());
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testFollowingIterator.
@Test
public void testFollowingIterator() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> tdi = IteratorFactory.<IEntity>descendantOrSelfIterator();
tdi.reset(g);
for (IEntity e : tdi) {
IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>followingIterator();
fi.reset(e);
if (fi.hasNext()) {
IEntityIterator<IEntity> tdi2 = tdi.clone();
tdi2.prune();
assertSame(tdi2.hasNext(), fi.hasNext());
assertSame(tdi2.lookahead(), fi.lookahead());
for (IEntity fe : fi) {
IEntity e1 = tdi2.next();
assertSame(e1, fe);
}
}
}
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testVariableIterator.
@Test
public void testVariableIterator() {
Grammar g = new TestXmlGrammar().create();
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
IEntityIterator<IEntity> i = IteratorFactory.variableIterator("testVar");
i.setBindings(bindings);
assertFalse(i.hasNext());
i.reset(g);
assertFalse(i.hasNext());
bindings.wDef("testVar", g);
assertTrue(i.hasNext());
IEntity g1 = i.next();
assertSame(g, g1);
assertFalse(i.hasNext());
i.reset(g);
assertTrue(i.hasNext());
g1 = i.next();
assertSame(g, g1);
assertFalse(i.hasNext());
bindings = BindingManagerFactory.instance.createBindingManager();
bindings.wDef("testVar", g);
i = IteratorFactory.variableIterator("testVar");
i.setBindings(bindings);
assertTrue(i.hasNext());
g1 = i.next();
assertSame(g, g1);
assertFalse(i.hasNext());
i.reset(g);
IEntityIterator<IEntity> i2 = i.clone();
assertTrue(i.hasNext());
g1 = i.next();
assertSame(g, g1);
assertFalse(i.hasNext());
assertTrue(i2.hasNext());
g1 = i2.next();
assertSame(g, g1);
assertFalse(i2.hasNext());
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testParentIteratorMarkReset.
@Test
public void testParentIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
IEntityIterator<IEntity> i = IteratorFactory.parentIterator();
i.reset(r);
IEntityIterator<IEntity> i2 = i.clone();
assertTrue(i.hasNext());
IEntity e1 = i.next();
assertSame(r.wGetParent(), e1);
assertTrue(i2.hasNext());
assertSame(r.wGetParent(), i2.next());
}
Aggregations