reflection - Access code file and line number from Scala macro? -
How can I get the name of the code file and the line number in Scala macro? I saw and it says that it can be easily implemented using macros ...
EDIT: To clarify, I want the caller's code file and line number I already have Is the same one and I want to modify it to print the line number and file name, whichever is the You should be Example string interpolator with macro, debug
c.macroApplication.pos , where
c is
context . For example, if your macro has
F "% p: $
c.enclosingPosition finds the adjacent macro in which the position is searched (see other answers.) Msg ", but if the situation does not specify, the
F macro will be positionless.
F "% p" :
/ * Convert extended conversions in some formats like it . *% C for quote,% p for position,% pf for file,% pn line number, *% p% column% p offset. * / Private def downConvert (parts: list [tree]): list [tree] = {df fix up (t: tree): tree = {val little (constant (s: string)) = t wall r = "(? End Lieutenant;;%)% (P | Q | PF | P.O. | PN | PC) | RRPP = CMCROAP Application.Po DF F (M: Match): String = M Group 1 Match {Case "P" = & gt; P.toString Case "PF" => P.source.file.name Case "Poe" = & gt; P.point.toString Case "Pn" => P.line.toString Case " PC "= & gt; P.column.toString Case" Q "= & gt;" \ ""} Val z = r.replaceAllIn (s, f _) Literal (continuous (z)) // setPos t.pos} Fixing the parts map}
Comments
Post a Comment