use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testIndexTest.
@Test
public void testIndexTest() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
IEntityIterator<Production> pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1a"), g);
Assert.assertTrue(pi.hasNext());
Assert.assertSame(g.getPhraseStructure().wGet(2), pi.next());
Assert.assertFalse(pi.hasNext());
pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1b"), g);
Assert.assertTrue(pi.hasNext());
Assert.assertSame(g.getPhraseStructure().wGet(2), pi.next());
Assert.assertFalse(pi.hasNext());
pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1c"), g);
Assert.assertTrue(pi.hasNext());
Assert.assertSame(g.getPhraseStructure().wGet(3), pi.next());
Assert.assertFalse(pi.hasNext());
pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1d"), g);
Assert.assertTrue(pi.hasNext());
Assert.assertSame(g.getPhraseStructure().wGet(3), pi.next());
Assert.assertFalse(pi.hasNext());
}
use of org.whole.lang.grammars.model.Grammar 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.Grammar 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.model.Grammar in project whole by wholeplatform.
the class GrammarsUIInterpreterVisitor method createGrammarBased.
public static IEntity createGrammarBased(Grammar entity, IBindingManager bm) {
// FIXME ensure normalized: NormalizerOperation.normalize(entity);
Grammar g = entity;
PathExpression pathExpression = new GrammarsToGrammarBasedQuery().create();
IEntity grammarBased = BehaviorUtils.evaluateFirstResult(pathExpression, g, bm);
return NormalizerOperation.normalize(grammarBased);
}
use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class GrammarsUtilsTest method testNormalizer.
@Test
public void testNormalizer() throws Exception {
Grammar testGrammar = NormalizerOperation.normalize(new TestGrammar().create());
Grammar testGrammarNormalized = new TestGrammarNormalized().create();
Assert.assertTrue(Matcher.match(testGrammarNormalized, testGrammar));
}
Aggregations