diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index a51c0d9f046d7..220181f9ba2db 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -2364,15 +2364,6 @@ in the requested `mime` format and simply returns `x`. """ reprmime -""" - @__FILE__ -> AbstractString - -`@__FILE__` expands to a string with the absolute file path of the file containing the -macro. Returns `nothing` if run from a REPL or an empty string if evaluated by -`julia -e `. Alternatively see [`PROGRAM_FILE`](:data:`PROGRAM_FILE`). -""" -:@__FILE__ - """ !(x) diff --git a/base/exports.jl b/base/exports.jl index ab7793502741c..e30494ed191a2 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1328,6 +1328,7 @@ export # Macros # parser internal @__FILE__, + @__DIR__, @int128_str, @uint128_str, @big_str, diff --git a/base/loading.jl b/base/loading.jl index 5034824e6a187..592cbfe19a4c5 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -494,8 +494,24 @@ function source_dir() p === nothing ? p : dirname(p) end +""" + @__FILE__ -> AbstractString + +`@__FILE__` expands to a string with the absolute file path of the file containing the +macro. Returns `nothing` if run from a REPL or an empty string if evaluated by +`julia -e `. Alternatively see [`PROGRAM_FILE`](:data:`PROGRAM_FILE`). +""" macro __FILE__() source_path() end +""" + @__DIR__ -> AbstractString + +`@__DIR__` expands to a string with the directory part of the absolute path of the file +containing the macro. Returns `nothing` if run from a REPL or an empty string if +evaluated by `julia -e `. +""" +macro __DIR__() source_dir() end + """ include(path::AbstractString) diff --git a/doc/manual/packages.rst b/doc/manual/packages.rst index eeb4ff147fb5f..dc0cc9d86cca9 100644 --- a/doc/manual/packages.rst +++ b/doc/manual/packages.rst @@ -771,6 +771,16 @@ testing service, and an ``appveyor.yml`` file for using `AppVeyor ``\ . Alternatively see :data:`PROGRAM_FILE`\ . +.. function:: @__DIR__ -> AbstractString + + .. Docstring generated from Julia source + + ``@__DIR__`` expands to a string with the directory part of the absolute path of the file containing the macro. Returns ``nothing`` if run from a REPL or an empty string if evaluated by ``julia -e ``\ . + .. function:: @__LINE__ -> Int .. Docstring generated from Julia source diff --git a/test/loading.jl b/test/loading.jl index 8d40b2c16981c..f876b21def25a 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -11,6 +11,9 @@ thefname = "the fname!//\\&\1*" @test basename(@__FILE__) == "loading.jl" @test isabspath(@__FILE__) +@test isdir(@__DIR__) +@test @__DIR__() == dirname(@__FILE__) + # Issue #5789 and PR #13542: let true_filename = "cAsEtEsT.jl", lowered_filename="casetest.jl" touch(true_filename)