Search in sources :

Example 16 with NonTerminal

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

the class SelectQueriesTest method testSelectDistinct.

@Test
public void testSelectDistinct() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectNonTerminalSet");
    Set<String> set = new HashSet<String>();
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) if (!set.add(nt.getValue()))
        fail();
    assertEquals(22, set.size());
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with NonTerminal

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

the class PathExpressionsQueriesTest method testPathByNameAndByIndexSteps.

@Test
public void testPathByNameAndByIndexSteps() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
    IEntityIterator<NonTerminal> nti = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1"), g);
    Assert.assertTrue(nti.hasNext());
    Assert.assertSame(prologNt, nti.next());
    nti.reset(g.getPhraseStructure());
    Assert.assertFalse(nti.hasNext());
    nti.reset(g);
    Assert.assertTrue(nti.hasNext());
    Assert.assertSame(prologNt, nti.next());
}
Also used : 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) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 18 with NonTerminal

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

the class IteratorFactoryTest method testSequenceIterator.

@SuppressWarnings("unchecked")
@Test
public void testSequenceIterator() {
    Grammar g = new TestXmlGrammar().create();
    Productions p1 = g.getPhraseStructure();
    Productions p2 = g.getLexicalStructure();
    List<Production> p3 = new ArrayList<Production>();
    IEntityIterator<Production> i11 = IteratorFactory.<Production>childIterator();
    i11.reset(p1);
    for (Production p : i11) p3.add(p);
    IEntityIterator<Production> i12 = IteratorFactory.<Production>childIterator();
    i12.reset(p2);
    for (Production p : i12) p3.add(p);
    Iterator<Production> i = p3.iterator();
    IEntityIterator<Production> i21 = IteratorFactory.<Production>childIterator();
    i21.reset(p1);
    IEntityIterator<Production> i22 = IteratorFactory.<Production>childIterator();
    i22.reset(p2);
    for (Production p : IteratorFactory.sequenceIterator(i21, i22)) assertSame(i.next(), p);
    // FIXME remove <NonTerminal> from topDownIterators
    IEntityIterator<NonTerminal> i1p1 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
    i1p1.reset(p1);
    IEntityIterator<NonTerminal> i1p2 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
    i1p2.reset(p2);
    IEntityIterator<NonTerminal> i1 = IteratorFactory.<NonTerminal>matcherIterator(IteratorFactory.sequenceIterator(i1p1, i1p2)).withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
    IEntityIterator<NonTerminal> i2p1 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
    i2p1.reset(p1);
    IEntityIterator<NonTerminal> i2p2 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
    i2p2.reset(p2);
    IEntityIterator<NonTerminal> i2 = IteratorFactory.sequenceIterator(IteratorFactory.<NonTerminal>matcherIterator(i2p1).withPattern(GrammarsEntityDescriptorEnum.NonTerminal), IteratorFactory.matcherIterator(i2p2).withPattern(GrammarsEntityDescriptorEnum.NonTerminal));
    for (NonTerminal nt : i1) assertSame(i2.next(), nt);
}
Also used : Productions(org.whole.lang.grammars.model.Productions) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) ArrayList(java.util.ArrayList) 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 19 with NonTerminal

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

the class IteratorFactoryTest method testRootIteratorMarkReset.

@Test
public void testRootIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
    IEntityIterator<IEntity> i = IteratorFactory.rootIterator();
    i.reset(prologNt);
    IEntityIterator<IEntity> i2 = i.clone();
    assertTrue(i.hasNext());
    assertSame(g, i.next());
    assertFalse(i.hasNext());
    assertTrue(i2.hasNext());
    assertSame(g, i2.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) 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

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