Permalink
Browse files

New feature: Quasiquotation of variant option.

Example: <[ variant_option: | $("Option1" : usesite) ]>
  • Loading branch information...
VladD2 committed Jul 22, 2011
1 parent 79fe562 commit 4616f4c8fc0be0d6ae8193fb59dd7f5ee6a04b90
View
@@ -21,4 +21,7 @@ misc/packages/wix/dist/
snippets/VS2010/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj.user
*.csproj.user
snippets/VS2010/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj.user
-snippets/WordToRsdnMlConverter/WordToRsdnMlConverter/Templates/Normal.dot
+snippets/WordToRsdnMlConverter/WordToRsdnMlConverter/Templates/Normal.dot
+VsIntegration/Nemerle.VisualStudio/Templates/Projects/Web/WSWebSite/Nemerle.Compiler.dll
+VsIntegration/Nemerle.VisualStudio/Templates/Projects/Web/WSWebSite/Nemerle.Macros.dll
+VsIntegration/Nemerle.VisualStudio/Templates/Projects/Web/WSWebSite/Nemerle.dll
View
@@ -50,6 +50,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
View
@@ -3263,11 +3263,20 @@ namespace Nemerle.Compiler
| "case" => SyntaxElement.MatchCase (parse_match_case ())
| "parameter" => SyntaxElement.Parameter (push ("quoted parameter", parse_parameter))
- | "decl" =>
+ | "variant_option" with isVariantOption = true
+ | "decl" with isVariantOption = false =>
def members = SCG.List();
+
+ def old_value_of_in_variant = in_variant;
+
+ when (isVariantOption)
+ in_variant = true;
ParseClassMember("decl", members);
+ when (isVariantOption)
+ in_variant = old_value_of_in_variant;
+
if (members.Count == 1)
SyntaxElement.ClassMember(members[0])
else if (members.Count > 1)
@@ -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();
+ }
+ }
+}
@@ -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
+*/

0 comments on commit 4616f4c

Please sign in to comment.