Hi all,
I am coming from a c# world and i am confused by the lack of "new" keyword.
I would like to define a "new" macro that will offer additional functionality, for example: new IMyInterface() => meaning : use some IOC to find an implementation of IMyInterface.
1) A problem is that "new" is reserved keyword and i cannot define a macro for it.
But even if i use another name, "New" for example, the macro compiles ok, but the use of it fails:
/out:obj\Debug\CodeGenMacrosTests.dll
F:\Projects\NemerleTests\ConsoleApplication1\CodeGenMacrosTests\Tests.n(19,29): error : parse error near `(...)' group: unexpected end of token sequence
F:\Projects\NemerleTests\ConsoleApplication1\CodeGenMacrosTests\Tests.n(19,29): error : parse error near separator or closing bracket: expecting `(' and some tokens inside
F:\Projects\NemerleTests\ConsoleApplication1\CodeGenMacrosTests\Tests.n(19,19): error : unable to parse syntax rule, stopped at: )
Done building project "CodeGenMacrosTests.nproj" -- FAILED.
namespace CSharp
{
macro New(typeName : PExpr)
// See:
http://nemerle.org/wiki/Macros_tutorial#Adding_new_syntax_to_the_compiler and
http://nemerle.org/wiki/Syntax_extensions
syntax ("New", typeName, "(",")")
{
Macro1Impl.DoTransform(Macros.ImplicitCTX(), typeName)
}
module Macro1Impl
{
public DoTransform(typer : Typer, typeName : PExpr) : PExpr
{
Macros.DefineCTX(typer);
<[ $typeName() ]>
}
}
}
USAGE:
module TestNew
{
TestNew() : void
{
def a = New object();// <= ERROR IS HERE BEFORE ()
}
}
What am i doing wrong?
Thank you