Search in sources :

Example 1 with GrammarBasedDataTypeParser

use of org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser 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)

Aggregations

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