Search in sources :

Example 26 with Production

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

the class IteratorFactoryTest method testTopDownIteratorAdd.

@Test
public void testTopDownIteratorAdd() {
    Grammar g = new TestXmlGrammar().create();
    Production production = (Production) g.getPhraseStructure().wGet(3);
    Choose choose = (Choose) production.getRule();
    int size = choose.wSize();
    int count = 0;
    Rule rAdded1 = null;
    Rule rAdded2 = null;
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i.reset(production);
    i.next();
    i.next();
    while (i.hasNext()) {
        IEntity r = i.next();
        assertNotSame(rAdded1, r);
        assertNotSame(rAdded2, r);
        if (count == 0)
            assertSame(choose, r);
        else if (count == 1)
            i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
        else if (count == 10) {
            i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
            i.add(rAdded2 = GrammarsEntityFactory.instance.createProduction());
        }
        count++;
    }
    assertEquals(size + 3, choose.wSize());
}
Also used : Choose(org.whole.lang.grammars.model.Choose) 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) Rule(org.whole.lang.grammars.model.Rule) Test(org.junit.Test)

Example 27 with Production

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

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

the class Grammars2ModelsVisitor method visit.

@Override
public void visit(Productions entity) {
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    ScannerIterator<Production> i = IteratorFactory.<Production>childScannerIterator();
    i.reset(entity);
    for (Production p : i) {
        String eName = getMappedEntityName(p);
        ModelDeclaration mDecl = CommonsEntityAdapterFactory.createResolver(ModelsEntityDescriptorEnum.ModelDeclaration);
        productionMap.put(p.getName().getValue(), p);
        declarationMap.put(eName, mDecl);
        modelDeclarations.wAdd(mDecl);
        mDecl.setModifiers(mf.createEntityModifiers());
        mDecl.setName(mf.createSimpleName(eName));
        mDecl.setTypes(mf.createTypes());
    }
    super.visit(entity);
}
Also used : Production(org.whole.lang.grammars.model.Production) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) ModelDeclaration(org.whole.lang.models.model.ModelDeclaration)

Example 29 with Production

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

the class GenericPredictiveParser method wParseStartSymbol.

public void wParseStartSymbol() {
    Production production = getProduction(grammar.getStartSymbol());
    if (production == null)
        throw createParseError("mising start symbol production");
    assert !isLexicon(production);
    wParse(production);
}
Also used : Production(org.whole.lang.grammars.model.Production)

Example 30 with Production

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

the class GrammarsPartFactoryVisitor method visit.

@Override
public void visit(NonTerminal entity) {
    Object parentEntity = context.getModel();
    if (parentEntity instanceof Production && entity == ((Production) parentEntity).getName())
        part = new DeclarationTextualEntityPart();
    else if (parentEntity instanceof Repeat && entity == ((Repeat) parentEntity).getSeparator())
        part = new ContentTextualEntityPart();
    else
        part = new NonTerminalPart();
}
Also used : ContentTextualEntityPart(org.whole.lang.ui.editparts.ContentTextualEntityPart) Production(org.whole.lang.grammars.model.Production) Repeat(org.whole.lang.grammars.model.Repeat) DeclarationTextualEntityPart(org.whole.lang.ui.editparts.DeclarationTextualEntityPart)

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