Search in sources :

Example 1 with TargetLanguage

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

the class GrammarsJavaModelGeneratorVisitor method visit.

@Override
public void visit(Grammar entity) {
    TargetLanguage targetLanguage = entity.getTargetLanguage();
    if (Matcher.match(GrammarsEntityDescriptorEnum.LanguageDescriptor, targetLanguage)) {
        Model targetModel = GrammarsUtils.deriveModel(entity, true);
        stagedVisit(targetModel);
    }
}
Also used : Model(org.whole.lang.models.model.Model) TargetLanguage(org.whole.lang.grammars.model.TargetLanguage)

Example 2 with TargetLanguage

use of org.whole.lang.grammars.model.TargetLanguage 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 TargetLanguage

use of org.whole.lang.grammars.model.TargetLanguage 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

TargetLanguage (org.whole.lang.grammars.model.TargetLanguage)3 LanguageDescriptor (org.whole.lang.grammars.model.LanguageDescriptor)2 IBindingManager (org.whole.lang.bindings.IBindingManager)1 GrammarBasedDataTypeParser (org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser)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