Skip to content

Commit

Permalink
Implement __LINE__ and __FILE__ magic macros
Browse files Browse the repository at this point in the history
Fixes #8066
  • Loading branch information
ihnorton committed Aug 21, 2015
1 parent e0b4510 commit 5e43774
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
7 changes: 0 additions & 7 deletions base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9531,13 +9531,6 @@ Returns an iterator over substrings of `s` that correspond to the extended graph
"""
graphemes

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__

doc"""
charwidth(c)
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,6 @@ export

# Macros
# parser internal
@__FILE__,
@int128_str,
@uint128_str,
@big_str,
Expand Down
2 changes: 0 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ function source_dir()
p === nothing ? p : dirname(p)
end

macro __FILE__() source_path() end

function include_from_node1(_path::AbstractString)
path, prev = _include_dependency(_path)
tls = task_local_storage()
Expand Down
14 changes: 9 additions & 5 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2039,14 +2039,18 @@
(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)))
((eqv? head '__FILE__) `(call string (quote ,current-filename)))
((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

0 comments on commit 5e43774

Please sign in to comment.