Skip to content

Commit

Permalink
allow methodless macros #22098 (fcards work) (#24171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 authored and JeffBezanson committed Oct 17, 2017
1 parent 361ceb0 commit 26c7ecb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ function docm(source::LineNumberNode, mod::Module, meta, ex, define = true)
# f(...)
#
isexpr(x, FUNC_HEADS) && is_signature(x.args[1]) ? objectdoc(source, mod, meta, def, x, signature(x)) :
isexpr(x, :function) && !isexpr(x.args[1], :call) ? objectdoc(source, mod, meta, def, x) :
isexpr(x, [:function, :macro]) && !isexpr(x.args[1], :call) ? objectdoc(source, mod, meta, def, x) :
isexpr(x, :call) ? calldoc(source, mod, meta, x) :

# Type definitions.
Expand Down
6 changes: 3 additions & 3 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1406,11 +1406,11 @@
((function macro)
(let* ((paren (eqv? (require-token s) #\())
(sig (parse-def s (not (eq? word 'macro)))))
(if (and (eq? word 'function) (not paren) (symbol-or-interpolate? sig))
(if (and (not paren) (symbol-or-interpolate? sig))
(begin (if (not (eq? (require-token s) 'end))
(error (string "expected \"end\" in definition of function \"" sig "\"")))
(error (string "expected \"end\" in definition of " word " \"" sig "\"")))
(take-token s)
`(function ,sig))
`(,word ,sig))
(let* ((usig (unwrap-where sig))
(def (if (or (valid-1arg-func-sig? usig)
(and (assignment? usig)
Expand Down
2 changes: 2 additions & 0 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@
v))
anames))
,@(cddr e)))))
((and (length= e 2) (symbol? (cadr e)))
(expand-forms `(function ,(symbol (string #\@ (cadr e))))))
(else
(error "invalid macro definition"))))

Expand Down
5 changes: 5 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5816,3 +5816,8 @@ function hh6614()
x, y
end
@test hh6614() == (1, 2)

# issue 22098
macro m22098 end
handle_on_m22098 = getfield(@__MODULE__, Symbol("@m22098"))
@test isempty(methods(handle_on_m22098))
5 changes: 5 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1066,3 +1066,8 @@ end
end
@test Main.f23011() == 2
@test docstrings_equal(@doc(Main.f23011), doc"second")

# issue 22098
"an empty macro"
macro mdoc22098 end
@test docstrings_equal(@doc(:@mdoc22098), doc"an empty macro")

0 comments on commit 26c7ecb

Please sign in to comment.