use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testTopDownScannerIteratorMarkReset.
@Test
public void testTopDownScannerIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfScannerIterator();
i.reset(g);
for (int j = 0; j < 15; j++) i.next();
IEntityIterator<IEntity> i2 = i.clone();
IEntityIterator<IEntity> i3 = i.clone();
IEntity e1 = i.next();
IEntity e2 = i.next();
for (int j = 0; j < 7; j++) i.next();
assertSame(e1, i2.next());
assertSame(e1, i3.next());
assertSame(e2, i3.next());
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testComposeIterator.
@Test
public void testComposeIterator() {
Grammar g = new TestXmlGrammar().create();
// query: g/phraseStructure/child()[ED = Production]/rule//[ED = Production]
IEntityIterator<Production> pi = IteratorFactory.composeIterator(IteratorFactory.<Production>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production), IteratorFactory.featureByNameIterator("rule"), IteratorFactory.<Production>childMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production), IteratorFactory.featureByNameIterator("phraseStructure"));
pi.reset(g);
Set<String> l = new HashSet<String>();
for (Production p : pi) l.add(p.getName().getValue());
assertEquals(16, l.size());
NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
// query: g/phraseStructure/0/rule/0/name
IEntityIterator<? extends IEntity> nti = IteratorFactory.composeIterator(IteratorFactory.featureByNameIterator("name"), IteratorFactory.featureByIndexIterator(0), IteratorFactory.featureByNameIterator("rule"), IteratorFactory.featureByIndexIterator(0), IteratorFactory.featureByNameIterator("phraseStructure"));
nti.reset(g);
assertTrue(nti.hasNext());
assertSame(prologNt, nti.next());
nti.reset(g.getPhraseStructure());
assertFalse(nti.hasNext());
nti.reset(g);
assertTrue(nti.hasNext());
assertSame(prologNt, nti.next());
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testDescendantAndDescendantOrSelfIterators.
@Test
public void testDescendantAndDescendantOrSelfIterators() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> dsi = IteratorFactory.<IEntity>descendantOrSelfIterator();
dsi.reset(g);
IEntityIterator<IEntity> di = IteratorFactory.<IEntity>descendantIterator();
di.reset(g);
assertSame(g, dsi.next());
assertSame(dsi.hasNext(), di.hasNext());
boolean hasNext;
do {
assertSame(dsi.lookahead(), di.lookahead());
assertSame(dsi.next(), di.next());
assertSame(hasNext = dsi.hasNext(), di.hasNext());
} while (hasNext);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testChildByNameAndByIndexIterators.
@Test
public void testChildByNameAndByIndexIterators() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> i1 = IteratorFactory.featureByNameIterator("phraseStructure");
i1.reset(g);
assertTrue(i1.hasNext());
assertSame(g.getPhraseStructure(), i1.next());
assertFalse(i1.hasNext());
assertNull(i1.lookahead());
IEntityIterator<IEntity> i2 = IteratorFactory.featureByIndexIterator(0);
i2.reset(g);
assertTrue(i2.hasNext());
assertSame(g.wGet(0), i2.next());
assertFalse(i2.hasNext());
assertNull(i2.lookahead());
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testSelfIteratorMarkReset.
@Test
public void testSelfIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<Grammar> si = IteratorFactory.<Grammar>selfIterator();
si.reset(g);
IEntityIterator<Grammar> si2 = si.clone();
assertSame(g, si.next());
assertFalse(si.hasNext());
assertTrue(si2.hasNext());
assertSame(g, si2.next());
}
Aggregations