use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testLookaheadScope.
@Test
public void testLookaheadScope() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
String[] templates = { "findNonTerminalOccurrences", "findProduction", "bindNonTerminalOccurrences", "recursiveProduction2", "testProduct1", "testProduct2", "testProduct3" };
for (String template : templates) {
PathExpression pe1 = (PathExpression) tm.create(template);
IBindingManager bm = BindingManagerFactory.instance.createArguments();
IEntityIterator<IEntity> i1 = BehaviorUtils.<IEntity>compileAndLazyEvaluate(pe1, g, bm);
IEntity p1 = null;
while ((p1 = i1.lookahead()) != null) {
Set<String> s1 = i1.lookaheadScope().wNames();
IEntity p2 = i1.next();
// false for tuples Assert.assertSame(p1,p2);
Assert.assertEquals(bm.wNames().size(), s1.size());
for (String name : s1) Assert.assertTrue(bm.wIsSet(name));
}
}
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testSequenceIterator.
@SuppressWarnings("unchecked")
@Test
public void testSequenceIterator() {
Grammar g = new TestXmlGrammar().create();
Productions p1 = g.getPhraseStructure();
Productions p2 = g.getLexicalStructure();
List<Production> p3 = new ArrayList<Production>();
IEntityIterator<Production> i11 = IteratorFactory.<Production>childIterator();
i11.reset(p1);
for (Production p : i11) p3.add(p);
IEntityIterator<Production> i12 = IteratorFactory.<Production>childIterator();
i12.reset(p2);
for (Production p : i12) p3.add(p);
Iterator<Production> i = p3.iterator();
IEntityIterator<Production> i21 = IteratorFactory.<Production>childIterator();
i21.reset(p1);
IEntityIterator<Production> i22 = IteratorFactory.<Production>childIterator();
i22.reset(p2);
for (Production p : IteratorFactory.sequenceIterator(i21, i22)) assertSame(i.next(), p);
// FIXME remove <NonTerminal> from topDownIterators
IEntityIterator<NonTerminal> i1p1 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i1p1.reset(p1);
IEntityIterator<NonTerminal> i1p2 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i1p2.reset(p2);
IEntityIterator<NonTerminal> i1 = IteratorFactory.<NonTerminal>matcherIterator(IteratorFactory.sequenceIterator(i1p1, i1p2)).withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
IEntityIterator<NonTerminal> i2p1 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i2p1.reset(p1);
IEntityIterator<NonTerminal> i2p2 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i2p2.reset(p2);
IEntityIterator<NonTerminal> i2 = IteratorFactory.sequenceIterator(IteratorFactory.<NonTerminal>matcherIterator(i2p1).withPattern(GrammarsEntityDescriptorEnum.NonTerminal), IteratorFactory.matcherIterator(i2p2).withPattern(GrammarsEntityDescriptorEnum.NonTerminal));
for (NonTerminal nt : i1) assertSame(i2.next(), nt);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testChildReverseIterator.
@Test
public void testChildReverseIterator() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int index = productions.wSize();
IEntityIterator<Production> ci = IteratorFactory.<Production>childReverseIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(--index), p);
}
index = productions.wSize();
ci = IteratorFactory.<Production>childReverseScannerIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(--index), p);
}
index = productions.wSize();
ci = IteratorFactory.<Production>childReverseMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(--index), p);
}
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testChildIteratorMarkReset.
@Test
public void testChildIteratorMarkReset() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> i = IteratorFactory.<IEntity>childIterator();
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.util.TestXmlGrammar 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());
}
Aggregations