Search in sources :

Example 1 with ISpoofaxLanguageSpec

use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.

the class LanguageSpecBuilder method archiveBuilderInput.

private ArchiveBuilder.Input archiveBuilderInput(LanguageSpecBuildInput input, Origin origin) {
    final ISpoofaxLanguageSpec languageSpec = input.languageSpec();
    final ISpoofaxLanguageSpecConfig config = languageSpec.config();
    final FileObject baseLoc = input.languageSpec().location();
    final SpoofaxLangSpecCommonPaths paths = new SpoofaxLangSpecCommonPaths(baseLoc);
    final FileObject buildInfoLoc = paths.plutoBuildInfoDir();
    final SpoofaxContext context = new SpoofaxContext(baseLoc, buildInfoLoc);
    final Iterable<IExportConfig> exports = config.exports();
    final LanguageIdentifier languageIdentifier = config.identifier();
    return new ArchiveBuilder.Input(context, origin, exports, languageIdentifier);
}
Also used : IExportConfig(org.metaborg.core.config.IExportConfig) BuildInput(org.metaborg.core.build.BuildInput) ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) SpoofaxContext(org.metaborg.spoofax.meta.core.pluto.SpoofaxContext) ISpoofaxLanguageSpecConfig(org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig) FileObject(org.apache.commons.vfs2.FileObject)

Example 2 with ISpoofaxLanguageSpec

use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec 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 ISpoofaxLanguageSpec

use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.

the class LanguageSpecBuilder method generateSourcesBuilderInput.

private GenerateSourcesBuilder.Input generateSourcesBuilderInput(LanguageSpecBuildInput input) throws FileSystemException, MetaborgException {
    final ISpoofaxLanguageSpec languageSpec = input.languageSpec();
    final ISpoofaxLanguageSpecConfig config = languageSpec.config();
    final FileObject baseLoc = input.languageSpec().location();
    final SpoofaxLangSpecCommonPaths paths = new SpoofaxLangSpecCommonPaths(baseLoc);
    final FileObject buildInfoLoc = paths.plutoBuildInfoDir();
    final SpoofaxContext context = new SpoofaxContext(baseLoc, buildInfoLoc);
    // SDF
    final Boolean sdfEnabled = config.sdfEnabled();
    final String sdfModule = config.sdfName();
    final FileObject sdfFileCandidate;
    final SdfVersion sdfVersion = config.sdfVersion();
    final Sdf2tableVersion sdf2tableVersion = config.sdf2tableVersion();
    switch(sdfVersion) {
        case sdf2:
            final Iterable<FileObject> sdfRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_SDF_NAME);
            sdfFileCandidate = paths.findSyntaxMainFile(sdfRoots, sdfModule);
            break;
        case sdf3:
            sdfFileCandidate = paths.syntaxSrcGenMainFile(sdfModule);
            break;
        default:
            throw new MetaborgException("Unknown SDF version: " + sdfVersion);
    }
    @Nullable final File sdfFile;
    if (sdfFileCandidate != null && sdfFileCandidate.exists()) {
        sdfFile = resourceService.localPath(sdfFileCandidate);
    } else {
        sdfFile = null;
    }
    @Nullable final File sdfExternalDef;
    final String sdfExternalDefStr = config.sdfExternalDef();
    if (sdfExternalDefStr != null) {
        final FileObject sdfExternalDefLoc = resourceService.resolve(sdfExternalDefStr);
        if (!sdfExternalDefLoc.exists()) {
            throw new MetaborgException("External SDF definition at " + sdfExternalDefLoc + " does not exist");
        }
        sdfExternalDef = resourceService.localFile(sdfExternalDefLoc);
    } else {
        sdfExternalDef = null;
    }
    final Iterable<FileObject> sdfIncludePaths = languagePathService.sourceAndIncludePaths(languageSpec, SpoofaxConstants.LANG_SDF_NAME);
    final FileObject packSdfIncludesReplicateDir = paths.replicateDir().resolveFile("pack-sdf-includes");
    packSdfIncludesReplicateDir.delete(new AllFileSelector());
    final List<File> packSdfIncludePaths = Lists.newArrayList();
    for (FileObject path : sdfIncludePaths) {
        if (!path.exists()) {
            continue;
        }
        packSdfIncludePaths.add(resourceService.localFile(path, packSdfIncludesReplicateDir));
    }
    final Arguments packSdfArgs = config.sdfArgs();
    // SDF completions
    final String sdfCompletionModule = config.sdfName() + "-completion-insertions";
    @Nullable final File sdfCompletionFile;
    FileObject sdfCompletionFileCandidate = null;
    if (sdf2tableVersion == Sdf2tableVersion.c) {
        sdfCompletionFileCandidate = paths.syntaxCompletionMainFile(sdfCompletionModule);
    } else if (sdf2tableVersion == Sdf2tableVersion.java || sdf2tableVersion == Sdf2tableVersion.dynamic) {
        sdfCompletionFileCandidate = paths.syntaxCompletionMainFileNormalized(sdfCompletionModule);
    }
    boolean dataDependent = config.dataDependent();
    if (sdfCompletionFileCandidate != null && sdfCompletionFileCandidate.exists()) {
        sdfCompletionFile = resourceService.localPath(sdfCompletionFileCandidate);
    } else {
        sdfCompletionFile = null;
    }
    // Meta-SDF
    final Iterable<FileObject> sdfRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_SDF_NAME);
    final String sdfMetaModule = config.metaSdfName();
    final FileObject sdfMetaFileCandidate = paths.findSyntaxMainFile(sdfRoots, sdfMetaModule);
    @Nullable final File sdfMetaFile;
    if (sdfMetaFileCandidate != null && sdfMetaFileCandidate.exists()) {
        sdfMetaFile = resourceService.localPath(sdfMetaFileCandidate);
    } else {
        sdfMetaFile = null;
    }
    // Stratego
    final String strModule = config.strategoName();
    final Iterable<FileObject> strRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_STRATEGO_NAME);
    final FileObject strFileCandidate = paths.findStrMainFile(strRoots, strModule);
    @Nullable final File strFile;
    if (strFileCandidate != null && strFileCandidate.exists()) {
        strFile = resourceService.localPath(strFileCandidate);
    } else {
        strFile = null;
    }
    final String strStratPkg = paths.strJavaTransPkg(config.identifier().id);
    final String strJavaStratPkg = paths.strJavaStratPkg(config.identifier().id);
    final FileObject strJavaStratFileCandidate = paths.strMainJavaStratFile(config.identifier().id);
    @Nullable final File strJavaStratFile;
    if (strJavaStratFileCandidate.exists()) {
        strJavaStratFile = resourceService.localPath(strJavaStratFileCandidate);
    } else {
        strJavaStratFile = null;
    }
    final StrategoFormat strFormat = config.strFormat();
    @Nullable final File strExternalJar;
    final String strExternalJarStr = config.strExternalJar();
    if (strExternalJarStr != null) {
        final FileObject strExternalJarLoc = resourceService.resolve(strExternalJarStr);
        if (!strExternalJarLoc.exists()) {
            throw new MetaborgException("External Stratego JAR at " + strExternalJarLoc + " does not exist");
        }
        strExternalJar = resourceService.localFile(strExternalJarLoc);
    } else {
        strExternalJar = null;
    }
    final String strExternalJarFlags = config.strExternalJarFlags();
    final Iterable<FileObject> strIncludePaths = languagePathService.sourceAndIncludePaths(languageSpec, SpoofaxConstants.LANG_STRATEGO_NAME);
    final FileObject strjIncludesReplicateDir = paths.replicateDir().resolveFile("strj-includes");
    strjIncludesReplicateDir.delete(new AllFileSelector());
    final List<File> strjIncludeDirs = Lists.newArrayList();
    final List<File> strjIncludeFiles = Lists.newArrayList();
    for (FileObject path : strIncludePaths) {
        if (!path.exists()) {
            continue;
        }
        if (path.isFolder()) {
            strjIncludeDirs.add(resourceService.localFile(path, strjIncludesReplicateDir));
        }
        if (path.isFile()) {
            strjIncludeFiles.add(resourceService.localFile(path, strjIncludesReplicateDir));
        }
    }
    final Arguments strjArgs = config.strArgs();
    return new GenerateSourcesBuilder.Input(context, config.identifier().id, config.sourceDeps(), sdfEnabled, sdfModule, sdfFile, sdfVersion, sdf2tableVersion, dataDependent, sdfExternalDef, packSdfIncludePaths, packSdfArgs, sdfCompletionModule, sdfCompletionFile, sdfMetaModule, sdfMetaFile, strFile, strStratPkg, strJavaStratPkg, strJavaStratFile, strFormat, strExternalJar, strExternalJarFlags, strjIncludeDirs, strjIncludeFiles, strjArgs);
}
Also used : StrategoFormat(org.metaborg.spoofax.meta.core.config.StrategoFormat) ISpoofaxLanguageSpecConfig(org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig) MetaborgException(org.metaborg.core.MetaborgException) Arguments(org.metaborg.util.cmd.Arguments) BuildInput(org.metaborg.core.build.BuildInput) ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) SdfVersion(org.metaborg.spoofax.meta.core.config.SdfVersion) SpoofaxContext(org.metaborg.spoofax.meta.core.pluto.SpoofaxContext) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) Sdf2tableVersion(org.metaborg.core.config.Sdf2tableVersion) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 4 with ISpoofaxLanguageSpec

use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.

the class CheckSdf2TablePrimitive method call.

@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
    org.metaborg.core.context.IContext context = (org.metaborg.core.context.IContext) env.contextObject();
    final FileObject location = context.location();
    final IProject project = projectService.get(location);
    if (project == null) {
        return false;
    }
    if (languageSpecServiceProvider == null) {
        // Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
        // should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
        logger.error("Language specification service is not available; static injection failed");
        return false;
    }
    final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
    if (!languageSpecService.available(project)) {
        return false;
    }
    final ISpoofaxLanguageSpec languageSpec;
    try {
        languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new InterpreterException("Unable to get language specification name for " + location, e);
    }
    if (languageSpec == null) {
        return false;
    }
    if (!languageSpec.config().sdfEnabled()) {
        env.setCurrent(env.getFactory().makeString("disabled"));
        return true;
    }
    env.setCurrent(env.getFactory().makeString(languageSpec.config().sdf2tableVersion().toString()));
    return true;
}
Also used : IContext(org.spoofax.interpreter.core.IContext) ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) InterpreterException(org.spoofax.interpreter.core.InterpreterException) ConfigException(org.metaborg.core.config.ConfigException) FileObject(org.apache.commons.vfs2.FileObject) IProject(org.metaborg.core.project.IProject)

Example 5 with ISpoofaxLanguageSpec

use of org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec in project spoofax by metaborg.

the class LanguageSpecificationPrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
    final IProject project = context.project();
    if (project == null) {
        return null;
    }
    if (languageSpecServiceProvider == null) {
        // Indicates that meta-Spoofax is not available (ISpoofaxLanguageSpecService cannot be injected), but this
        // should never happen because this primitive is inside meta-Spoofax. Check for null just in case.
        logger.error("Language specification service is not available; static injection failed");
        return null;
    }
    final ISpoofaxLanguageSpecService languageSpecService = languageSpecServiceProvider.get();
    if (!languageSpecService.available(project)) {
        return null;
    }
    final ISpoofaxLanguageSpec languageSpec;
    try {
        languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new MetaborgException("Unable to get language specification configuration for " + project, e);
    }
    if (languageSpec == null) {
        return null;
    }
    final IStrategoString nameTerm = factory.makeString(languageSpec.config().name());
    final LanguageIdentifier id = languageSpec.config().identifier();
    final IStrategoString groupIdTerm = factory.makeString(id.groupId);
    final IStrategoString idTerm = factory.makeString(id.id);
    final IStrategoString versionTerm = factory.makeString(id.version.toString());
    final IStrategoString locationTerm = factory.makeString(languageSpec.location().getName().getURI());
    return factory.makeTuple(nameTerm, groupIdTerm, idTerm, versionTerm, locationTerm);
}
Also used : ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) MetaborgException(org.metaborg.core.MetaborgException) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ConfigException(org.metaborg.core.config.ConfigException) IProject(org.metaborg.core.project.IProject)

Aggregations

ISpoofaxLanguageSpec (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec)9 FileObject (org.apache.commons.vfs2.FileObject)8 ConfigException (org.metaborg.core.config.ConfigException)5 IProject (org.metaborg.core.project.IProject)5 ISpoofaxLanguageSpecService (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService)5 MetaborgException (org.metaborg.core.MetaborgException)4 ISpoofaxLanguageSpecConfig (org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig)4 BuildInput (org.metaborg.core.build.BuildInput)3 SpoofaxContext (org.metaborg.spoofax.meta.core.pluto.SpoofaxContext)3 File (java.io.File)2 Nullable (javax.annotation.Nullable)2 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)2 StrategoFormat (org.metaborg.spoofax.meta.core.config.StrategoFormat)2 IContext (org.spoofax.interpreter.core.IContext)2 InterpreterException (org.spoofax.interpreter.core.InterpreterException)2 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)2 AllFileSelector (org.apache.commons.vfs2.AllFileSelector)1 IExportConfig (org.metaborg.core.config.IExportConfig)1 ILanguageComponentConfig (org.metaborg.core.config.ILanguageComponentConfig)1 Sdf2tableVersion (org.metaborg.core.config.Sdf2tableVersion)1