Skip to content

Instantly share code, notes, and snippets.

@Ziaw
Created August 5, 2011 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ziaw/1127024 to your computer and use it in GitHub Desktop.
Save Ziaw/1127024 to your computer and use it in GitHub Desktop.
using Nemerle;
using Nemerle.Collections;
using Nemerle.Compiler;
using Nemerle.Compiler.Parsetree;
using Nemerle.Text;
using Nemerle.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
namespace NUnitDSL
{
[Nemerle.MacroUsage(Nemerle.MacroPhase.BeforeInheritance,
Nemerle.MacroTargets.Method)]
public macro TestCase(type_builder : TypeBuilder, _method : ParsedMethod, token : Token)
syntax("testcase", token)
{
TestCaseImpl.TestCase(type_builder, token);
}
module TestCaseImpl
{
public TestCase(tb : TypeBuilder, token : Token) : void
{
def (name, body) = match (token.NToList())
{
| [name, body] => (name.ToString(), body);
| _ => Message.FatalError("invalid syntax");
}
def (bodyExpr, _) = MainParser.ParseExpr(tb.GlobalEnv, Token.LooseGroup(body.Location, body));
def bodyExpr = Util.locate(body.Location, <[ $bodyExpr ]>);
Util.locate(token.Location, tb.Define(<[decl: public $(name : usesite)() : void { $bodyExpr }]>));
tb.Compile();
}
}
}
public class Test
{
testcase Test
{
Console.WriteLine("1");
Console.WriteLine("1");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment