-
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.
Open
Custom placeholders #107
Changes from all commits
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
There are no files selected for viewing
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
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
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
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
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
48 changes: 46 additions & 2 deletions
48
lwb/metalang/sdf3/sdf3/src/main/java/mb/sdf3/stratego/Sdf3Context.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 |
---|---|---|
@@ -1,9 +1,53 @@ | ||
package mb.sdf3.stratego; | ||
|
||
public class Sdf3Context { | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* SDF3 context. | ||
* | ||
* Add this context to a Stratego context using {@link mb.stratego.common.StrategoRuntime#addContextObject}. | ||
*/ | ||
public final class Sdf3Context implements Serializable { | ||
/** The language specification name as a Stratego qualifier. */ | ||
public final String strategoQualifier; | ||
/** The prefix for placeholders; or {@code null} to use the default. */ | ||
public final String placeholderPrefix; | ||
/** The suffix for placeholders; or {@code null} to use the default. */ | ||
public final String placeholderSuffix; | ||
|
||
public Sdf3Context(String strategoQualifier) { | ||
public Sdf3Context( | ||
String strategoQualifier, | ||
String placeholderPrefix, | ||
String placeholderSuffix | ||
) { | ||
this.strategoQualifier = strategoQualifier; | ||
this.placeholderPrefix = placeholderPrefix; | ||
this.placeholderSuffix = placeholderSuffix; | ||
} | ||
|
||
@Override public boolean equals(Object o) { | ||
if(this == o) return true; | ||
if(o == null || getClass() != o.getClass()) return false; | ||
Sdf3Context that = (Sdf3Context)o; | ||
return strategoQualifier.equals(that.strategoQualifier) | ||
&& placeholderPrefix.equals(that.placeholderPrefix) | ||
&& placeholderSuffix.equals(that.placeholderSuffix); | ||
} | ||
|
||
@Override public int hashCode() { | ||
return Objects.hash( | ||
strategoQualifier, | ||
placeholderPrefix, | ||
placeholderSuffix | ||
); | ||
} | ||
|
||
@Override public String toString() { | ||
return "Sdf3Context{" + | ||
"strategoQualifier='" + strategoQualifier + '\'' + | ||
", placeholderPrefix='" + placeholderPrefix + '\'' + | ||
", placeholderSuffix='" + placeholderSuffix + '\'' + | ||
'}'; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...etalang/sdf3/sdf3/src/main/java/mb/sdf3/stratego/Sdf3SslExtPlaceholderCharsPrimitive.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,33 @@ | ||
package mb.sdf3.stratego; | ||
|
||
import org.spoofax.interpreter.library.AbstractPrimitive; | ||
import mb.stratego.common.AdaptableContext; | ||
import org.spoofax.interpreter.core.IContext; | ||
import org.spoofax.interpreter.core.InterpreterException; | ||
import org.spoofax.interpreter.stratego.Strategy; | ||
import org.spoofax.interpreter.terms.IStrategoTerm; | ||
import org.spoofax.interpreter.terms.ITermFactory; | ||
|
||
/** | ||
* Returns a tuple with the prefix and suffix, respectively, to use to parse/pretty-print placeholders. | ||
*/ | ||
public final class Sdf3SslExtPlaceholderCharsPrimitive extends AbstractPrimitive { | ||
|
||
public Sdf3SslExtPlaceholderCharsPrimitive() { | ||
super("SSL_EXT_placeholder_chars", 0, 0); | ||
} | ||
|
||
@Override public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException { | ||
final ITermFactory factory = env.getFactory(); | ||
try { | ||
final Sdf3Context context = AdaptableContext.adaptContextObject(env.contextObject(), Sdf3Context.class); | ||
env.setCurrent(factory.makeTuple( | ||
factory.makeString(context.placeholderPrefix), | ||
factory.makeString(context.placeholderSuffix) | ||
)); | ||
return true; | ||
} catch(RuntimeException e) { | ||
return false; // Context not available; fail | ||
} | ||
} | ||
} |
Oops, something went wrong.
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
RuntimeException
s is bad practice, as it catches all kinds of exceptions indicating bugs such asNullPointerException
. This will silently hide them, which is very bad.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.
This was based on your own code for
Sdf3PpLanguageSpecNamePrimitive
.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.
Then that code should be changed as well. I think it should catch
AdaptException
instead.