Macro: how to display context info in REPL?

138 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Léonard Schneider

ungelesen,
15.11.2012, 10:35:4615.11.12
an scala...@googlegroups.com
Hi,

Anyone knows what option to pass to scala REPL for displaying macro context info? I set force to false when calling context info. It displays with -verbose option, but then it is sunk into a lot REPL debug info which I dont need. I tried -Xmacro-settings:force=true, but nothing happens.

Best regards,


Leo

Eugene Burmako

ungelesen,
15.11.2012, 12:50:1015.11.12
an scala-user
What do you mean by context info? Could you provide more details?

On Nov 15, 4:35 pm, Léonard Schneider <leonard.schnei...@gmail.com>
wrote:

Léonard Schneider

ungelesen,
15.11.2012, 13:06:1415.11.12
an scala...@googlegroups.com
I mean using the info method of the macro Context, like:

scala> :pas
// Entering paste mode (ctrl-D to finish)
def test = macro testImpl
def testImpl(c: Context) = {
c.info(c.enclosingPosition, "Info here", false)
c.literal("Output")
}
// Exiting paste mode, now interpreting.
test: String
testImpl: (c: scala.reflect.macros.Context)c.Expr[String]
scala> test
res0: String = Output

The only way I've found to get it to print something in REPL is to call it with the -verbose option but then I have too much info. I'd like to be able to activate only macro related debug info with a switch. -Ymacro-debug-lite and -Ymacro-debug-verbose does not force display info either. So I must miss something.

Eugene Burmako

ungelesen,
16.11.2012, 05:42:2716.11.12
an scala-user
Looks like force=true does the trick. Otherwise it's only -verbose.

11:41 ~/Projects/Kepler (2.10.x)$ scala
Welcome to Scala version 2.10.1-20121112-131306-1a6c859710 (Java
HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def impl(c: Context) = { c.info(c.universe.NoPosition, "hello",
force = true); c.literalUnit }
impl: (c: scala.reflect.macros.Context)c.Expr[Unit]

scala> def foo = macro impl
foo: Unit

scala> foo
hello

On Nov 15, 7:06 pm, Léonard Schneider <leonard.schnei...@gmail.com>
wrote:

Daniel Sobral

ungelesen,
16.11.2012, 06:54:4516.11.12
an Eugene Burmako, scala-user
That's what's documented.
--
Daniel C. Sobral

I travel to the future all the time.

Léonard Schneider

ungelesen,
16.11.2012, 07:56:5016.11.12
an scala...@googlegroups.com, Eugene Burmako
Thanks. Yes, I read the doc. I thought somehow that the force parameter could passed through a command line option. That would have been neat.

Léonard Schneider

ungelesen,
16.11.2012, 09:02:2916.11.12
an scala...@googlegroups.com, Eugene Burmako
OK. No big deal. I'm now using c.Info with force=System.getProperty("force", "false").toBoolean

Then when I want to debug from SBT, before launching the console command, I just type eval System.setProperty("force", "true")

I'm all set :))
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten