Search in sources :

Example 6 with NonTerminal

use of org.whole.lang.grammars.model.NonTerminal 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 7 with NonTerminal

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

the class PathExpressionsQueriesTest method testSingleVariableTestInPathExpPredicateOfPathInternalStep.

@Test
public void testSingleVariableTestInPathExpPredicateOfPathInternalStep() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("findAllNonTerminalsUsed");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    // FIXME bm.wDefValue("pname", "Element");
    bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("IName"));
    int count = 0;
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g, bm)) count++;
    Assert.assertEquals(4, count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) 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) Test(org.junit.Test)

Example 8 with NonTerminal

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

the class SelectQueriesTest method testSelectPathExpression2.

@Test
public void testSelectPathExpression2() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    PathExpression query = (PathExpression) tm.create("selectPath2");
    StringBuilder names = new StringBuilder();
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(query, model)) names.append(nt.getValue());
    assertEquals("DocumentElementINameIContent", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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) Test(org.junit.Test)

Example 9 with NonTerminal

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

the class SelectQueriesTest method testSelectPathExpression1.

@Test
public void testSelectPathExpression1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectPath1");
    StringBuilder names = new StringBuilder();
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) names.append(nt.getValue());
    assertEquals("DocumentElementINameIContent", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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) Test(org.junit.Test)

Example 10 with NonTerminal

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

the class SelectQueriesTest method testSelectTuple1.

@Test
public void testSelectTuple1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTuple1");
    int count = 0;
    for (IEntity t : BehaviorUtils.compileAndLazyEvaluate(pe1, g)) {
        NonTerminal name = (NonTerminal) t.wGet(0);
        Rule rule = (Rule) t.wGet(1);
        Production prod = (Production) t.wGet(2);
        assertEquals(name, prod.getName());
        assertSame(rule, prod.getRule());
        assertEquals(g.getName(), t.wGet(3));
        count++;
    }
    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) 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) Rule(org.whole.lang.grammars.model.Rule) Test(org.junit.Test)

Aggregations

NonTerminal (org.whole.lang.grammars.model.NonTerminal)19 Grammar (org.whole.lang.grammars.model.Grammar)14 Test (org.junit.Test)13 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)13 ITemplateManager (org.whole.lang.templates.ITemplateManager)9 Production (org.whole.lang.grammars.model.Production)8 PathExpression (org.whole.lang.queries.model.PathExpression)8 HashSet (java.util.HashSet)5 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)5 Rule (org.whole.lang.grammars.model.Rule)5 IEntity (org.whole.lang.model.IEntity)5 IBindingManager (org.whole.lang.bindings.IBindingManager)3 As (org.whole.lang.grammars.model.As)2 Productions (org.whole.lang.grammars.model.Productions)2 Repeat (org.whole.lang.grammars.model.Repeat)2 GrammarsEntityDescriptorEnum (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 ArrayList (java.util.ArrayList)1