Search in sources :

Example 26 with Grammar

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

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

the class RewriteQueriesTest method testDelete3.

@Test
public void testDelete3() {
    Grammar model = new TestXmlGrammar().create();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("delete3");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Name, entity) || EntityUtils.isResolver(entity));
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(EntityUtils.isResolver(entity));
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 28 with Grammar

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

the class SelectQueriesTest method testSelectTemplateWithTwoNestedSimpleQueries.

@Test
public void testSelectTemplateWithTwoNestedSimpleQueries() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithTwoNestedSimpleQueries");
    for (Feature f : BehaviorUtils.<Feature>compileAndLazyEvaluate(pe1, g)) {
        assertEquals(ModelsEntityDescriptorEnum.Feature, f.wGetEntityDescriptor());
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 29 with Grammar

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

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

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