English 中文(简体)
How to create nested macro in Boo
原标题:
  • 时间:2010-01-29 14:16:49
  •  标签:
  • boo

I am creating nested macros in Boo, I wrote this program:

macro text:
  macro subMacro:
    text["Text"] = "Hello World"

  return [|
    block:  
      System.Console.WriteLine( "Hello World" );
  |]

But I am getting the error "Unknown Identifer: text " in the 3rd line of the code.

问题回答

The error you are getting is likely to do with a missing import in the code where the macro is being called from.

If your macro is in a namespace named foo for example, you will need to add

import foo

At the top of the calling code.

A second issue you may run into once you fix this compiler issue is the error

"Unknown identifier block (BCE0005)

To fix this, add a .Body after the quasi-quotation section like this:

import Boo.Lang.Compiler.Ast

macro text:
    macro subMacro:
        text["Text"] = "Hello world"

    return [|
        block:
            System.Console.WriteLine("Hello World");
    |].Body

EDIT - IMHO macros are a bit of a dark art. For more help, you should try the boo mailing list, or the excellent DSLs in BOO





相关问题
How stable and mature is Boo?

I had a look at Boo and it looks pretty awesome! I m just curious about how stable it is at this stage? I mean, would you consider using it in real live production code?

How to create nested macro in Boo

I am creating nested macros in Boo, I wrote this program: macro text: macro subMacro: text["Text"] = "Hello World" return [| block: System.Console.WriteLine( "Hello World" ); |]...

Boo: Explicitly specifying the type of a hash

I am new to Boo, and trying to figure out how to declare the type of a hash. When I do: myHash = {} myHash[key] = value (later) myHash[key].method() the compiler complains that "method ...

Is it possible to save a dynamic assembly to disk?

I recently bought Ayende s book Building DSLs in Boo (buy it, read it, it s awesome) but I m coming up against an implementation problem and I want to see what the generated code looks like. I would ...

Is WSA compiler in Boo safe to use?

In our program we use boo as macro system about 2 years. All works like a charm, but python syntax is weird for newcomers. As I know boo has white space agnostic (WSA) compiler with ruby like syntax: ...

Boo - Excel Automation, trouble selecting ranges

I m investigating Boo and thought it would be a useful exercise to try converting a couple of venerable VB Scripts that automate Excel (2007, in this instance). A lot of things seem to translate very ...

热门标签