Macro: Including an annotation?

8 views
Skip to first unread message

Robert Fischer

unread,
Apr 17, 2011, 4:13:10 PM4/17/11
to The Mirah Programming Language
In the following code, I get an error if I include the annotation.

This compiles fine:
defmacro test(name,&block) do
quote {
#$org.junit.Test
def `name`:void
`block.body`
end
}
end

If you uncomment the annotation, it dies with the message:

Execution failed for task ':ashlar-dist:compileTestMirah'.
Cause: jmeta.SyntaxError: expected terms before ' {' (at line: 32,
char: 8)

(Line 32 is the "quote {" line.)

Changing it to "macro def" instead of "defmacro" doesn't change
anything.

Any idea how to get around that? I'm really looking forward to using
Mirah for my test cases, but since I'm using JUnit 4, the annotations
are pretty much mandatory.

~~ Robert.

Robert Fischer

unread,
Apr 18, 2011, 11:40:34 AM4/18/11
to The Mirah Programming Language
Here's a minimal example:

============================
macro def foo
quote {
$javax.annotation.Generated
def bar
end
}
end

foo
============================

Speaking of which, is there a JIRA or something kicking around?

~~ Robert.

Rib Rdb

unread,
Apr 18, 2011, 12:58:47 PM4/18/11
to mi...@googlegroups.com

I suspect the parser thinks you're creating a hash. What if you use quote do ... end?

The issue tracker is at code.google.com/p/mirah

-- Sent from my phone

Robert Fischer

unread,
Apr 18, 2011, 6:41:28 PM4/18/11
to mi...@googlegroups.com
Tried that. No dice. Here's the specifics.

# test.mirah
macro def foo
quote do


$javax.annotation.Generated
def bar
end
end

end

# Results
Parsing...
test.mirah
Exception in thread "main" mirah/impl/Mirah.mirah:4443:in `do_block':
jmeta.SyntaxError: expected statement before ' $javax.anno' (at line:
3, char: 1) (NativeException)
from mirah/impl/Mirah.mirah:4389:in `brace_block'
from mirah/impl/Mirah.mirah:3558:in `primary2_id'
from mirah/impl/Mirah.mirah:2359:in `primary2'
from mirah/impl/Mirah.mirah:1757:in `primary'
from mirah/impl/Mirah.mirah:7105:in `lhs2'
from mirah/impl/Mirah.mirah:7068:in `lhs'
from mirah/impl/Mirah.mirah:1061:in `statement2'
from mirah/impl/Mirah.mirah:681:in `statement'

No difference if it's macro def or defmacro.

~~ Robert.

Rib Rdb

unread,
Apr 20, 2011, 1:45:24 PM4/20/11
to mi...@googlegroups.com
hmm.  You need to use :: rather than dots for a fully qualified name. But I don't know if annotations work with fully qualified names.

This might work:
 $javax::annotation::Generated

If not, maybe this:

quote do
  import javax.annotation.Generated
  $Generated
  def bar
  ...

Robert Fischer

unread,
Apr 20, 2011, 3:38:56 PM4/20/11
to mi...@googlegroups.com
I'll give it a shot when I get home, but I seem to recall it not
working when I had the import at the top level (e.g. as the first line
of the file), even if I added the import both to the top level of the
file defining the macro and to the top level of the file using the
macro.

~~ Robert.

Rib Rdb

unread,
Apr 20, 2011, 5:20:51 PM4/20/11
to mi...@googlegroups.com
I think it should work if the import is at the top of the file using the macro, or if the import is inside the macro.

Robert Fischer

unread,
Apr 21, 2011, 7:49:58 AM4/21/11
to mi...@googlegroups.com
The explicit naming of the annotation didn't work, but putting the
import within the macro did.

# test.mirah
macro def foo
quote do

import javax.annotation.Generated
$Generated
def bar

end
end
end

Thanks for helping me sort this out!

~~ Robert.

Reply all
Reply to author
Forward
0 new messages