Search in sources :

Example 1 with ConfigException

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

the class SpoofaxContext method init.

public void init() {
    this.base = this.resourceService().resolve(baseURI);
    this.project = projectService.get(base);
    if (this.project == null) {
        this.languageSpec = null;
        return;
    }
    try {
        this.languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new MetaborgRuntimeException("Cannot convert project " + project + " into a language specification project", e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) ConfigException(org.metaborg.core.config.ConfigException)

Example 2 with ConfigException

use of org.metaborg.core.config.ConfigException 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 3 with ConfigException

use of org.metaborg.core.config.ConfigException 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)

Example 4 with ConfigException

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

the class LegacyLanguageSpecNamePrimitive method call.

@Override
protected IStrategoTerm call(IStrategoTerm current, Strategy[] svars, IStrategoTerm[] tvars, ITermFactory factory, IContext context) throws MetaborgException {
    final FileObject location = context.location();
    final IProject project = projectService.get(location);
    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.debug("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 name for " + location, e);
    }
    if (languageSpec == null) {
        return null;
    }
    return factory.makeString(languageSpec.config().name());
}
Also used : ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) MetaborgException(org.metaborg.core.MetaborgException) ConfigException(org.metaborg.core.config.ConfigException) FileObject(org.apache.commons.vfs2.FileObject) IProject(org.metaborg.core.project.IProject)

Example 5 with ConfigException

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

the class PlaceholderCharsPrimitive 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;
    }
    PlaceholderCharacters placeholderChars = languageSpec.config().placeholderChars();
    IStrategoString prefix = env.getFactory().makeString(placeholderChars.prefix);
    IStrategoString suffix = null;
    if (placeholderChars.suffix != null) {
        suffix = env.getFactory().makeString(placeholderChars.suffix);
    } else {
        suffix = env.getFactory().makeString("");
    }
    env.setCurrent(env.getFactory().makeTuple(prefix, suffix));
    return true;
}
Also used : IContext(org.spoofax.interpreter.core.IContext) InterpreterException(org.spoofax.interpreter.core.InterpreterException) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) ConfigException(org.metaborg.core.config.ConfigException) PlaceholderCharacters(org.metaborg.spoofax.meta.core.config.PlaceholderCharacters) IProject(org.metaborg.core.project.IProject) ISpoofaxLanguageSpec(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec) ISpoofaxLanguageSpecService(org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

ConfigException (org.metaborg.core.config.ConfigException)7 FileObject (org.apache.commons.vfs2.FileObject)5 IProject (org.metaborg.core.project.IProject)5 ISpoofaxLanguageSpec (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpec)5 ISpoofaxLanguageSpecService (org.metaborg.spoofax.meta.core.project.ISpoofaxLanguageSpecService)5 MetaborgException (org.metaborg.core.MetaborgException)3 IContext (org.spoofax.interpreter.core.IContext)2 InterpreterException (org.spoofax.interpreter.core.InterpreterException)2 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)2 Nullable (javax.annotation.Nullable)1 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)1 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)1 StreamMessagePrinter (org.metaborg.core.messages.StreamMessagePrinter)1 ISpoofaxLanguageSpecConfig (org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig)1 PlaceholderCharacters (org.metaborg.spoofax.meta.core.config.PlaceholderCharacters)1