Search in sources :

Example 36 with Production

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

the class PathExpressionsQueriesTest method testVariableJoinTest5.

@Test
public void testVariableJoinTest5() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction5");
    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 37 with Production

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

the class PathExpressionsQueriesTest method testProduct1.

@Test
public void testProduct1() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct1");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String vname = ((Production) bm.wGet("pp")).getName().getValue() + "x" + ((Production) bm.wGet("lp")).getName().getValue();
        String tname = ((Production) tuple.wGet(0)).getName().getValue() + "x" + ((Production) tuple.wGet(1)).getName().getValue();
        Assert.assertEquals(vname, tname);
        count++;
    }
    Assert.assertEquals(g.getPhraseStructure().wSize() * g.getLexicalStructure().wSize(), count);
}
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) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) Test(org.junit.Test)

Example 38 with Production

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

the class PathExpressionsQueriesTest method testRebindVariable.

@Test
public void testRebindVariable() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("Element"));
    int count = 0;
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("findProduction"), g, bm)) count++;
    Assert.assertEquals(1, count);
    count = 0;
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("findProduction"), g)) count++;
    Assert.assertEquals(6, count);
}
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 39 with Production

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

the class PathExpressionsQueriesTest method testEveryPredicate.

@Test
public void testEveryPredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("unusedProduction");
    IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g);
    Assert.assertTrue(iterator.hasNext());
    Production p = iterator.next();
    Assert.assertEquals("Statement", p.getName().getValue());
    Assert.assertTrue(iterator.hasNext());
    p = iterator.next();
    Assert.assertEquals("Declaration", p.getName().getValue());
    Assert.assertTrue(iterator.hasNext());
    p = iterator.next();
    Assert.assertEquals("Index", p.getName().getValue());
    Assert.assertFalse(iterator.hasNext());
}
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 40 with Production

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

the class PathExpressionsQueriesTest method testBindingOfSelfIndex.

@Category(KnownFailingTests.class)
@Test
public void testBindingOfSelfIndex() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    int count = 0;
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path6"), g)) {
        Assert.assertTrue(g.getPhraseStructure().wIndexOf(p) >= 2);
        count++;
    }
    Assert.assertEquals(2, count);
}
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) Category(org.junit.experimental.categories.Category) 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