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));
}
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);
}
}
}
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);
}
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;
}
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());
}
Aggregations