Search in sources :

Example 6 with Productions

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

the class IteratorFactoryTest method testTopDownMatcherIteratorRemove.

@Test
public void testTopDownMatcherIteratorRemove() {
    Grammar g = new TestXmlGrammar().create();
    g.wRemove(GrammarsFeatureDescriptorEnum.lexicalStructure);
    Productions productions = g.getPhraseStructure();
    IEntityIterator<Production> ci = IteratorFactory.<Production>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci.reset(g);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(0), p);
        ci.remove();
    }
    assertEquals(0, productions.wSize());
    g = new TestXmlGrammar().create();
    IEntityIterator<NonTerminal> ci2 = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
    ci2.reset(g);
    while (ci2.hasNext()) {
        NonTerminal nt = ci2.next();
        ci2.remove();
    }
    assertNull(Matcher.find(GenericTraversalFactory.instance.sequence(GenericMatcherFactory.instance.hasTypeMatcher(GrammarsEntityDescriptorEnum.NonTerminal), GenericMatcherFactory.instance.isImplMatcher()), g, false));
}
Also used : Productions(org.whole.lang.grammars.model.Productions) 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)

Example 7 with Productions

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

the class IteratorFactoryTest method testChildIteratorAdd.

@Test
public void testChildIteratorAdd() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    int size = productions.wSize();
    int count = 0;
    Production pAdded1 = null;
    Production pAdded2 = null;
    IEntityIterator<Production> i = IteratorFactory.<Production>childIterator();
    i.reset(productions);
    while (i.hasNext()) {
        Production p = i.next();
        assertNotSame(pAdded1, p);
        assertNotSame(pAdded2, p);
        count++;
        if (count == 1)
            i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
        if (count == 3) {
            i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
            i.add(pAdded2 = GrammarsEntityFactory.instance.createProduction());
        }
    }
    assertEquals(size, count);
    assertEquals(size + 3, productions.wSize());
}
Also used : Productions(org.whole.lang.grammars.model.Productions) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 8 with Productions

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

the class IteratorFactoryTest method testPrecedingSiblingIterator.

@Test
public void testPrecedingSiblingIterator() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    int index = 0;
    IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
        fi.reset(p);
        int findex = index++;
        for (Production fp : fi) assertSame(productions.wGet(--findex), fp);
    }
    for (int i = g.wSize() - 1; i >= 0; i--) {
        IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>precedingSiblingIterator();
        fi.reset(g.wGet(i));
        for (int j = i - 1; j >= 0; j--) assertSame(g.wGet(j), fi.next());
    }
    for (int i = productions.wSize() - 1; i >= 0; i--) {
        IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
        fi.reset(productions.wGet(i));
        for (int j = i - 1; j >= 0; j--) assertSame(productions.wGet(j), fi.next());
    }
}
Also used : Productions(org.whole.lang.grammars.model.Productions) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 9 with Productions

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

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

the class IteratorFactoryTest method testChildReverseIterator.

@Test
public void testChildReverseIterator() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    int index = productions.wSize();
    IEntityIterator<Production> ci = IteratorFactory.<Production>childReverseIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(--index), p);
    }
    index = productions.wSize();
    ci = IteratorFactory.<Production>childReverseScannerIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(--index), p);
    }
    index = productions.wSize();
    ci = IteratorFactory.<Production>childReverseMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(--index), p);
    }
}
Also used : Productions(org.whole.lang.grammars.model.Productions) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 Grammar (org.whole.lang.grammars.model.Grammar)14 Productions (org.whole.lang.grammars.model.Productions)14 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)14 Production (org.whole.lang.grammars.model.Production)13 IEntity (org.whole.lang.model.IEntity)4 NonTerminal (org.whole.lang.grammars.model.NonTerminal)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)1 Type (org.whole.lang.models.model.Type)1 PathExpression (org.whole.lang.queries.model.PathExpression)1 ITemplateManager (org.whole.lang.templates.ITemplateManager)1 GenericIdentityVisitor (org.whole.lang.visitors.GenericIdentityVisitor)1 IVisitor (org.whole.lang.visitors.IVisitor)1