Search in sources :

Example 1 with LanguageDescriptor

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

the class LanguageDescriptorPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    LanguageDescriptor entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(4);
    list.add(entity.getUri());
    list.add(entity.getNamespace());
    list.add(entity.getName());
    list.add(entity.getVersion());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor)

Example 2 with LanguageDescriptor

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

the class GrammarsInterpreterVisitor method visit.

@Override
public void visit(Grammar grammar) {
    grammar = normalize(grammar);
    GrammarsRegistry.instance().putGrammar(grammar);
    TargetLanguage targetLanguage = grammar.getTargetLanguage();
    ILanguageKit languageKit = null;
    final String languageUri;
    IBindingManager bm = getBindings();
    if (Matcher.match(GrammarsEntityDescriptorEnum.URI, targetLanguage)) {
        languageUri = targetLanguage.wStringValue();
        languageKit = ReflectionFactory.getLanguageKit(languageUri, true, bm);
    } else {
        languageUri = ((LanguageDescriptor) targetLanguage).getUri().getValue();
        stagedVisit(GrammarsUtils.deriveModel(grammar, false));
        languageKit = (ILanguageKit) bm.getResult().wGetValue();
    }
    if (languageKit.isDynamic()) {
        DynamicLanguageKit dynamicLanguageKit = (DynamicLanguageKit) languageKit;
        GrammarBasedDataTypeParser dataTypeParser = new GrammarBasedDataTypeParser(grammar.getUri().getValue());
        dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, dataTypeParser);
        dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, dataTypeParser);
    }
    ReflectionFactory.updatePersistenceAndEditorKits(languageKit);
    ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {

        public void deploy(ReflectionFactory platform) {
            platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {

                public IVisitor create(IOperation operation, int stage) {
                    return new GenericGrammarBasedPrettyPrinterVisitor((PrettyPrinterOperation) operation);
                }
            });
            platform.addOperationFactory(languageUri, ValidatorOperation.ID, new IVisitorFactory() {

                public IVisitor create(IOperation operation, int stage) {
                    return new GenericGrammarBasedValidatorVisitor();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) GrammarBasedDataTypeParser(org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) IBindingManager(org.whole.lang.bindings.IBindingManager) TargetLanguage(org.whole.lang.grammars.model.TargetLanguage)

Example 3 with LanguageDescriptor

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

the class Grammars2ModelsVisitor method visit.

@Override
public void visit(Grammar entity) {
    entity = normalize(entity);
    IEntityIterator<Production> lexiconIiterator = IteratorFactory.<Production>childIterator();
    lexiconIiterator.reset(entity.getLexicalStructure());
    for (Production p : lexiconIiterator) lexiconMap.put(p.getName().getValue(), p);
    LanguageDescriptor ld = (LanguageDescriptor) entity.getTargetLanguage();
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    Model model = mf.createModel(mf.createSimpleName(ld.getName().getValue()), mf.createTypeRelations(), modelDeclarations = mf.createModelDeclarations(), mf.createNamespace(ld.getNamespace().getValue()), EntityUtils.isResolver(ld.getVersion()) ? CommonsEntityAdapterFactory.createResolver(ModelsEntityDescriptorEnum.Version) : mf.createVersion(ld.getVersion().getValue()), mf.createURI(ld.getUri().getValue()));
    entity.getPhraseStructure().accept(this);
    setResult(model);
}
Also used : Production(org.whole.lang.grammars.model.Production) Model(org.whole.lang.models.model.Model) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory)

Example 4 with LanguageDescriptor

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

the class AbstractGrammarSpecificPersistenceKit method removeLanguageDescriptor.

public static Grammar removeLanguageDescriptor(Grammar grammar) {
    TargetLanguage targetLanguage = grammar.getTargetLanguage();
    if (Matcher.match(GrammarsEntityDescriptorEnum.URI, targetLanguage))
        return grammar;
    grammar.setTargetLanguage(EntityUtils.remove(((LanguageDescriptor) targetLanguage).getUri()));
    return grammar;
}
Also used : LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) TargetLanguage(org.whole.lang.grammars.model.TargetLanguage)

Aggregations

LanguageDescriptor (org.whole.lang.grammars.model.LanguageDescriptor)4 TargetLanguage (org.whole.lang.grammars.model.TargetLanguage)2 ArrayList (java.util.ArrayList)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 Production (org.whole.lang.grammars.model.Production)1 GrammarBasedDataTypeParser (org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser)1 IEntity (org.whole.lang.model.IEntity)1 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)1 Model (org.whole.lang.models.model.Model)1 IOperation (org.whole.lang.operations.IOperation)1 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)1 DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1 ReflectionFactory (org.whole.lang.reflect.ReflectionFactory)1 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)1