Search in sources :

Example 1 with DataTerminal

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) DataTerminal(org.whole.lang.grammars.model.DataTerminal) ArrayList(java.util.ArrayList)

Example 2 with DataTerminal

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));
}
Also used : Pattern(java.util.regex.Pattern) CompiledPattern(org.whole.lang.grammars.model.CompiledPattern) CompiledPattern(org.whole.lang.grammars.model.CompiledPattern) DataTerminal(org.whole.lang.grammars.model.DataTerminal)

Example 3 with DataTerminal

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));
        }
    }
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) GrammarsEntityDescriptorEnum(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum) HashMap(java.util.HashMap) NonTerminal(org.whole.lang.grammars.model.NonTerminal) ILanguageKit(org.whole.lang.reflect.ILanguageKit) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) Production(org.whole.lang.grammars.model.Production) DataTerminal(org.whole.lang.grammars.model.DataTerminal) Rule(org.whole.lang.grammars.model.Rule)

Example 4 with 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;
}
Also used : IEntity(org.whole.lang.model.IEntity) DataTerminal(org.whole.lang.grammars.model.DataTerminal) ArrayList(java.util.ArrayList)

Example 5 with DataTerminal

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) DataTerminal(org.whole.lang.grammars.model.DataTerminal) ArrayList(java.util.ArrayList)

Aggregations

DataTerminal (org.whole.lang.grammars.model.DataTerminal)5 ArrayList (java.util.ArrayList)3 IEntity (org.whole.lang.model.IEntity)3 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 CompiledPattern (org.whole.lang.grammars.model.CompiledPattern)1 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Production (org.whole.lang.grammars.model.Production)1 Rule (org.whole.lang.grammars.model.Rule)1 GrammarsEntityDescriptorEnum (org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1