-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Pass file/column/line information to custom string literals (#9577) #9579
Conversation
Alternatively it occurs to me, we could pass a LineNumberNode as the second argument. That would feel more macro-y. |
This relies on JuliaLang/julia#9579, but should be easy to adapt to whatever final solution is adopted. As a nice side effect, we now also get proper source locations for C++ code :): In the REPL: ``` C++ > foobar a; In file included from :1: REPL:1:1: error: unknown type name 'foobar' foobar a; ^ ``` Or in a file ``` shell> cat test.jl cxx""" foobar a; """ julia> include("test.jl") /Users/kfischer/.julia/Cxx/test/test.jl:2:1: error: unknown type name 'foobar' foobar a; ^ ```
@JeffBezanson I'm still very interested in getting location information for my string macros. Any new ideas as to the best way to do that? |
It seems like having a mandatory additional StringLiteralInfo argument that includes all of this as a single object might be easier and allow for more info to be added without breaking code in the future. |
Yes, that would be nice to have. |
Does it need to be a mandatory argument (which would break all current string macros)? |
String macros can't have optional arguments, so it either needs to be mandatory (though it's generally possible to do define the macros in a backwards compatible way) or some more fancy mechanism needs to be used. I suppose it would be possible to do this for all macros, though I haven't found any use for it yet. I worry that exposing too much scope information would open the door to macros that are extremely context sensitive. Right now, macros nicely only operate on the syntax they are passed. I'm sure @JeffBezanson has strong opinions here. |
@Keno What I've suggested is no different that C/C++ code being able to use |
I'm fine with line and file that seems useful, I have a problem with |
@Keno Those are very useful (necessary?) if you want to try to associate documentation with particular fields within a type, for example. What are you concerned about in particular with having the extra information? |
Related: Laurence Tratt's recent post about "Debugging Layers" in Converge (h/t @jakebolewski). |
i think this has been resolved (via introduction of |
This is not resolved. |
Rebased as jn/kf-linecolstr. But need to fix the column numbers for macros to point at the the first symbol of the first argument for this to be useful for its original purpose. (currently, it tries to describe the |
This is one possible way to handle #9577, but I'm not sure if it's ideal, because it forces people to declare the arguments to every
_str
macro even if they have no intention of doing anything with it. The other alternative I mentioned in #9577 is to save this information in a global variable that can be retrieved through a function call. That alternative seems more hacky though as it adds new global state and I'm not sure what would happen with quoted string literals. Alternative thoughts appreciated.