use of org.whole.lang.grammars.model.NonTerminal in project whole by wholeplatform.
the class SelectQueriesTest method testSelectDistinct.
@Test
public void testSelectDistinct() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("selectNonTerminalSet");
Set<String> set = new HashSet<String>();
for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) if (!set.add(nt.getValue()))
fail();
assertEquals(22, set.size());
}
use of org.whole.lang.grammars.model.NonTerminal in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPathByNameAndByIndexSteps.
@Test
public void testPathByNameAndByIndexSteps() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
IEntityIterator<NonTerminal> nti = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1"), g);
Assert.assertTrue(nti.hasNext());
Assert.assertSame(prologNt, nti.next());
nti.reset(g.getPhraseStructure());
Assert.assertFalse(nti.hasNext());
nti.reset(g);
Assert.assertTrue(nti.hasNext());
Assert.assertSame(prologNt, nti.next());
}
use of org.whole.lang.grammars.model.NonTerminal 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.model.NonTerminal 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());
}
Aggregations