Search in sources :

Example 11 with Production

use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPatternWithVariablePredicate.

@Test
public void testPatternWithVariablePredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    StringBuilder names = new StringBuilder();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path8"), g, bm);
    for (Production p : iterator) {
        Assert.assertEquals(bm.wStringValue("name"), p.getName().getValue());
        names.append(p.getName().getValue());
    }
    Assert.assertEquals("VersionEncodingValueNameNameSpaceCharDataCDataSectDataCommentText", names.toString());
}
Also used : TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) 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) Test(org.junit.Test)

Example 12 with Production

use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPathWithFiltersIterator.

@Test
public void testPathWithFiltersIterator() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    Set<String> l = new HashSet<String>();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path4"), g)) l.add(p.getName().getValue());
    Assert.assertEquals(16, l.size());
}
Also used : 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) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with Production

use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testVariableJoinTest3.

@Test
public void testVariableJoinTest3() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction3");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) 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) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 14 with Production

use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testSingleVariableTestInPathExpPredicate.

@Test
public void testSingleVariableTestInPathExpPredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    Production p = (Production) g.getPhraseStructure().wGet(1);
    PathExpression pe1 = (PathExpression) tm.create("findProduction");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    // FIXME bm.wDefValue("pname", "Element");
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("Element"));
    IEntity p1 = BehaviorUtils.evaluateFirstResult(pe1, g, bm);
    Assert.assertSame(p, p1);
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("invented"));
    p1 = BehaviorUtils.evaluateFirstResult(pe1, g, bm);
    Assert.assertNull(p1);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) 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) Test(org.junit.Test)

Example 15 with Production

use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testProduct4.

@Test
public void testProduct4() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    PathExpression pe1 = (PathExpression) tm.create("testProduct4");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        Production p = (Production) productions.wGet(count++);
        Assert.assertSame(p.getName(), bm.wGet("name"));
        Assert.assertSame(p.getRule(), bm.wGet("rule"));
        Assert.assertSame(p.getName(), tuple.wGet(0));
        Assert.assertSame(p.getRule(), tuple.wGet(1));
    }
    Assert.assertEquals(g.getPhraseStructure().wSize(), count);
}
Also used : Productions(org.whole.lang.grammars.model.Productions) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) 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) Test(org.junit.Test)

Aggregations

Production (org.whole.lang.grammars.model.Production)55 Grammar (org.whole.lang.grammars.model.Grammar)43 Test (org.junit.Test)41 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)41 ITemplateManager (org.whole.lang.templates.ITemplateManager)26 PathExpression (org.whole.lang.queries.model.PathExpression)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 IEntity (org.whole.lang.model.IEntity)18 IBindingManager (org.whole.lang.bindings.IBindingManager)14 Productions (org.whole.lang.grammars.model.Productions)13 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 Rule (org.whole.lang.grammars.model.Rule)3 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)3 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Category (org.junit.experimental.categories.Category)1