-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom placeholders #107
Open
Virtlink
wants to merge
11
commits into
develop
Choose a base branch
from
custom-placeholders
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+709
−187
Open
Custom placeholders #107
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d50f41
Add placeholder config option
Virtlink 86dc296
Extend and use Sdf3Context object
Virtlink 25981e9
Use Sdf3SpecConfig object
Virtlink dd728b9
Add SSL_EXT_placeholder_chars primitive
Virtlink a706ce4
Add Sdf3Config object
Virtlink a2e9071
Use Sdf3Config object
Virtlink 7ad3439
Abstract Sdf3 tranformation tasks
Virtlink f9f1409
Attempt to refactor Sdf3ToNormalForm
Virtlink f378300
Reimplement Sdf3ShowNormalForm
Virtlink 909b60a
Thread Sdf3Config
Virtlink 4072554
Merge branch 'develop' into custom-placeholders
Virtlink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Abstract Sdf3 tranformation tasks
commit 7ad3439be32865417e9ed151339321139fd55fcd
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
lwb/metalang/sdf3/sdf3/src/main/java/mb/sdf3/task/Sdf3AstStrategoTransformTaskDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package mb.sdf3.task; | ||
|
||
import mb.common.result.Result; | ||
import mb.pie.api.ExecContext; | ||
import mb.pie.api.Interactivity; | ||
import mb.pie.api.Supplier; | ||
import mb.pie.api.TaskDef; | ||
import mb.sdf3.Sdf3Scope; | ||
import mb.sdf3.stratego.Sdf3Context; | ||
import mb.sdf3.task.spec.Sdf3Config; | ||
import mb.stratego.common.StrategoException; | ||
import mb.stratego.common.StrategoRuntime; | ||
import mb.stratego.pie.AstStrategoTransformTaskDef; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.spoofax.interpreter.terms.IStrategoTerm; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* Abstract task definition similar to {@link AstStrategoTransformTaskDef} | ||
* but injects a {@link Sdf3Context} into the {@link StrategoRuntime}. | ||
*/ | ||
public abstract class Sdf3AstStrategoTransformTaskDef<I extends Sdf3AstStrategoTransformTaskDef.Input> implements TaskDef<I, Result<IStrategoTerm, ?>> { | ||
public /* open */ static class Input implements Serializable { | ||
public final Supplier<? extends Result<IStrategoTerm, ?>> astSupplier; | ||
public final String strategyAffix; | ||
public final Sdf3Config sdf3Config; | ||
|
||
public Input( | ||
Supplier<? extends Result<IStrategoTerm, ?>> astSupplier, | ||
String strategyAffix, | ||
Sdf3Config sdf3Config | ||
) { | ||
this.astSupplier = astSupplier; | ||
this.strategyAffix = strategyAffix; | ||
this.sdf3Config = sdf3Config; | ||
} | ||
|
||
@Override public boolean equals(@Nullable Object o) { | ||
if(this == o) return true; | ||
if(o == null || getClass() != o.getClass()) return false; | ||
final Input input = (Input)o; | ||
return astSupplier.equals(input.astSupplier) | ||
&& strategyAffix.equals(input.strategyAffix) | ||
&& sdf3Config.equals(input.sdf3Config); | ||
} | ||
|
||
@Override public int hashCode() { | ||
return Objects.hash(astSupplier, strategyAffix, sdf3Config); | ||
} | ||
|
||
@Override public String toString() { | ||
return "Sdf3AstStrategoTransformTaskDef$Input{" + | ||
"astSupplier=" + astSupplier + | ||
", strategyAffix='" + strategyAffix + '\'' + | ||
", sdf3Config=" + sdf3Config + | ||
'}'; | ||
} | ||
} | ||
|
||
private final Provider<StrategoRuntime> strategoRuntimeProvider; | ||
|
||
protected Sdf3AstStrategoTransformTaskDef(Provider<StrategoRuntime> strategoRuntimeProvider) { | ||
this.strategoRuntimeProvider = strategoRuntimeProvider; | ||
} | ||
|
||
@Override public Result<IStrategoTerm, ?> exec(ExecContext context, I input) throws Exception { | ||
final Sdf3Context sdf3Context = new Sdf3Context( | ||
input.strategyAffix, | ||
input.sdf3Config.placeholderPrefix, | ||
input.sdf3Config.placeholderSuffix | ||
); | ||
final StrategoRuntime strategoRuntime = strategoRuntimeProvider.get().addContextObject(sdf3Context); | ||
return context.require(input.astSupplier).flatMapOrElse((ast) -> { | ||
try { | ||
ast = doExec(context, input, strategoRuntime, ast); | ||
return Result.ofOk(ast); | ||
} catch(Exception e) { | ||
return Result.ofErr(e); | ||
} | ||
}, Result::ofErr); | ||
} | ||
|
||
protected abstract IStrategoTerm doExec(ExecContext context, I input, StrategoRuntime strategoRuntime, IStrategoTerm ast) throws StrategoException, Exception; | ||
} |
70 changes: 5 additions & 65 deletions
70
lwb/metalang/sdf3/sdf3/src/main/java/mb/sdf3/task/Sdf3ToPrettyPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching all
Exception
s is bad practice, as it also catches allRuntimeException
s indicating bugs such asNullPointerException
which should just crash the build, as well as catchingInterruptedException
s which should cancel the build, etc.