Search in sources :

Example 1 with ILanguageComponentConfig

use of org.metaborg.core.config.ILanguageComponentConfig in project spoofax by metaborg.

the class LanguageComponentFactory method createConfig.

@Override
public ComponentCreationConfig createConfig(IComponentCreationConfigRequest configRequest) throws MetaborgException {
    final ComponentFactoryRequest request = (ComponentFactoryRequest) configRequest;
    final FileObject location = request.location();
    if (!request.valid()) {
        throw new MetaborgException(request.toString());
    }
    final ILanguageComponentConfig componentConfig = request.config();
    logger.debug("Creating language component for {}", location);
    final LanguageIdentifier identifier = componentConfig.identifier();
    final Collection<LanguageContributionIdentifier> langContribs = request.config().langContribs();
    if (langContribs.isEmpty()) {
        langContribs.add(new LanguageContributionIdentifier(identifier, componentConfig.name()));
    }
    final ComponentCreationConfig config = new ComponentCreationConfig(identifier, location, langContribs, componentConfig);
    final SyntaxFacet syntaxFacet;
    if (componentConfig.sdfEnabled()) {
        syntaxFacet = request.syntaxFacet();
        if (syntaxFacet != null) {
            config.addFacet(syntaxFacet);
        }
    } else {
        syntaxFacet = null;
    }
    final StrategoRuntimeFacet strategoRuntimeFacet = request.strategoRuntimeFacet();
    if (strategoRuntimeFacet != null) {
        config.addFacet(strategoRuntimeFacet);
    }
    final IStrategoAppl esvTerm = request.esvTerm();
    if (esvTerm != null) {
        final String[] extensions = extensions(esvTerm);
        if (extensions.length != 0) {
            final Iterable<String> extensionsIterable = Iterables2.from(extensions);
            final IdentificationFacet identificationFacet = new IdentificationFacet(new ResourceExtensionsIdentifier(extensionsIterable));
            config.addFacet(identificationFacet);
            final ResourceExtensionFacet resourceExtensionsFacet = new ResourceExtensionFacet(extensionsIterable);
            config.addFacet(resourceExtensionsFacet);
        }
        if (ParseFacetFromESV.hasParser(esvTerm)) {
            config.addFacet(ParseFacetFromESV.create(esvTerm));
        } else if (syntaxFacet != null) {
            config.addFacet(new ParseFacet("jsglr"));
        }
        final boolean hasContext = ContextFacetFromESV.hasContext(esvTerm);
        final boolean hasAnalysis = AnalysisFacetFromESV.hasAnalysis(esvTerm);
        final IContextFactory contextFactory;
        final ISpoofaxAnalyzer analyzer;
        final AnalysisFacet analysisFacet;
        if (hasAnalysis) {
            final String analysisType = AnalysisFacetFromESV.type(esvTerm);
            assert analysisType != null : "Analyzer type cannot be null because hasAnalysis is true, no null check is needed.";
            analyzer = analyzers.get(analysisType);
            analysisFacet = AnalysisFacetFromESV.create(esvTerm);
            final String contextType = hasContext ? ContextFacetFromESV.type(esvTerm) : null;
            if (hasContext && contextType == null) {
                contextFactory = null;
            } else {
                final String analysisContextType;
                switch(analysisType) {
                    default:
                    case StrategoAnalyzer.name:
                        analysisContextType = LegacyContextFactory.name;
                        break;
                    case TaskEngineAnalyzer.name:
                        analysisContextType = IndexTaskContextFactory.name;
                        break;
                    case ConstraintSingleFileAnalyzer.name:
                        analysisContextType = SingleFileScopeGraphContextFactory.name;
                        break;
                    case ConstraintMultiFileAnalyzer.name:
                        analysisContextType = MultiFileScopeGraphContextFactory.name;
                        break;
                }
                if (hasContext && !analysisContextType.equals(contextType)) {
                    logger.warn("Ignoring explicit context type {}, because it is incompatible with analysis {}.", contextType, analysisType);
                }
                contextFactory = contextFactory(analysisContextType);
            }
        } else if (hasContext) {
            final String type = ContextFacetFromESV.type(esvTerm);
            contextFactory = contextFactory(type);
            analyzer = null;
            analysisFacet = null;
        } else {
            contextFactory = contextFactory(LegacyContextFactory.name);
            analyzer = null;
            analysisFacet = null;
        }
        if (contextFactory != null) {
            final IContextStrategy contextStrategy = contextStrategy(ProjectContextStrategy.name);
            config.addFacet(new ContextFacet(contextFactory, contextStrategy));
        }
        if (analyzer != null) {
            config.addFacet(new AnalyzerFacet<>(analyzer));
        }
        if (analysisFacet != null) {
            config.addFacet(analysisFacet);
        }
        final ActionFacet menusFacet = ActionFacetFromESV.create(esvTerm);
        if (menusFacet != null) {
            config.addFacet(menusFacet);
        }
        final StylerFacet stylerFacet = StylerFacetFromESV.create(esvTerm);
        if (stylerFacet != null) {
            config.addFacet(stylerFacet);
        }
        final ResolverFacet resolverFacet = ResolverFacetFromESV.createResolver(esvTerm);
        if (resolverFacet != null) {
            config.addFacet(resolverFacet);
        }
        final HoverFacet hoverFacet = ResolverFacetFromESV.createHover(esvTerm);
        if (hoverFacet != null) {
            config.addFacet(hoverFacet);
        }
        final OutlineFacet outlineFacet = OutlineFacetFromESV.create(esvTerm);
        if (outlineFacet != null) {
            config.addFacet(outlineFacet);
        }
        final ShellFacet shellFacet = ShellFacetFromESV.create(esvTerm);
        if (shellFacet != null) {
            config.addFacet(shellFacet);
        }
    }
    return config;
}
Also used : ResourceExtensionsIdentifier(org.metaborg.core.language.ResourceExtensionsIdentifier) ResolverFacet(org.metaborg.spoofax.core.tracing.ResolverFacet) MetaborgException(org.metaborg.core.MetaborgException) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) LanguageContributionIdentifier(org.metaborg.core.language.LanguageContributionIdentifier) ParseFacet(org.metaborg.core.syntax.ParseFacet) ISpoofaxAnalyzer(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzer) IContextFactory(org.metaborg.core.context.IContextFactory) FileObject(org.apache.commons.vfs2.FileObject) StylerFacet(org.metaborg.spoofax.core.style.StylerFacet) ContextFacet(org.metaborg.core.context.ContextFacet) OutlineFacet(org.metaborg.spoofax.core.outline.OutlineFacet) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) StrategoRuntimeFacet(org.metaborg.spoofax.core.stratego.StrategoRuntimeFacet) ShellFacet(org.metaborg.spoofax.core.shell.ShellFacet) SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) IdentificationFacet(org.metaborg.core.language.IdentificationFacet) ActionFacet(org.metaborg.spoofax.core.action.ActionFacet) AnalysisFacet(org.metaborg.spoofax.core.analysis.AnalysisFacet) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) IContextStrategy(org.metaborg.core.context.IContextStrategy) ResourceExtensionFacet(org.metaborg.core.language.ResourceExtensionFacet) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) HoverFacet(org.metaborg.spoofax.core.tracing.HoverFacet)

Example 2 with ILanguageComponentConfig

use of org.metaborg.core.config.ILanguageComponentConfig in project spoofax by metaborg.

the class LanguageSpecBuilder method generateSources.

public void generateSources(LanguageSpecBuildInput input, @Nullable IFileAccess access) throws IOException, MetaborgException {
    final ISpoofaxLanguageSpec languageSpec = input.languageSpec();
    final FileObject location = languageSpec.location();
    final ISpoofaxLanguageSpecConfig config = languageSpec.config();
    logger.debug("Generating sources for {}", input.languageSpec().location());
    final ContinuousLanguageSpecGenerator generator = new ContinuousLanguageSpecGenerator(new GeneratorSettings(location, config), access, config.sdfEnabled(), config.sdfVersion());
    generator.generateAll();
    componentConfigBuilder.reset();
    componentConfigBuilder.copyFrom(input.languageSpec().config());
    final ILanguageComponentConfig componentConfig = componentConfigBuilder.build(location);
    componentConfigWriter.write(location, componentConfig, access);
    for (IBuildStep buildStep : buildSteps) {
        buildStep.execute(LanguageSpecBuildPhase.generateSources, input);
    }
}
Also used : ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) ISpoofaxLanguageSpecConfig(org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig) FileObject(org.apache.commons.vfs2.FileObject) ContinuousLanguageSpecGenerator(org.metaborg.spoofax.meta.core.generator.general.ContinuousLanguageSpecGenerator) GeneratorSettings(org.metaborg.spoofax.meta.core.generator.GeneratorSettings) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig)

Example 3 with ILanguageComponentConfig

use of org.metaborg.core.config.ILanguageComponentConfig in project spoofax by metaborg.

the class GenerateSourcesBuilder method build.

@Override
public None build(GenerateSourcesBuilder.Input input) throws IOException {
    final File srcGenSigDir = toFile(paths.syntaxSrcGenSignatureDir());
    final File srcGenSyntaxDir = toFile(paths.syntaxSrcGenDir());
    final File srcGenSyntaxCompletionDir = toFile(paths.syntaxCompletionSrcGenDir());
    final File srcGenPpDir = toFile(paths.syntaxSrcGenPpDir());
    final File targetMetaborgDir = toFile(paths.targetMetaborgDir());
    // SDF
    @Nullable final Origin parenthesizeOrigin;
    @Nullable final Origin javaParenthesizeOrigin;
    @Nullable final Origin sigOrigin;
    if (input.sdfModule != null && input.sdfEnabled) {
        final String sdfModule = input.sdfModule;
        final File sdfFile = input.sdfFile;
        // new parse table generator
        if (input.sdf2tableVersion == Sdf2tableVersion.java || input.sdf2tableVersion == Sdf2tableVersion.dynamic || input.sdf2tableVersion == Sdf2tableVersion.incremental) {
            // Get JSGLR parse table from the normalized SDF aterm
            final boolean dynamicGeneration = (input.sdf2tableVersion == Sdf2tableVersion.dynamic || input.sdf2tableVersion == Sdf2tableVersion.incremental);
            final boolean dataDependent = input.dataDependent;
            final File srcNormDir = toFile(paths.syntaxNormDir());
            final File tableFile = FileUtils.getFile(targetMetaborgDir, "sdf.tbl");
            final File contextualGrammarFile = FileUtils.getFile(targetMetaborgDir, "ctxgrammar.aterm");
            final File persistedTableFile = FileUtils.getFile(targetMetaborgDir, "table.bin");
            final File sdfNormFile = FileUtils.getFile(srcNormDir, "permissive-norm.aterm");
            final List<String> paths = Lists.newLinkedList();
            paths.add(srcGenSyntaxDir.getAbsolutePath());
            for (LanguageIdentifier langId : input.sourceDeps) {
                ILanguageImpl lang = context.languageService().getImpl(langId);
                for (final ILanguageComponent component : lang.components()) {
                    ILanguageComponentConfig config = component.config();
                    Collection<IExportConfig> exports = config.exports();
                    for (IExportConfig exportConfig : exports) {
                        exportConfig.accept(new IExportVisitor() {

                            @Override
                            public void visit(LangDirExport export) {
                                if (export.language.equals(SpoofaxConstants.LANG_ATERM_NAME)) {
                                    try {
                                        paths.add(toFileReplicate(component.location().resolveFile(export.directory)).getAbsolutePath());
                                    } catch (FileSystemException e) {
                                        System.out.println("Failed to locate path");
                                        e.printStackTrace();
                                    }
                                }
                            }

                            @Override
                            public void visit(LangFileExport export) {
                            // Ignore file exports
                            }

                            @Override
                            public void visit(ResourceExport export) {
                            // Ignore resource exports
                            }
                        });
                    }
                }
            }
            final Origin sdf2TableJavaOrigin = Sdf2Table.origin(new Sdf2Table.Input(context, sdfNormFile, tableFile, persistedTableFile, contextualGrammarFile, paths, dynamicGeneration, dataDependent));
            requireBuild(sdf2TableJavaOrigin);
            // New parenthesizer
            final File parenthesizerFile = FileUtils.getFile(srcGenPpDir, sdfModule + "-parenthesize.str");
            javaParenthesizeOrigin = Sdf2Parenthesize.origin(new Sdf2Parenthesize.Input(context, persistedTableFile, parenthesizerFile, sdfModule));
            parenthesizeOrigin = null;
            sigOrigin = null;
        } else {
            // Get the SDF def file, either from existing external def, or by running pack SDF on the grammar
            // specification.
            @Nullable final File packSdfFile;
            @Nullable final Origin packSdfOrigin;
            if (input.sdfExternalDef != null) {
                packSdfFile = input.sdfExternalDef;
                packSdfOrigin = null;
            } else if (sdfFile != null) {
                require(sdfFile, FileExistsStamper.instance);
                if (!sdfFile.exists()) {
                    throw new IOException("Main SDF file at " + sdfFile + " does not exist");
                }
                packSdfFile = FileUtils.getFile(srcGenSyntaxDir, sdfModule + ".def");
                packSdfOrigin = PackSdf.origin(new PackSdf.Input(context, sdfModule, sdfFile, packSdfFile, input.packSdfIncludePaths, input.packSdfArgs, null));
            } else {
                packSdfFile = null;
                packSdfOrigin = null;
            }
            if (packSdfFile != null) {
                // file.
                if (input.sdfExternalDef != null || input.sdfVersion == SdfVersion.sdf2) {
                    final File rtgFile = FileUtils.getFile(srcGenSigDir, sdfModule + ".rtg");
                    final Origin rtgOrigin = Sdf2Rtg.origin(new Sdf2Rtg.Input(context, packSdfFile, rtgFile, sdfModule, packSdfOrigin));
                    final File sigFile = FileUtils.getFile(srcGenSigDir, sdfModule + ".str");
                    final String sigModule = "signatures/" + sdfModule;
                    sigOrigin = Rtg2Sig.origin(new Rtg2Sig.Input(context, rtgFile, sigFile, sigModule, rtgOrigin));
                } else {
                    sigOrigin = null;
                }
                // Get Stratego parenthesizer file, from the SDF def file.
                final File parenthesizeFile = FileUtils.getFile(srcGenPpDir, sdfModule + "-parenthesize.str");
                final String parenthesizeModule = "pp/" + sdfModule + "-parenthesize";
                parenthesizeOrigin = Sdf2ParenthesizeLegacy.origin(new Sdf2ParenthesizeLegacy.Input(context, packSdfFile, parenthesizeFile, sdfModule, parenthesizeModule, packSdfOrigin));
                // Get SDF permissive def file, from the SDF def file.
                final File permissiveDefFile = FileUtils.getFile(srcGenSyntaxDir, sdfModule + "-permissive.def");
                final Origin permissiveDefOrigin = MakePermissive.origin(new MakePermissive.Input(context, packSdfFile, permissiveDefFile, sdfModule, packSdfOrigin));
                // Get JSGLR parse table, from the SDF permissive def file.
                final File tableFile = FileUtils.getFile(targetMetaborgDir, "sdf.tbl");
                final Origin sdf2TableOrigin = Sdf2TableLegacy.origin(new Sdf2TableLegacy.Input(context, permissiveDefFile, tableFile, sdfModule, permissiveDefOrigin));
                requireBuild(sdf2TableOrigin);
                javaParenthesizeOrigin = null;
            } else {
                javaParenthesizeOrigin = null;
                parenthesizeOrigin = null;
                sigOrigin = null;
            }
        }
    } else {
        javaParenthesizeOrigin = null;
        parenthesizeOrigin = null;
        sigOrigin = null;
    }
    // SDF completions
    final Origin sdfCompletionOrigin;
    if (input.sdfCompletionFile != null && input.sdfEnabled) {
        final String sdfCompletionsModule = input.sdfCompletionModule;
        final File sdfCompletionsFile = input.sdfCompletionFile;
        if (input.sdf2tableVersion == Sdf2tableVersion.java || input.sdf2tableVersion == Sdf2tableVersion.dynamic || input.sdf2tableVersion == Sdf2tableVersion.incremental) {
            // Get JSGLR parse table, from the normalized SDF aterm
            final boolean dynamicGeneration = (input.sdf2tableVersion == Sdf2tableVersion.dynamic || input.sdf2tableVersion == Sdf2tableVersion.incremental);
            final boolean dataDependent = input.dataDependent;
            final List<String> paths = Lists.newLinkedList();
            paths.add(srcGenSyntaxDir.getAbsolutePath());
            for (LanguageIdentifier langId : input.sourceDeps) {
                ILanguageImpl lang = context.languageService().getImpl(langId);
                for (final ILanguageComponent component : lang.components()) {
                    ILanguageComponentConfig config = component.config();
                    Collection<IExportConfig> exports = config.exports();
                    for (IExportConfig exportConfig : exports) {
                        exportConfig.accept(new IExportVisitor() {

                            @Override
                            public void visit(LangDirExport export) {
                                if (export.language.equals(SpoofaxConstants.LANG_ATERM_NAME)) {
                                    try {
                                        paths.add(toFileReplicate(component.location().resolveFile(export.directory)).getAbsolutePath());
                                    } catch (FileSystemException e) {
                                        System.out.println("Failed to locate path");
                                        e.printStackTrace();
                                    }
                                }
                            }

                            @Override
                            public void visit(LangFileExport export) {
                            // Ignore file exports
                            }

                            @Override
                            public void visit(ResourceExport export) {
                            // Ignore resource exports
                            }
                        });
                    }
                }
            }
            final File tableFile = FileUtils.getFile(targetMetaborgDir, "sdf-completions.tbl");
            sdfCompletionOrigin = Sdf2Table.origin(new Sdf2Table.Input(context, sdfCompletionsFile, tableFile, null, null, paths, dynamicGeneration, dataDependent));
            requireBuild(sdfCompletionOrigin);
        } else {
            // Get the SDF def file, either from existing external def, or by running pack SDF on the grammar
            // specification.
            @Nullable final File packSdfCompletionsFile;
            @Nullable final Origin packSdfCompletionsOrigin;
            if (sdfCompletionsFile != null) {
                require(sdfCompletionsFile, FileExistsStamper.instance);
                if (!sdfCompletionsFile.exists()) {
                    throw new IOException("Main SDF completions file at " + sdfCompletionsFile + " does not exist");
                }
                packSdfCompletionsFile = FileUtils.getFile(srcGenSyntaxCompletionDir, sdfCompletionsModule + ".def");
                packSdfCompletionsOrigin = PackSdf.origin(new PackSdf.Input(context, sdfCompletionsModule, sdfCompletionsFile, packSdfCompletionsFile, input.packSdfIncludePaths, input.packSdfArgs, null));
            } else {
                packSdfCompletionsFile = null;
                packSdfCompletionsOrigin = null;
            }
            if (packSdfCompletionsFile != null) {
                // Get SDF permissive def file, from the SDF def file.
                final File permissiveCompletionsDefFile = FileUtils.getFile(srcGenSyntaxCompletionDir, sdfCompletionsModule + "-permissive.def");
                final Origin permissiveCompletionsDefOrigin = MakePermissive.origin(new MakePermissive.Input(context, packSdfCompletionsFile, permissiveCompletionsDefFile, sdfCompletionsModule, packSdfCompletionsOrigin));
                // Get JSGLR parse table, from the SDF permissive def file.
                final File completionsTableFile = FileUtils.getFile(targetMetaborgDir, "sdf-completions.tbl");
                sdfCompletionOrigin = Sdf2TableLegacy.origin(new Sdf2TableLegacy.Input(context, permissiveCompletionsDefFile, completionsTableFile, "completion/" + sdfCompletionsModule, permissiveCompletionsDefOrigin));
                requireBuild(sdfCompletionOrigin);
            } else {
                sdfCompletionOrigin = null;
            }
        }
    } else {
        sdfCompletionOrigin = null;
    }
    // SDF meta-module for creating a Stratego concrete syntax extension parse table
    final File sdfMetaFile = input.sdfMetaFile;
    final Origin sdfMetaOrigin;
    if (sdfMetaFile != null) {
        require(sdfMetaFile, FileExistsStamper.instance);
        if (!sdfMetaFile.exists()) {
            throw new IOException("Main meta-SDF file at " + sdfMetaFile + " does not exist");
        }
        final String sdfMetaModule = input.sdfMetaModule;
        final BuildRequest<PrepareNativeBundle.Input, OutputTransient<PrepareNativeBundle.Output>, PrepareNativeBundle, SpoofaxBuilderFactory<PrepareNativeBundle.Input, OutputTransient<PrepareNativeBundle.Output>, PrepareNativeBundle>> nativeBundleRequest = PrepareNativeBundle.request(new PrepareNativeBundle.Input(context));
        final File strategoMixFile = requireBuild(nativeBundleRequest).val().strategoMixFile;
        final Origin strategoMixOrigin = Origin.from(nativeBundleRequest);
        final Arguments packSdfMetaArgs = new Arguments(input.packSdfArgs);
        packSdfMetaArgs.addFile("-Idef", strategoMixFile);
        final File packSdfFile = FileUtils.getFile(srcGenSyntaxDir, sdfMetaModule + ".def");
        final Origin packSdfOrigin = PackSdf.origin(new PackSdf.Input(context, sdfMetaModule, sdfMetaFile, packSdfFile, input.packSdfIncludePaths, packSdfMetaArgs, strategoMixOrigin));
        final File permissiveDefFile = FileUtils.getFile(srcGenSyntaxDir, sdfMetaModule + "-permissive.def");
        final Origin permissiveDefOrigin = MakePermissive.origin(new MakePermissive.Input(context, packSdfFile, permissiveDefFile, sdfMetaModule, packSdfOrigin));
        final File transDir = toFile(paths.transDir());
        final File tableFile = FileUtils.getFile(transDir, sdfMetaModule + ".tbl");
        sdfMetaOrigin = Sdf2TableLegacy.origin(new Sdf2TableLegacy.Input(context, permissiveDefFile, tableFile, sdfMetaModule, permissiveDefOrigin));
        requireBuild(sdfMetaOrigin);
    } else {
        sdfMetaOrigin = null;
    }
    // Stratego
    final File strFile = input.strFile;
    if (strFile != null) {
        require(strFile, FileExistsStamper.instance);
        if (!strFile.exists()) {
            throw new IOException("Main Stratego file at " + strFile + " does not exist");
        }
        boolean buildStrJavaStrat = input.strJavaStratPackage != null && input.strJavaStratFile != null;
        if (buildStrJavaStrat) {
            require(input.strJavaStratFile, FileExistsStamper.instance);
            if (!input.strJavaStratFile.exists()) {
                throw new IOException("Main Stratego Java strategies file at " + input.strJavaStratFile + " does not exist");
            }
        }
        final Arguments extraArgs = new Arguments();
        extraArgs.addAll(input.strjArgs);
        final File outputFile;
        final File depPath;
        if (input.strFormat == StrategoFormat.ctree) {
            outputFile = FileUtils.getFile(targetMetaborgDir, "stratego.ctree");
            depPath = outputFile;
            extraArgs.add("-F");
        } else {
            depPath = toFile(paths.strSrcGenJavaTransDir(input.languageId));
            outputFile = FileUtils.getFile(depPath, "Main.java");
            extraArgs.add("-la", "java-front");
            if (buildStrJavaStrat) {
                extraArgs.add("-la", input.strJavaStratPackage);
            }
        }
        if (input.strExternalJarFlags != null) {
            extraArgs.addLine(input.strExternalJarFlags);
        }
        // @formatter:off
        final Origin origin;
        if (input.sdf2tableVersion == Sdf2tableVersion.java || input.sdf2tableVersion == Sdf2tableVersion.dynamic) {
            origin = Origin.Builder().add(sigOrigin).add(sdfCompletionOrigin).add(sdfMetaOrigin).add(javaParenthesizeOrigin).get();
        } else {
            origin = Origin.Builder().add(parenthesizeOrigin).add(sigOrigin).add(sdfCompletionOrigin).add(sdfMetaOrigin).get();
        }
        // @formatter:on
        final File cacheDir = toFile(paths.strCacheDir());
        final Strj.Input strjInput = new Strj.Input(context, strFile, outputFile, depPath, input.strJavaPackage, true, true, input.strjIncludeDirs, input.strjIncludeFiles, Lists.newArrayList(), cacheDir, extraArgs, origin);
        final Origin strjOrigin = Strj.origin(strjInput);
        requireBuild(strjOrigin);
        // Typesmart
        final File typesmartExportedFile = toFile(paths.strTypesmartExportedFile());
        final Typesmart.Input typesmartInput = new Typesmart.Input(context, input.strFile, input.strjIncludeDirs, typesmartExportedFile, origin);
        final Origin typesmartOrigin = Typesmart.origin(typesmartInput);
        requireBuild(typesmartOrigin);
    }
    return None.val;
}
Also used : Origin(build.pluto.dependency.Origin) MakePermissive(org.metaborg.spoofax.meta.core.pluto.build.MakePermissive) OutputTransient(build.pluto.output.OutputTransient) IExportConfig(org.metaborg.core.config.IExportConfig) Sdf2Table(org.metaborg.spoofax.meta.core.pluto.build.Sdf2Table) FileSystemException(org.apache.commons.vfs2.FileSystemException) SpoofaxInput(org.metaborg.spoofax.meta.core.pluto.SpoofaxInput) Typesmart(org.metaborg.spoofax.meta.core.pluto.build.Typesmart) IExportVisitor(org.metaborg.core.config.IExportVisitor) LangDirExport(org.metaborg.core.config.LangDirExport) Sdf2Rtg(org.metaborg.spoofax.meta.core.pluto.build.Sdf2Rtg) Strj(org.metaborg.spoofax.meta.core.pluto.build.Strj) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) LangFileExport(org.metaborg.core.config.LangFileExport) PackSdf(org.metaborg.spoofax.meta.core.pluto.build.PackSdf) PrepareNativeBundle(org.metaborg.spoofax.meta.core.pluto.build.misc.PrepareNativeBundle) Arguments(org.metaborg.util.cmd.Arguments) IOException(java.io.IOException) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ResourceExport(org.metaborg.core.config.ResourceExport) Sdf2TableLegacy(org.metaborg.spoofax.meta.core.pluto.build.Sdf2TableLegacy) SpoofaxBuilderFactory(org.metaborg.spoofax.meta.core.pluto.SpoofaxBuilderFactory) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 4 with ILanguageComponentConfig

use of org.metaborg.core.config.ILanguageComponentConfig in project spoofax by metaborg.

the class LanguageComponentFactory method request.

private IComponentCreationConfigRequest request(FileObject root) throws MetaborgException {
    final Collection<String> errors = Lists.newLinkedList();
    final Collection<Throwable> exceptions = Lists.newLinkedList();
    final ConfigRequest<ILanguageComponentConfig> configRequest = componentConfigService.get(root);
    if (!configRequest.valid()) {
        for (IMessage message : configRequest.errors()) {
            errors.add(message.message());
            final Throwable exception = message.exception();
            if (exception != null) {
                exceptions.add(exception);
            }
        }
    }
    final ILanguageComponentConfig config = configRequest.config();
    if (config == null) {
        final String message = logger.format("Cannot retrieve language component configuration at {}", root);
        errors.add(message);
        return new ComponentFactoryRequest(root, errors, exceptions);
    }
    final IStrategoAppl esvTerm;
    try {
        final FileObject esvFile = root.resolveFile("target/metaborg/editor.esv.af");
        if (!esvFile.exists()) {
            esvTerm = null;
        } else {
            esvTerm = esvTerm(root, esvFile);
        }
    } catch (ParseError | IOException | MetaborgException e) {
        exceptions.add(e);
        return new ComponentFactoryRequest(root, errors, exceptions);
    }
    SyntaxFacet syntaxFacet = null;
    StrategoRuntimeFacet strategoRuntimeFacet = null;
    if (esvTerm != null) {
        try {
            syntaxFacet = SyntaxFacetFromESV.create(esvTerm, root);
            if (syntaxFacet != null) {
                Iterables.addAll(errors, syntaxFacet.available());
            }
        } catch (FileSystemException e) {
            exceptions.add(e);
        }
        try {
            strategoRuntimeFacet = StrategoRuntimeFacetFromESV.create(esvTerm, root);
            if (strategoRuntimeFacet != null) {
                Iterables.addAll(errors, strategoRuntimeFacet.available(resourceService));
            }
        } catch (IOException e) {
            exceptions.add(e);
        }
    }
    final ComponentFactoryRequest request;
    if (errors.isEmpty() && exceptions.isEmpty()) {
        request = new ComponentFactoryRequest(root, config, esvTerm, syntaxFacet, strategoRuntimeFacet);
    } else {
        request = new ComponentFactoryRequest(root, errors, exceptions);
    }
    return request;
}
Also used : SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) IMessage(org.metaborg.core.messages.IMessage) MetaborgException(org.metaborg.core.MetaborgException) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) IOException(java.io.IOException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ParseError(org.spoofax.terms.ParseError) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) StrategoRuntimeFacet(org.metaborg.spoofax.core.stratego.StrategoRuntimeFacet)

Example 5 with ILanguageComponentConfig

use of org.metaborg.core.config.ILanguageComponentConfig in project spoofax by metaborg.

the class DialectService method createDialect.

private ILanguageImpl createDialect(String name, FileObject location, ILanguageImpl base, IFacet syntaxFacet, boolean replaceIdentification, boolean appendDialectName) {
    final LanguageIdentifier baseId = base.id();
    final String dialectId;
    if (appendDialectName) {
        dialectId = baseId.id + "-Dialect-" + name;
    } else {
        dialectId = baseId.id;
    }
    final LanguageIdentifier id = new LanguageIdentifier(baseId.groupId, dialectId, baseId.version);
    // HACK: use config of first component.
    final ILanguageComponentConfig config = Iterables.get(base.components(), 0).config();
    final ComponentCreationConfig creationConfig = languageService.create(id, location, Iterables2.singleton(new LanguageContributionIdentifier(id, name)), config);
    for (IFacet facet : base.facets()) {
        if (facet instanceof IdentificationFacet && replaceIdentification) {
            creationConfig.addFacet(new IdentificationFacet(new MetaFileIdentifier((IdentificationFacet) facet)));
        } else if (facet instanceof SyntaxFacet || facet instanceof ResourceExtensionFacet) {
        // Ignore
        } else {
            creationConfig.addFacet(facet);
        }
    }
    creationConfig.addFacet(syntaxFacet);
    final ILanguageComponent dialectComponent = languageService.add(creationConfig);
    final ILanguageImpl dialect = Iterables.get(dialectComponent.contributesTo(), 0);
    return dialect;
}
Also used : SyntaxFacet(org.metaborg.spoofax.core.syntax.SyntaxFacet) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) IdentificationFacet(org.metaborg.core.language.IdentificationFacet) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IFacet(org.metaborg.core.language.IFacet) ResourceExtensionFacet(org.metaborg.core.language.ResourceExtensionFacet) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) ILanguageComponentConfig(org.metaborg.core.config.ILanguageComponentConfig) LanguageContributionIdentifier(org.metaborg.core.language.LanguageContributionIdentifier)

Aggregations

ILanguageComponentConfig (org.metaborg.core.config.ILanguageComponentConfig)5 FileObject (org.apache.commons.vfs2.FileObject)3 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)3 SyntaxFacet (org.metaborg.spoofax.core.syntax.SyntaxFacet)3 IOException (java.io.IOException)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 MetaborgException (org.metaborg.core.MetaborgException)2 ComponentCreationConfig (org.metaborg.core.language.ComponentCreationConfig)2 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)2 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)2 IdentificationFacet (org.metaborg.core.language.IdentificationFacet)2 LanguageContributionIdentifier (org.metaborg.core.language.LanguageContributionIdentifier)2 ResourceExtensionFacet (org.metaborg.core.language.ResourceExtensionFacet)2 StrategoRuntimeFacet (org.metaborg.spoofax.core.stratego.StrategoRuntimeFacet)2 Origin (build.pluto.dependency.Origin)1 OutputTransient (build.pluto.output.OutputTransient)1 File (java.io.File)1 Nullable (javax.annotation.Nullable)1 IExportConfig (org.metaborg.core.config.IExportConfig)1 IExportVisitor (org.metaborg.core.config.IExportVisitor)1