Search in sources :

Example 1 with EndNamedGoal

use of org.metaborg.core.action.EndNamedGoal in project spoofax by metaborg.

the class ActionFacetFromESV method menu.

private static Menu menu(IStrategoTerm menuTerm, TransformActionFlags flags, ImmutableList<String> nesting, Multimap<ITransformGoal, ITransformAction> actions) {
    final String name = name(menuTerm.getSubterm(0));
    final ImmutableList<String> newNesting = ImmutableList.<String>builder().addAll(nesting).add(name).build();
    final TransformActionFlags extraFlags = flags(menuTerm.getSubterm(1));
    final TransformActionFlags mergedFlags = TransformActionFlags.merge(flags, extraFlags);
    final Iterable<IStrategoTerm> items = menuTerm.getSubterm(2);
    final Menu menu = new Menu(name);
    for (IStrategoTerm item : items) {
        final String constructor = Tools.constructorName(item);
        if (constructor == null) {
            logger.error("Could not interpret menu item from term {}", item);
            continue;
        }
        switch(constructor) {
            case "Submenu":
                final Menu submenu = menu(item, mergedFlags, newNesting, actions);
                menu.add(submenu);
                break;
            case "Action":
                final String actionName = name(item.getSubterm(0));
                final String strategy = Tools.asJavaString(item.getSubterm(1).getSubterm(0));
                final TransformActionFlags actionFlags = flags(item.getSubterm(2));
                final TransformActionFlags mergedActionFlags = TransformActionFlags.merge(mergedFlags, actionFlags);
                final ImmutableList<String> newActionNesting = ImmutableList.<String>builder().addAll(newNesting).add(actionName).build();
                final NamedGoal goal = new NamedGoal(newActionNesting);
                final TransformAction action = new TransformAction(actionName, goal, mergedActionFlags, strategy);
                actions.put(goal, action);
                actions.put(new EndNamedGoal(goal.names.get(goal.names.size() - 1)), action);
                final MenuAction menuAction = new MenuAction(action);
                menu.add(menuAction);
                break;
            case "Separator":
                final Separator separator = new Separator();
                menu.add(separator);
                break;
            default:
                logger.warn("Unhandled menu item term {}", item);
                break;
        }
    }
    return menu;
}
Also used : MenuAction(org.metaborg.core.menu.MenuAction) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) NamedGoal(org.metaborg.core.action.NamedGoal) EndNamedGoal(org.metaborg.core.action.EndNamedGoal) TransformActionFlags(org.metaborg.core.action.TransformActionFlags) EndNamedGoal(org.metaborg.core.action.EndNamedGoal) ITransformAction(org.metaborg.core.action.ITransformAction) IMenu(org.metaborg.core.menu.IMenu) Menu(org.metaborg.core.menu.Menu) Separator(org.metaborg.core.menu.Separator)

Example 2 with EndNamedGoal

use of org.metaborg.core.action.EndNamedGoal in project spoofax by metaborg.

the class LanguageSpecBuilder method compile.

public void compile(LanguageSpecBuildInput input) throws MetaborgException {
    logger.debug("Running pre-Java build for {}", input.languageSpec().location());
    initPluto();
    try {
        final String path = path(input);
        plutoBuild(GenerateSourcesBuilder.request(generateSourcesBuilderInput(input)), path);
    } catch (RequiredBuilderFailed e) {
        if (e.getMessage().contains("no rebuild of failing builder")) {
            throw new MetaborgException(failingRebuildMessage, e);
        } else {
            throw new MetaborgException();
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Throwable e) {
        throw new MetaborgException(e);
    }
    final SpoofaxCommonPaths paths = new SpoofaxLangSpecCommonPaths(input.languageSpec().location());
    // HACK: compile the main ESV file to make sure that packed.esv file is always available.
    final Iterable<FileObject> esvRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_ESV_NAME);
    final FileObject mainEsvFile = paths.findEsvMainFile(esvRoots);
    try {
        if (mainEsvFile != null && mainEsvFile.exists()) {
            logger.info("Compiling Main ESV file {}", mainEsvFile);
            // @formatter:off
            final BuildInput buildInput = new BuildInputBuilder(input.languageSpec()).addSource(mainEsvFile).addTransformGoal(new CompileGoal()).withMessagePrinter(new StreamMessagePrinter(sourceTextService, false, true, logger)).build(dependencyService, languagePathService);
            // @formatter:on
            final ISpoofaxBuildOutput result = runner.build(buildInput, null, null).schedule().block().result();
            if (!result.success()) {
                throw new MetaborgException("Compiling Main ESV file failed");
            }
        }
    } catch (FileSystemException e) {
        final String message = logger.format("Could not compile ESV file {}", mainEsvFile);
        throw new MetaborgException(message, e);
    } catch (InterruptedException e) {
    // Ignore
    }
    // HACK: compile the main DS file if available, after generating sources (because ds can depend on Stratego
    // strategies), to generate an interpreter.
    final Iterable<FileObject> dsRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_DYNSEM_NAME);
    final FileObject mainDsFile = paths.findDsMainFile(dsRoots, input.languageSpec().config().strategoName());
    try {
        if (mainDsFile != null && mainDsFile.exists()) {
            if (languageIdentifierService.identify(mainDsFile, input.project()) == null) {
                logger.error("Could not identify DynSem main file {}, please add DynSem as a compile dependency", mainDsFile);
            }
            logger.info("Compiling main DynSem file {}", mainDsFile);
            // @formatter:off
            final BuildInput buildInput = new BuildInputBuilder(input.languageSpec()).addSource(mainDsFile).addTransformGoal(new EndNamedGoal("Generate interpreter")).withMessagePrinter(new StreamMessagePrinter(sourceTextService, false, true, logger)).build(dependencyService, languagePathService);
            // @formatter:on
            final ISpoofaxBuildOutput result = runner.build(buildInput, null, null).schedule().block().result();
            if (!result.success()) {
                logger.error("Compiling main DynSem file {} failed", mainDsFile);
            }
        }
    } catch (FileSystemException e) {
        final String message = logger.format("Could not compile DynSem file {}", mainDsFile);
        throw new MetaborgException(message, e);
    } catch (InterruptedException e) {
    // Ignore
    }
    for (IBuildStep buildStep : buildSteps) {
        buildStep.execute(LanguageSpecBuildPhase.compile, input);
    }
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) CompileGoal(org.metaborg.core.action.CompileGoal) ISpoofaxBuildOutput(org.metaborg.spoofax.core.build.ISpoofaxBuildOutput) MetaborgException(org.metaborg.core.MetaborgException) BuildInputBuilder(org.metaborg.core.build.BuildInputBuilder) FileSystemException(org.apache.commons.vfs2.FileSystemException) BuildInput(org.metaborg.core.build.BuildInput) EndNamedGoal(org.metaborg.core.action.EndNamedGoal) RequiredBuilderFailed(build.pluto.builder.RequiredBuilderFailed) FileObject(org.apache.commons.vfs2.FileObject) SpoofaxCommonPaths(org.metaborg.spoofax.core.build.SpoofaxCommonPaths)

Aggregations

EndNamedGoal (org.metaborg.core.action.EndNamedGoal)2 RequiredBuilderFailed (build.pluto.builder.RequiredBuilderFailed)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 MetaborgException (org.metaborg.core.MetaborgException)1 CompileGoal (org.metaborg.core.action.CompileGoal)1 ITransformAction (org.metaborg.core.action.ITransformAction)1 NamedGoal (org.metaborg.core.action.NamedGoal)1 TransformActionFlags (org.metaborg.core.action.TransformActionFlags)1 BuildInput (org.metaborg.core.build.BuildInput)1 BuildInputBuilder (org.metaborg.core.build.BuildInputBuilder)1 IMenu (org.metaborg.core.menu.IMenu)1 Menu (org.metaborg.core.menu.Menu)1 MenuAction (org.metaborg.core.menu.MenuAction)1 Separator (org.metaborg.core.menu.Separator)1 StreamMessagePrinter (org.metaborg.core.messages.StreamMessagePrinter)1 ISpoofaxBuildOutput (org.metaborg.spoofax.core.build.ISpoofaxBuildOutput)1 SpoofaxCommonPaths (org.metaborg.spoofax.core.build.SpoofaxCommonPaths)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1