-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cfg configuration option for SDF3 placeholder pre/postfix
- Loading branch information
1 parent
203839e
commit 567a944
Showing
20 changed files
with
394 additions
and
35 deletions.
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
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
10 changes: 8 additions & 2 deletions
10
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,15 @@ | ||
package mb.sdf3.stratego; | ||
|
||
import org.metaborg.util.tuple.Tuple2; | ||
|
||
import mb.common.option.Option; | ||
|
||
public class Sdf3Context { | ||
public final String strategoQualifier; | ||
public final Option<String> strategoQualifier; | ||
public final Option<Tuple2<String, String>> placeholders; | ||
|
||
public Sdf3Context(String strategoQualifier) { | ||
public Sdf3Context(Option<String> strategoQualifier, Option<Tuple2<String, String>> placeholders) { | ||
this.strategoQualifier = strategoQualifier; | ||
this.placeholders = placeholders; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
lwb/metalang/sdf3/sdf3/src/main/java/mb/sdf3/stratego/Sdf3PlaceholderCharsPrimitive.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,37 @@ | ||
package mb.sdf3.stratego; | ||
|
||
import java.util.Objects; | ||
|
||
import org.metaborg.util.tuple.Tuple2; | ||
import org.spoofax.interpreter.core.IContext; | ||
import org.spoofax.interpreter.core.InterpreterException; | ||
import org.spoofax.interpreter.library.AbstractPrimitive; | ||
import org.spoofax.interpreter.stratego.Strategy; | ||
import org.spoofax.interpreter.terms.IStrategoTerm; | ||
import org.spoofax.interpreter.terms.ITermFactory; | ||
|
||
import mb.common.option.Option; | ||
import mb.stratego.common.AdaptException; | ||
import mb.stratego.common.AdaptableContext; | ||
|
||
public class Sdf3PlaceholderCharsPrimitive extends AbstractPrimitive { | ||
public Sdf3PlaceholderCharsPrimitive() { | ||
super("SSL_EXT_placeholder_chars", 0, 0); | ||
} | ||
|
||
@Override public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException { | ||
try { | ||
final Sdf3Context context = AdaptableContext.adaptContextObject(env.contextObject(), Sdf3Context.class); | ||
final Option<Tuple2<String, String>> placeholders = context.placeholders; | ||
if(placeholders.isNone()) { | ||
return false; | ||
} | ||
final Tuple2<String, String> placeholderChars = Objects.requireNonNull(placeholders.get()); | ||
final ITermFactory f = env.getFactory(); | ||
env.setCurrent(f.makeTuple(f.makeString(placeholderChars._1()), f.makeString(placeholderChars._2()))); | ||
return true; | ||
} catch(AdaptException e) { | ||
return false; // Context not available; fail | ||
} | ||
} | ||
} |
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
Oops, something went wrong.