use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testAncestorIteratorMarkReset.
@Test
public void testAncestorIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
IEntityIterator<IEntity> i = IteratorFactory.ancestorIterator();
i.reset(r);
i.next();
i.next();
IEntityIterator<IEntity> i2 = i.clone();
IEntityIterator<IEntity> i3 = i.clone();
IEntity e1 = i.next();
IEntity e2 = i.next();
assertSame(e1, i2.next());
assertSame(e1, i3.next());
assertSame(e2, i3.next());
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testAncestorOrSelfIteratorRemoveSet.
@Test
public void testAncestorOrSelfIteratorRemoveSet() {
Grammar g = new TestXmlGrammar().create();
MiscEntityFactory mef = MiscEntityFactory.instance(RegistryConfigurations.RESOLVER);
Any any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, g);
Misc innerMisc = mef.createMisc(any);
any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, innerMisc);
Misc outerMisc = mef.createMisc(any);
Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
i.reset(r);
IEntity next = null;
while (i.hasNext()) {
next = i.next();
if (Matcher.match(MiscEntityDescriptorEnum.Misc, next))
break;
}
assertSame(innerMisc, next);
i.set(EntityUtils.clone(any));
assertEquals(1, outerMisc.wSize());
Rule r2 = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
assertTrue(Matcher.match(r, r2));
assertNotSame(r, r2);
i.remove();
assertEquals(0, outerMisc.wSize());
i.reset(r2);
while (i.hasNext()) {
next = i.next();
if (i.hasNext())
i.remove();
}
assertFalse(EntityUtils.hasParent(next));
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testChildReverseIteratorMarkReset.
@Test
public void testChildReverseIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> i = IteratorFactory.<IEntity>childReverseIterator();
i.reset(g);
i.next();
i.next();
IEntityIterator<IEntity> i2 = i.clone();
IEntityIterator<IEntity> i3 = i.clone();
IEntity e1 = i.next();
IEntity e2 = i.next();
assertSame(e1, i2.next());
assertSame(e1, i3.next());
assertSame(e2, i3.next());
}
use of org.whole.lang.grammars.model.Grammar 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);
}
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class IteratorFactoryTest method testAncestorOrSelfIteratorMarkReset.
@Test
public void testAncestorOrSelfIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
i.reset(r);
IEntity e1 = i.next();
assertSame(r, e1);
e1 = i.next();
assertSame(r.wGetParent(), e1);
IEntityIterator<IEntity> i2 = i.clone();
IEntityIterator<IEntity> i3 = i.clone();
e1 = i.next();
IEntity e2 = i.next();
assertSame(e1, i2.next());
assertSame(e1, i3.next());
assertSame(e2, i3.next());
}
Aggregations