Search in sources :

Example 46 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testProduct2.

@Test
public void testProduct2() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct2");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String prodname = ((Production) bm.wGet("prod")).getName().getValue();
        Assert.assertEquals(prodname, tuple.wGet(0).wStringValue());
        count++;
    }
    Assert.assertEquals(g.getPhraseStructure().wSize(), count);
}
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 47 with IBindingManager

use of org.whole.lang.bindings.IBindingManager 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 48 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testProduct3.

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

Example 49 with IBindingManager

use of org.whole.lang.bindings.IBindingManager 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)

Example 50 with IBindingManager

use of org.whole.lang.bindings.IBindingManager 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());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) 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

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5