Search in sources :

Example 1 with Grammar

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

the class GrammarsUtilsTest method testGrammarToModelMapping.

@Test
public void testGrammarToModelMapping() {
    Model m = new XmlModel().create();
    Grammar g = new XmlGrammar().create();
    Model m1 = GrammarsUtils.deriveModel(g, true);
    Assert.assertTrue(Matcher.match(m, m1));
}
Also used : Model(org.whole.lang.models.model.Model) Grammar(org.whole.lang.grammars.model.Grammar) XmlGrammar(org.whole.lang.grammars.codebase.XmlGrammar) XmlGrammar(org.whole.lang.grammars.codebase.XmlGrammar) Test(org.junit.Test)

Example 2 with Grammar

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

the class GrammarsResourceBindingsContributor method addResourceBindings.

public void addResourceBindings(IBindingManager bm) {
    if (!bm.wIsSet("grammarProvider")) {
        Collection<Grammar> grammars = GrammarsRegistry.instance().grammars();
        if (!grammars.isEmpty()) {
            IGrammarProvider provider = new DialogGrammarProvider(bm);
            bm.wDefValue("grammarProvider", provider);
        }
    }
}
Also used : IGrammarProvider(org.whole.lang.grammars.codebase.IGrammarProvider) Grammar(org.whole.lang.grammars.model.Grammar)

Example 3 with Grammar

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

the class GrammarsUtils method unparse.

public static void unparse(IEntity e, Appendable appendable, String grammarUri, IBindingManager bm) {
    Grammar g = GrammarsRegistry.instance().getGrammar(grammarUri);
    if (g == null)
        throw new IllegalArgumentException("Grammar not deployed: " + grammarUri);
    new GrammarBasedUnparserVisitor(e, appendable, bm).visit(g);
}
Also used : GrammarBasedUnparserVisitor(org.whole.lang.grammars.visitors.GrammarBasedUnparserVisitor) Grammar(org.whole.lang.grammars.model.Grammar)

Example 4 with Grammar

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

the class GrammarsUtils method getGrammarUri.

public static String getGrammarUri(IBindingManager bm) {
    String grammarUri = null;
    boolean grammarFromBindings = bm.wIsSet("grammar");
    if (grammarFromBindings) {
        Grammar grammar = (Grammar) bm.wGet("grammar");
        InterpreterOperation.interpret(grammar, bm);
        grammarUri = grammar.getUri().getValue();
    } else if (bm.wIsSet("grammarURI"))
        grammarUri = bm.wStringValue("grammarURI");
    if (grammarUri == null && bm.wIsSet("grammarProvider")) {
        IGrammarProvider provider = (IGrammarProvider) bm.wGetValue("grammarProvider");
        grammarUri = provider.getGrammarUri(null);
    }
    return grammarUri;
}
Also used : IGrammarProvider(org.whole.lang.grammars.codebase.IGrammarProvider) Grammar(org.whole.lang.grammars.model.Grammar)

Example 5 with Grammar

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

the class GenericGrammarBasedValidatorVisitor method visit.

@Override
public void visit(IEntity entity) {
    Collection<Grammar> grammars = GrammarsRegistry.instance().getGrammarsFor(entity);
    if (grammars.isEmpty())
        throw new IllegalArgumentException("cannot find a suitable grammar to unparse the entity");
    Grammar grammar = grammars.iterator().next();
    calculateDataTerminals(grammar);
    IEntityIterator<IEntity> iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(EntityKinds.DATA);
    iterator.reset(entity);
    while (iterator.hasNext()) validateDataTerminal(iterator.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) Grammar(org.whole.lang.grammars.model.Grammar)

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