Skip to content

Commit

Permalink
Deprecate the use of ? as an identifier
Browse files Browse the repository at this point in the history
Ref #6286
  • Loading branch information
carlobaldassi committed Jul 16, 2017
1 parent 4f193e0 commit fabe9ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ the byte representation is different.
This would create a 25-by-30000 `BitArray`, linked to the file associated with stream `s`.
"""
Mmap.mmap(io, ::BitArray, dims = ?, offset = ?)
Mmap.mmap(io, ::BitArray, dims, offset)

"""
sizeof(T)
Expand Down Expand Up @@ -2151,7 +2151,7 @@ julia> pop!(d, "e", 4)
4
```
"""
pop!(collection,key,?)
pop!(collection,key,default)

"""
pop!(collection) -> item
Expand Down
21 changes: 15 additions & 6 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
(define whitespace-newline #f)
; enable parsing `where` with high precedence
(define where-enabled #t)
; the question mark is only allowed as a token in ternary expressions
(define allow-question-mark #f)

(define current-filename 'none)

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

(define-macro (with-allow-question-mark . body)
`(with-bindings ((allow-question-mark #t))
,@body))

;; --- lexer ---

(define (newline? c) (eqv? c #\newline))
Expand Down Expand Up @@ -541,11 +547,14 @@
t)))))

(define (take-token s)
(or
(begin0 (ts:pbtok s)
(aset! s 3 #f))
(begin0 (ts:last-tok s)
(ts:set-tok! s #f))))
(let ((t (or
(begin0 (ts:pbtok s)
(aset! s 3 #f))
(begin0 (ts:last-tok s)
(ts:set-tok! s #f)))))
(if (and (not allow-question-mark) (eq? t '?))
(syntax-deprecation s "`?` used as an identifier" ""))
t))

;; --- misc ---

Expand Down Expand Up @@ -736,7 +745,7 @@
(cond ((eq? (peek-token s) '?)
(begin (if (not (ts:space? s))
(syntax-deprecation s (string (deparse ex) "?") (string (deparse ex) " ?")))
(take-token s) ; take the ?
(with-allow-question-mark (take-token s)) ; take the ?
(let ((t (with-whitespace-newline (without-range-colon (peek-token s)))))
(if (not (ts:space? s))
(syntax-deprecation s (string (deparse ex) " ?" (deparse t)) (string (deparse ex) " ? " (deparse t)))))
Expand Down
2 changes: 1 addition & 1 deletion test/enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ end
@test Integer(_zerobi) == 1

# can't use non-identifiers as enum members
@test_throws ArgumentError eval(:(@enum(Test2, ?)))
@test_throws ArgumentError eval(:(@enum Test2 x ? 1 : 2))
@test_throws ArgumentError eval(:(@enum Test22 1=2))

# other Integer types of enum members
Expand Down

0 comments on commit fabe9ee

Please sign in to comment.