Search in sources :

Example 76 with Grammar

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());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 77 with Grammar

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());
}
Also used : TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) NonTerminal(org.whole.lang.grammars.model.NonTerminal) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 78 with Grammar

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));
        }
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) Test(org.junit.Test)

Example 79 with Grammar

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);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) GrammarsToGrammarBasedQuery(org.whole.lang.grammarbased.GrammarsToGrammarBasedQuery) Grammar(org.whole.lang.grammars.model.Grammar)

Example 80 with Grammar

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));
}
Also used : Grammar(org.whole.lang.grammars.model.Grammar) XmlGrammar(org.whole.lang.grammars.codebase.XmlGrammar) Test(org.junit.Test)

Aggregations

Grammar (org.whole.lang.grammars.model.Grammar)96 Test (org.junit.Test)82 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)80 IEntity (org.whole.lang.model.IEntity)50 ITemplateManager (org.whole.lang.templates.ITemplateManager)46 Production (org.whole.lang.grammars.model.Production)43 PathExpression (org.whole.lang.queries.model.PathExpression)40 IBindingManager (org.whole.lang.bindings.IBindingManager)28 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)25 NonTerminal (org.whole.lang.grammars.model.NonTerminal)14 Productions (org.whole.lang.grammars.model.Productions)14 HashSet (java.util.HashSet)8 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)7 Rule (org.whole.lang.grammars.model.Rule)6 XmlGrammar (org.whole.lang.grammars.codebase.XmlGrammar)3 As (org.whole.lang.grammars.model.As)3 Feature (org.whole.lang.models.model.Feature)3 ILanguageKit (org.whole.lang.reflect.ILanguageKit)3 ArrayList (java.util.ArrayList)2 IGrammarProvider (org.whole.lang.grammars.codebase.IGrammarProvider)2