Skip to content

Commit

Permalink
Allow returntype and where annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Jul 8, 2024
1 parent 8abd102 commit dabbc1d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1154,20 +1154,20 @@
(parse-atom s))))

(define (parse-def s is-func anon)
(let ((ex (parse-unary-prefix s)))
(if (and (pair? ex) (eq? (car ex) 'macrocall))
ex
(let* ((sig (if (or (and is-func (reserved-word? ex)) (initial-reserved-word? ex))
(error (string "invalid name \"" ex "\""))
(parse-call-chain s ex #f)))
(decl-sig
(if (and is-func (eq? (peek-token s) '|::|))
(begin (take-token s)
`(|::| ,sig ,(parse-call s)))
sig)))
(if (eq? (peek-token s) 'where)
(parse-where-chain s decl-sig)
decl-sig)))))
(let* ((ex (parse-unary-prefix s))
(sig
(if (and (pair? ex) (eq? (car ex) 'macrocall)) ex
(if (or (and is-func (reserved-word? ex)) (initial-reserved-word? ex))
(error (string "invalid name \"" ex "\""))
(parse-call-chain s ex #f))))
(decl-sig
(if (and is-func (eq? (peek-token s) '|::|))
(begin (take-token s)
`(|::| ,sig ,(parse-call s)))
sig)))
(if (eq? (peek-token s) 'where)
(parse-where-chain s decl-sig)
decl-sig)))

(define (disallowed-space-error lno ex t)
(error (string "space before \"" t "\" not allowed in \""
Expand Down Expand Up @@ -1331,14 +1331,12 @@

(define (valid-func-sig? paren sig)
(and (pair? sig)
(or (eq? (car sig) 'macrocall)
(eq? (car sig) 'call)
(eq? (car sig) 'tuple)
(or (memq (car sig) '(macrocall call tuple))
(and paren (eq? (car sig) 'block))
(and paren (eq? (car sig) '...))
(and (eq? (car sig) '|::|)
(pair? (cadr sig))
(eq? (car (cadr sig)) 'call))
(memq (car (cadr sig)) '(call macrocall)))
(and (eq? (car sig) 'where)
(valid-func-sig? paren (cadr sig))))))

Expand Down
22 changes: 22 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3904,3 +3904,25 @@ module ExtendedIsDefined
@test !$(Expr(:isdefined, GlobalRef(@__MODULE__, :x4), false))
end
end

# PR# 55040 - Macrocall as function sig
function callme end
macro callmemacro(args...)
Expr(:call, esc(:callme), map(esc, args)...)
end

function @callmemacro(a::Int)
return 1
end
@callmemacro(b::Float64) = 2
function @callmemacro(a::T, b::T) where T <: Int64
return 3
end
function @callmemacro(a::Int, b::Int, c::Int)::Float64
return 4
end

@test callme(1) === 1
@test callme(2.0) === 2
@test callme(3, 3) === 3
@test callme(4, 4, 4) === 4.0

0 comments on commit dabbc1d

Please sign in to comment.