Skip to content
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: Implement @__LINE__ macro #12727

Merged
merged 1 commit into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ New language features
Default continues to be of length 1 ([#12385]).
See http:https://docs.julialang.org/en/latest/manual/parallel-computing/#remoterefs-and-abstractchannels for details.

* `@__LINE__` special macro now available to reflect invocation source line number ([#12727]).

Language changes
----------------
Expand Down
16 changes: 13 additions & 3 deletions base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Base.LinAlg.BLAS

import .Docs: keywords

doc"""
ger!(alpha, x, y, A)

Expand Down Expand Up @@ -9537,12 +9539,20 @@ Returns an iterator over substrings of `s` that correspond to the extended graph
"""
graphemes

doc"""
keywords[symbol("@__FILE__")] = doc"""

@__FILE__() -> AbstractString

`@__FILE__` expands to a string with the absolute path and file name of the script being run. Returns `nothing` if run from a REPL or an empty string if evaluated by `julia -e <expr>`.
`@__FILE__` expands to a string with the absolute path and file name of the script being run.
Returns `"none"` if run from a REPL or command-line context.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this actually change from nothing to "none" here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihnorton can you confirm? Just tried it and this looks wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was left from the proposed change. I'll fix the doc.
On Aug 28, 2015 7:35 PM, "Tony Kelman" [email protected] wrote:

In base/docs/helpdb.jl
#12727 (comment):

 @__FILE__() -> AbstractString

-@__FILE__ expands to a string with the absolute path and file name of the script being run. Returns nothing if run from a REPL or an empty string if evaluated by julia -e <expr>.
+@__FILE__ expands to a string with the absolute path and file name of the script being run.
+Returns "none" if run from a REPL or command-line context.

@ihnorton https://github.com/ihnorton can you confirm? Just tried it
and this looks wrong.


Reply to this email directly or view it on GitHub
https://github.com/JuliaLang/julia/pull/12727/files#r38254310.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8fb7046 (on the docfix branch)

"""

keywords[symbol("@__LINE__")] = doc"""

@__LINE__() -> Int

`@__LINE__` expands to the line number of the call-site.
"""
:@__FILE__

doc"""
charwidth(c)
Expand Down
13 changes: 8 additions & 5 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2039,14 +2039,17 @@
(with-space-sensitive
(let* ((head (parse-unary-prefix s))
(t (peek-token s)))
(if (ts:space? s)
(cond
((eqv? head '__LINE__) (input-port-line (ts:port s)))
((ts:space? s)
`(macrocall ,(macroify-name head)
,@(parse-space-separated-exprs s))
(let ((call (parse-call-chain s head #t)))
(if (and (pair? call) (eq? (car call) 'call))
,@(parse-space-separated-exprs s)))
(else
(let ((call (parse-call-chain s head #t)))
(if (and (pair? call) (eq? (car call) 'call))
`(macrocall ,(macroify-name (cadr call)) ,@(cddr call))
`(macrocall ,(macroify-name call)
,@(parse-space-separated-exprs s))))))))
,@(parse-space-separated-exprs s)))))))))

;; command syntax
((eqv? t #\`)
Expand Down
2 changes: 2 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using Base.Test

@test @__LINE__ == 5

include("test_sourcepath.jl")
thefname = "the fname!//\\&\0\1*"
@test include_string("include_string_test() = @__FILE__", thefname)() == Base.source_path()
Expand Down