Search in sources :

Example 56 with Grammar

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

the class GrammarBasedPartFactory method createEntityPart.

protected IEntityPart createEntityPart(IEntity entity) {
    Grammar grammar = GrammarsRegistry.instance().getGrammarsFor(entity).iterator().next();
    Map<String, IEntity> configurations = getConfigurations(grammar.getUri().getValue());
    IEntity configuration = configurations.get(entity.wGetEntityDescriptor().getName());
    if (configuration == null)
        return null;
    IEntityPart entityPart = null;
    switch(entity.wGetEntityKind()) {
        case COMPOSITE:
            if (!configuration.wGetEntityDescriptor().getName().equals("CompositePart"))
                throw new IllegalArgumentException();
            entityPart = new CompositeEntityPart(configuration);
            break;
        case SIMPLE:
            if (!configuration.wGetEntityDescriptor().getName().equals("SimplePart"))
                throw new IllegalArgumentException();
            entityPart = new SimpleEntityPart(configuration);
            break;
        case DATA:
            if (!configuration.wGetEntityDescriptor().getName().equals("DataPart") && !configuration.wGetEntityDescriptor().getName().equals("EnumPart"))
                throw new IllegalArgumentException();
            entityPart = DataTypeUtils.getDataKind(entity).isEnumValue() ? new EnumEntityPart(configuration) : new DataEntityPart(configuration);
            break;
    }
    return entityPart;
}
Also used : IEntity(org.whole.lang.model.IEntity) Grammar(org.whole.lang.grammars.model.Grammar) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 57 with Grammar

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

the class GrammarBasedUnparserVisitor method normalize.

protected void normalize(Grammar entity) {
    // FIXME ensure normalized: NormalizerOperation.normalize(entity);
    Grammar g = entity;
    ScannerIterator<Production> li = IteratorFactory.<Production>childScannerIterator();
    li.reset(g.getLexicalStructure());
    for (Production p : li) {
        String name = p.getName().getValue();
        nameProductionMap.put(name, p);
        lexiconSet.add(name);
    }
    ScannerIterator<Production> pi = IteratorFactory.<Production>childScannerIterator();
    pi.reset(g.getPhraseStructure());
    for (Production p : pi) nameProductionMap.put(p.getName().getValue(), p);
}
Also used : Production(org.whole.lang.grammars.model.Production) Grammar(org.whole.lang.grammars.model.Grammar)

Example 58 with Grammar

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

the class PathExpressionsQueriesTest method testVariableJoinTest4.

@Test
public void testVariableJoinTest4() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction4");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 59 with Grammar

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

the class PathExpressionsQueriesTest method testVariableJoinTest5.

@Test
public void testVariableJoinTest5() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction5");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 60 with Grammar

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

the class PathExpressionsQueriesTest method testProduct1.

@Test
public void testProduct1() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct1");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String vname = ((Production) bm.wGet("pp")).getName().getValue() + "x" + ((Production) bm.wGet("lp")).getName().getValue();
        String tname = ((Production) tuple.wGet(0)).getName().getValue() + "x" + ((Production) tuple.wGet(1)).getName().getValue();
        Assert.assertEquals(vname, tname);
        count++;
    }
    Assert.assertEquals(g.getPhraseStructure().wSize() * g.getLexicalStructure().wSize(), count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) 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