use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPathWithPatternFiltersIterator.
@Test
public void testPathWithPatternFiltersIterator() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
Set<String> l = new HashSet<String>();
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path5"), g)) l.add(p.getName().getValue());
Assert.assertEquals(2, l.size());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testVariablesInQuantifiedPredicate.
@Test
public void testVariablesInQuantifiedPredicate() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("recursiveProduction6");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
iterator.next();
Assert.assertTrue(bm.wIsSet("pname"));
Assert.assertTrue(bm.wIsSet("nt"));
pe1 = (PathExpression) tm.create("exactlyOneDefUse");
bm = BindingManagerFactory.instance.createArguments();
iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
iterator.next();
Assert.assertTrue(bm.wIsSet("pname"));
Assert.assertTrue(bm.wIsSet("nt"));
pe1 = (PathExpression) tm.create("unusedProduction");
bm = BindingManagerFactory.instance.createArguments();
iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
iterator.next();
Assert.assertTrue(bm.wNames().isEmpty());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testSomePredicate.
@Test
public void testSomePredicate() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new QueriesGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("recursiveProduction6");
StringBuilder names = new StringBuilder();
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTuple1.
@Test
public void testSelectTuple1() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("selectTuple1");
int count = 0;
for (IEntity t : BehaviorUtils.compileAndLazyEvaluate(pe1, g)) {
NonTerminal name = (NonTerminal) t.wGet(0);
Rule rule = (Rule) t.wGet(1);
Production prod = (Production) t.wGet(2);
assertEquals(name, prod.getName());
assertSame(rule, prod.getRule());
assertEquals(g.getName(), t.wGet(3));
count++;
}
assertEquals(g.getPhraseStructure().wSize(), count);
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testChildReverseIteratorRemove.
@Test
public void testChildReverseIteratorRemove() {
Grammar g = new TestXmlGrammar().create();
Productions productions = EntityUtils.clone(g.getPhraseStructure());
IEntityIterator<Production> ci = IteratorFactory.<Production>childReverseIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(productions.wSize() - 1), p);
ci.remove();
}
assertEquals(0, productions.wSize());
productions = EntityUtils.clone(g.getPhraseStructure());
ci = IteratorFactory.<Production>childReverseScannerIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(productions.wSize() - 1), p);
ci.remove();
}
assertEquals(0, productions.wSize());
productions = EntityUtils.clone(g.getPhraseStructure());
ci = IteratorFactory.<Production>childReverseMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(productions.wSize() - 1), p);
ci.remove();
}
assertEquals(0, productions.wSize());
}
Aggregations