Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#16071: restrict typed variable declaration to local x::T and global x::T #17125

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
(define end-symbol #f)
; treat newline like ordinary whitespace instead of as a potential separator
(define whitespace-newline #f)
; after the keywords `global` or `local`, the LHS of assignments can be typed.
(define allow-typed-assignments #f)

(define current-filename 'none)

Expand Down Expand Up @@ -160,6 +162,10 @@
`(with-bindings ((whitespace-newline #f))
,@body))

(define-macro (with-typed-assignments . body)
`(with-bindings ((allow-typed-assignments #f))
,@body))

;; --- lexer ---

(define (newline? c) (eqv? c #\newline))
Expand Down Expand Up @@ -924,7 +930,14 @@
(let ((t (peek-token s)))
(case t
((|::|) (take-token s)
(loop (list t ex (parse-call s))))
; (loop (list t ex (parse-call s))))
(let ((exx (list t ex (parse-call s))))
(if (and (not allow-typed-assignments)
(is-prec-assignment? (peek-token s)))
(syntax-deprecation s
(string "Type statement on left hand side of assignment.")
(string "Use with `local` or `global` first.")))
(loop exx)))
((->) (take-token s)
;; -> is unusual: it binds tightly on the left and
;; loosely on the right.
Expand Down Expand Up @@ -1160,7 +1173,7 @@
(const (and (eq? (peek-token s) 'const)
(take-token s)))
(expr (cons word
(parse-comma-separated-assignments s))))
(parse-comma-separated-typed-assignments s))))
(if const
`(const ,expr)
expr)))
Expand Down Expand Up @@ -1393,9 +1406,15 @@
((#\,) (take-token s) (loop (cons r exprs)))
(else (reverse! (cons r exprs)))))))


(define (parse-comma-separated-assignments s)
(parse-comma-separated s parse-eq*))


(define (parse-comma-separated-typed-assignments s)
(with-typed-assignments
(parse-comma-separated-assignments s)))

;; as above, but allows both "i=r" and "i in r"
(define (parse-iteration-spec s)
(let* ((lhs (parse-pipes s))
Expand Down