Search in sources :

Example 46 with Production

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

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

the class ProductionInlinePart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    Production production = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(3);
    list.add(production.getRule());
    list.add(production.getName());
    list.add(production.getTemplate());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) Production(org.whole.lang.grammars.model.Production) ArrayList(java.util.ArrayList)

Example 48 with Production

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

the class GrammarsUtilsTest method buildGrammar.

public Grammar buildGrammar() {
    GrammarsEntityFactory gf = GrammarsEntityFactory.instance;
    Production data1 = createProduction(gf.createNonTerminal("MyDataNT1"), gf.createAs(createDataTerminal(gf.createRegExp(".*"), gf.createFormat("%s")), gf.createName("MyDataEntity1")));
    Production data2 = createProduction(gf.createNonTerminal("MyDataNT2"), gf.createAs(gf.createConcatenate(createLiteralTerminal("BEFORE_DELIMITER"), createDataTerminal(gf.createRegExp(".*"), gf.createFormat("%s")), createLiteralTerminal("AFTER_DELIMITER")), gf.createName("MyDataEntity2")));
    Production enum1 = createProduction(gf.createNonTerminal("MyEnumNT1"), gf.createAs(gf.createChoose(gf.createAs(createLiteralTerminal("L1"), gf.createName("V1")), createLiteralTerminal("V2"), gf.createAs(createLiteralTerminal("L3"), gf.createName("V3"))), gf.createName("MyEnumEntity1")));
    Production composite1 = createProduction(gf.createNonTerminal("MyCompositeNT1"), gf.createAs(createRepeat(gf.createNonTerminal("MyComponentNT")), gf.createName("MyCompositeEntity1")));
    Production composite2 = createProduction(gf.createNonTerminal("MyCompositeNT2"), gf.createAs(gf.createConcatenate(createLiteralTerminal("BEFORE_DELIMITER"), gf.createRepeat(gf.createSize(0), gf.createUnbounded(), // FIXME gf.createFormat(", "))),
    createLiteralTerminal(","), gf.createNonTerminal("MyComponentNT")), createLiteralTerminal("AFTER_DELIMITER")), gf.createName("MyCompositeEntity2")));
    Production simple1 = createProduction(gf.createNonTerminal("MySimpleNT1"), gf.createAs(gf.createConcatenate(gf.createAs(gf.createNonTerminal("MyEnumNT1"), gf.createName("feature1")), gf.createAs(gf.createNonTerminal("MyDataNT1"), gf.createName("feature2"))), gf.createName("MySimpleEntity1")));
    Production simple2 = createProduction(gf.createNonTerminal("MySimpleNT2"), gf.createAs(gf.createConcatenate(createLiteralTerminal("BEFORE_DELIMITER"), gf.createAs(gf.createNonTerminal("MyEnumNT1"), gf.createName("feature1")), gf.createOptional(gf.createConcatenate(createLiteralTerminal("FEATURE_DELIMITER"), gf.createAs(gf.createNonTerminal("MyDataNT1"), gf.createName("feature2")))), createLiteralTerminal("AFTER_DELIMITER")), gf.createName("MySimpleEntity2")));
    Production abstract1 = createProduction(gf.createNonTerminal("MyComponentNT"), gf.createAs(gf.createChoose(gf.createNonTerminal("MySimpleEntity1"), gf.createNonTerminal("MyDataNT1")), gf.createName("MyAbstractEntity1")));
    Production abstract2 = createProduction(gf.createNonTerminal("MyComponentNT2"), gf.createAs(gf.createConcatenate(gf.createAs(gf.createNonTerminal("MyEnumNT1"), gf.createName("inheritedFeature1")), gf.createAs(gf.createNonTerminal("MyDataNT1"), gf.createName("inheritedFeature2")), gf.createChoose(gf.createNonTerminal("MySimpleEntity1"), gf.createNonTerminal("MySimpleEntity2"))), gf.createName("MyAbstractEntity2")));
    return createGrammar(gf.createName("MyGrammar"), gf.createURI("MyLanguage"), gf.createProductions(), gf.createProductions(simple1, simple2, abstract1, abstract2, composite1, composite2, enum1, data1, data2));
}
Also used : Production(org.whole.lang.grammars.model.Production) GrammarsEntityFactory(org.whole.lang.grammars.factories.GrammarsEntityFactory)

Example 49 with Production

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

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

Production (org.whole.lang.grammars.model.Production)55 Grammar (org.whole.lang.grammars.model.Grammar)43 Test (org.junit.Test)41 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)41 ITemplateManager (org.whole.lang.templates.ITemplateManager)26 PathExpression (org.whole.lang.queries.model.PathExpression)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 IEntity (org.whole.lang.model.IEntity)18 IBindingManager (org.whole.lang.bindings.IBindingManager)14 Productions (org.whole.lang.grammars.model.Productions)13 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 Rule (org.whole.lang.grammars.model.Rule)3 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)3 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)2 ILanguageKit (org.whole.lang.reflect.ILanguageKit)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Category (org.junit.experimental.categories.Category)1