Skip to content

Commit

Permalink
fix #21440, parsing +(x::T,y::T) where {T}
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Apr 21, 2017
1 parent b9a541e commit 1fe7043
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/julia-parser.scm
Expand Up @@ -25,9 +25,11 @@
(define prec-bitshift (add-dots '(<< >> >>>)))
(define prec-times (add-dots '(* / ÷ % & ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗)))
(define prec-rational (add-dots '(//)))
;; `where`
;; unary
(define prec-power (add-dots '(^ ↑ ↓ ⇵ ⟰ ⟱ ⤈ ⤉ ⤊ ⤋ ⤒ ⤓ ⥉ ⥌ ⥍ ⥏ ⥑ ⥔ ⥕ ⥘ ⥙ ⥜ ⥝ ⥠ ⥡ ⥣ ⥥ ⥮ ⥯ ↑ ↓)))
(define prec-decl '(|::|))
;; `where`
;; `where` occurring after `::`
(define prec-dot '(|.|))

(define prec-names '(prec-assignment
Expand Down Expand Up @@ -594,7 +596,8 @@
ex))))

(define (parse-where s)
(let ((ex (parse-call s)))
;; `where` needs to be below unary for `+(x::T,y::T) where {T} = ...` to work
(let ((ex (parse-unary s)))
(if (and where-enabled
(eq? (peek-token s) 'where))
(parse-where-chain s ex)
Expand Down Expand Up @@ -819,7 +822,7 @@

(define (parse-term s) (parse-with-chains s parse-rational is-prec-times? '(*)))

(define (parse-rational s) (parse-LtoR s parse-unary is-prec-rational?))
(define (parse-rational s) (parse-LtoR s parse-where is-prec-rational?))

(define (parse-pipes s) (parse-LtoR s parse-range is-prec-pipe?))

Expand Down Expand Up @@ -954,7 +957,7 @@
(parse-factor-h s parse-decl is-prec-power?))

(define (parse-decl s)
(let loop ((ex (parse-where s)))
(let loop ((ex (parse-call s)))
(let ((t (peek-token s)))
(case t
((|::|) (take-token s)
Expand Down
3 changes: 3 additions & 0 deletions test/parse.jl
Expand Up @@ -1103,3 +1103,6 @@ end
Expr(:toplevel,
Expr(:using, Symbol("."), :B),
Expr(:using, Symbol("."), :C))

# issue #21440
@test parse("+(x::T,y::T) where {T} = 0") == parse("(+)(x::T,y::T) where {T} = 0")

0 comments on commit 1fe7043

Please sign in to comment.