Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: Quasiquotation of variant option.
Example: <[ variant_option: | $("Option1" : usesite) ]>
- Loading branch information
Showing
5 changed files
with
69 additions
and
2 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
28 changes: 28 additions & 0 deletions
28
ncc/testsuite/positive/variant-option-quasiquotation-lib.n
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,28 @@ | ||
// REFERENCE: Nemerle.Compiler | ||
|
||
using Nemerle; | ||
using Nemerle.Compiler; | ||
using Nemerle.Compiler.Parsetree; | ||
|
||
namespace MacroLibrary1 | ||
{ | ||
|
||
[MacroUsage(MacroPhase.BeforeInheritance, MacroTargets.Class)] | ||
macro DefineVariantOption(tb : TypeBuilder, optionName) | ||
{ | ||
DefineVariantOptionImpl.DoTransform(tb, Macros.ImplicitCTX(), optionName) | ||
} | ||
|
||
module DefineVariantOptionImpl | ||
{ | ||
public DoTransform(tb : TypeBuilder, typer : Typer, optionName : PExpr) : void | ||
{ | ||
Macros.DefineCTX(typer); | ||
|
||
def optionNameStr = optionName.ToString(); | ||
def variantOptionBuilder = tb.DefineNestedType( | ||
<[ variant_option: | $(optionNameStr : usesite) ]>); | ||
variantOptionBuilder.Compile(); | ||
} | ||
} | ||
} |
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,26 @@ | ||
// REFERENCE: variant-option-quasiquotation-lib | ||
|
||
using System.Console; | ||
using MacroLibrary1; | ||
|
||
[DefineVariantOption(GeneratedOption1)] | ||
[DefineVariantOption(GeneratedOption2)] | ||
variant Test | ||
{ | ||
} | ||
|
||
module Program | ||
{ | ||
Main() : void | ||
{ | ||
WriteLine(Test.GeneratedOption1().GetType().Name); | ||
WriteLine(Test.GeneratedOption2().GetType().Name); | ||
} | ||
} | ||
|
||
/* | ||
BEGIN-OUTPUT | ||
GeneratedOption1 | ||
GeneratedOption2 | ||
END-OUTPUT | ||
*/ |