use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testChildReverseIteratorAdd.
@Test
public void testChildReverseIteratorAdd() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int size = productions.wSize();
int count = 0;
Production pAdded1 = null;
Production pAdded2 = null;
IEntityIterator<Production> i = IteratorFactory.<Production>childReverseIterator();
i.reset(productions);
while (i.hasNext()) {
Production p = i.next();
assertNotSame(pAdded1, p);
assertNotSame(pAdded2, p);
count++;
if (count == 1)
i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
if (count == 3) {
i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
i.add(pAdded2 = GrammarsEntityFactory.instance.createProduction());
}
}
assertEquals(size, count);
assertEquals(size + 3, productions.wSize());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testChildScannerIteratorAdd.
@Test
public void testChildScannerIteratorAdd() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int size = productions.wSize();
int count = 0;
Production pAdded1 = null;
Production pAdded2 = null;
IEntityIterator<Production> i = IteratorFactory.<Production>childScannerIterator();
i.reset(productions);
while (i.hasNext()) {
Production p = i.next();
assertNotSame(pAdded1, p);
assertNotSame(pAdded2, p);
count++;
if (count == 1)
i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
if (count == 3) {
i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
i.add(pAdded2 = GrammarsEntityFactory.instance.createProduction());
}
}
assertEquals(size, count);
assertEquals(size + 3, productions.wSize());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testRootIteratorMarkReset.
@Test
public void testRootIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
IEntityIterator<IEntity> i = IteratorFactory.rootIterator();
i.reset(prologNt);
IEntityIterator<IEntity> i2 = i.clone();
assertTrue(i.hasNext());
assertSame(g, i.next());
assertFalse(i.hasNext());
assertTrue(i2.hasNext());
assertSame(g, i2.next());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testFollowingSiblingIterator.
@Test
public void testFollowingSiblingIterator() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int index = 0;
IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
IEntityIterator<Production> fi = IteratorFactory.<Production>followingSiblingIterator();
fi.reset(p);
int findex = ++index;
for (Production fp : fi) assertSame(productions.wGet(findex++), fp);
}
for (int i = 0; i < g.wSize(); i++) {
IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>followingSiblingIterator();
fi.reset(g.wGet(i));
for (int j = i + 1; j < g.wSize(); j++) assertSame(g.wGet(j), fi.next());
}
for (int i = 0; i < productions.wSize(); i++) {
IEntityIterator<Production> fi = IteratorFactory.<Production>followingSiblingIterator();
fi.reset(productions.wGet(i));
for (int j = i + 1; j < productions.wSize(); j++) assertSame(productions.wGet(j), fi.next());
}
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testChildIterator.
@Test
public void testChildIterator() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int index = 0;
IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(index++), p);
}
index = 0;
ci = IteratorFactory.<Production>childScannerIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(index++), p);
}
index = 0;
ci = IteratorFactory.<Production>childMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(index++), p);
}
}
Aggregations