use of org.whole.lang.grammars.model.DataTerminal in project whole by wholeplatform.
the class DataTerminalPart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
DataTerminal entity = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(2);
list.add(entity.getPattern());
list.add(entity.getFormat());
return list;
}
use of org.whole.lang.grammars.model.DataTerminal in project whole by wholeplatform.
the class GenericGrammarBasedValidatorVisitor method validateDataTerminal.
protected void validateDataTerminal(IEntity entity) {
EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
if (ed.getDataKind().isEnumValue())
return;
String value = DataTypeUtils.getAsPersistenceString(entity);
DataTerminal dataTerminal = getDataTerminal(ed);
if (dataTerminal != null) {
Pattern pattern = ((CompiledPattern) dataTerminal.getPattern()).getValue();
if (!pattern.matcher(value).matches())
getDecorationManager().addError(entity, "the data entity doesn't match the pattern: " + pattern.toString(), EntityUtils.getLocation(entity));
} else
getDecorationManager().addError(entity, "the data entity is unknonwn", EntityUtils.getLocation(entity));
}
use of org.whole.lang.grammars.model.DataTerminal in project whole by wholeplatform.
the class GenericGrammarBasedValidatorVisitor method calculateDataTerminals.
private void calculateDataTerminals(Grammar grammar) {
this.dataTerminals = new HashMap<EntityDescriptor<?>, DataTerminal>();
// TODO ensure grammar normalized
Map<String, Rule> productions = new HashMap<String, Rule>();
IEntityIterator<Production> pi = IteratorFactory.<Production>childIterator();
pi.reset(grammar.getPhraseStructure());
for (Production p : pi) productions.put(p.getName().getValue(), p.getRule());
Map<String, Rule> lexicon = new HashMap<String, Rule>();
IEntityIterator<Production> li = IteratorFactory.<Production>childIterator();
li.reset(grammar.getLexicalStructure());
for (Production p : li) lexicon.put(p.getName().getValue(), p.getRule());
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(GrammarsUtils.getLanguageURI(grammar), false, null);
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
for (EntityDescriptor<?> ed : edEnum) if (EntityUtils.isData(ed)) {
Rule production = productions.get(ed.getName());
if (!ed.getDataKind().isEnumValue()) {
DataTerminal dataTerminal = Matcher.find(GrammarsEntityDescriptorEnum.DataTerminal, production, false);
if (dataTerminal == null) {
NonTerminal nonTerminal = Matcher.find(GrammarsEntityDescriptorEnum.NonTerminal, production, false);
dataTerminal = Matcher.find(GrammarsEntityDescriptorEnum.DataTerminal, lexicon.get(nonTerminal.getValue()), false);
}
dataTerminals.put(ed, EntityUtils.clone(dataTerminal));
}
}
}
use of org.whole.lang.grammars.model.DataTerminal in project whole by wholeplatform.
the class DataTerminalUnparserPart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
DataTerminal entity = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(1);
list.add(entity.getFormat());
return list;
}
use of org.whole.lang.grammars.model.DataTerminal in project whole by wholeplatform.
the class DataTerminalParserPart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
DataTerminal entity = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(1);
list.add(entity.getPattern());
return list;
}
Aggregations