Search in sources :

Example 91 with Grammar

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

the class IteratorFactoryTest method testAncestorIteratorMarkReset.

@Test
public void testAncestorIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorIterator();
    i.reset(r);
    i.next();
    i.next();
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    IEntity e1 = i.next();
    IEntity e2 = i.next();
    assertSame(e1, i2.next());
    assertSame(e1, i3.next());
    assertSame(e2, i3.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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)

Example 92 with Grammar

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

the class IteratorFactoryTest method testAncestorOrSelfIteratorRemoveSet.

@Test
public void testAncestorOrSelfIteratorRemoveSet() {
    Grammar g = new TestXmlGrammar().create();
    MiscEntityFactory mef = MiscEntityFactory.instance(RegistryConfigurations.RESOLVER);
    Any any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, g);
    Misc innerMisc = mef.createMisc(any);
    any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, innerMisc);
    Misc outerMisc = mef.createMisc(any);
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(r);
    IEntity next = null;
    while (i.hasNext()) {
        next = i.next();
        if (Matcher.match(MiscEntityDescriptorEnum.Misc, next))
            break;
    }
    assertSame(innerMisc, next);
    i.set(EntityUtils.clone(any));
    assertEquals(1, outerMisc.wSize());
    Rule r2 = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
    assertTrue(Matcher.match(r, r2));
    assertNotSame(r, r2);
    i.remove();
    assertEquals(0, outerMisc.wSize());
    i.reset(r2);
    while (i.hasNext()) {
        next = i.next();
        if (i.hasNext())
            i.remove();
    }
    assertFalse(EntityUtils.hasParent(next));
}
Also used : MiscEntityFactory(org.whole.lang.misc.factories.MiscEntityFactory) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Misc(org.whole.lang.misc.model.Misc) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Rule(org.whole.lang.grammars.model.Rule) Any(org.whole.lang.misc.model.Any) Test(org.junit.Test)

Example 93 with Grammar

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

the class IteratorFactoryTest method testChildReverseIteratorMarkReset.

@Test
public void testChildReverseIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>childReverseIterator();
    i.reset(g);
    i.next();
    i.next();
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    IEntity e1 = i.next();
    IEntity e2 = i.next();
    assertSame(e1, i2.next());
    assertSame(e1, i3.next());
    assertSame(e2, i3.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 94 with Grammar

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

the class IteratorFactoryTest method testChildIterator.

@Test
public void testChildIterator() {
    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();
        assertSame(productions.wGet(index++), p);
    }
    index = 0;
    ci = IteratorFactory.<Production>childScannerIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(index++), p);
    }
    index = 0;
    ci = IteratorFactory.<Production>childMatcherIterator().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)

Example 95 with Grammar

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

the class IteratorFactoryTest method testAncestorOrSelfIteratorMarkReset.

@Test
public void testAncestorOrSelfIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(r);
    IEntity e1 = i.next();
    assertSame(r, e1);
    e1 = i.next();
    assertSame(r.wGetParent(), e1);
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    e1 = i.next();
    IEntity e2 = i.next();
    assertSame(e1, i2.next());
    assertSame(e1, i3.next());
    assertSame(e2, i3.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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

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