Skip to content

Commit

Permalink
Deprecate no spaces around ternary operators
Browse files Browse the repository at this point in the history
* deprecate no space after the ? (no space before was already
  deprecated)

* deprecate no space around the :

* fix instances where no spaces were used in Base
  • Loading branch information
carlobaldassi committed Jul 16, 2017
1 parent 223dd50 commit 4f193e0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base/grisu/bignum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function generateshortestdigits!(num,den,minus,plus,is_even,buffer)
in_delta_room_minus = is_even ?
Bignums.lessequal(num,minus) : Bignums.less(num,minus)
in_delta_room_plus = is_even ?
Bignums.pluscompare(num,plus,den) >= 0: Bignums.pluscompare(num,plus,den) > 0
Bignums.pluscompare(num,plus,den) >= 0 : Bignums.pluscompare(num,plus,den) > 0
if !in_delta_room_minus && !in_delta_room_plus
Bignums.times10!(num)
Bignums.times10!(minus)
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/repository.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function reset!(repo::GitRepo, obj::Nullable{<:GitObject}, pathspecs::AbstractSt
@check ccall((:git_reset_default, :libgit2), Cint,
(Ptr{Void}, Ptr{Void}, Ptr{StrArrayStruct}),
repo.ptr,
isnull(obj) ? C_NULL: Base.get(obj).ptr,
isnull(obj) ? C_NULL : Base.get(obj).ptr,
collect(pathspecs))
return head_oid(repo)
end
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ end
# blas.jl defines matmul for floats; other integer and mixed precision
# cases are handled here

lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1:2), size(M, t=='N' ? 2:1))
lapack_size(t::Char, M::AbstractVecOrMat) = (size(M, t=='N' ? 1 : 2), size(M, t=='N' ? 2 : 1))

function copy!(B::AbstractVecOrMat, ir_dest::UnitRange{Int}, jr_dest::UnitRange{Int}, tM::Char, M::AbstractVecOrMat, ir_src::UnitRange{Int}, jr_src::UnitRange{Int})
if tM == 'N'
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end

convert(::Type{Tridiagonal}, A::Bidiagonal{T}) where {T} =
Tridiagonal(A.uplo == 'U' ? zeros(T, size(A.dv,1)-1) : A.ev, A.dv,
A.uplo == 'U' ? A.ev:zeros(T, size(A.dv,1)-1))
A.uplo == 'U' ? A.ev : zeros(T, size(A.dv,1)-1))

function convert(::Type{Bidiagonal}, A::SymTridiagonal)
if !iszero(A.ev)
Expand Down
2 changes: 1 addition & 1 deletion base/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function parse(str::AbstractString, pos::Int; greedy::Bool=true, raise::Bool=tru
bstr = String(str)
ex, pos = ccall(:jl_parse_string, Any,
(Ptr{UInt8}, Csize_t, Int32, Int32),
bstr, sizeof(bstr), pos-1, greedy ? 1:0)
bstr, sizeof(bstr), pos-1, greedy ? 1 : 0)
if raise && isa(ex,Expr) && ex.head === :error
throw(ParseError(ex.args[1]))
end
Expand Down
2 changes: 1 addition & 1 deletion base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function banner(io::IO = STDOUT)
commit_string = "$(branch)/$(commit) (fork: $(distance) commits, $(days) $(unit))"
end
end
commit_date = !isempty(GIT_VERSION_INFO.date_string) ? " ($(GIT_VERSION_INFO.date_string))": ""
commit_date = !isempty(GIT_VERSION_INFO.date_string) ? " ($(GIT_VERSION_INFO.date_string))" : ""

if have_color
c = text_colors
Expand Down
17 changes: 13 additions & 4 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,20 @@
(cond ((eq? (peek-token s) '?)
(begin (if (not (ts:space? s))
(syntax-deprecation s (string (deparse ex) "?") (string (deparse ex) " ?")))
(take-token s)
(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)))))
(let ((then (without-range-colon (parse-eq* s))))
(if (not (eq? (take-token s) ':))
(error "colon expected in \"?\" expression")
(list 'if ex then (parse-eq* s))))))
(if (not (eq? (peek-token s) ':))
(error "colon expected in \"?\" expression"))
(if (not (ts:space? s))
(syntax-deprecation s (string (deparse ex) " ? " (deparse then) ":") (string (deparse ex) " ? " (deparse then) " :")))
(take-token s) ; take the :
(let ((t (with-whitespace-newline (peek-token s))))
(if (not (ts:space? s))
(syntax-deprecation s (string (deparse ex) " ? " (deparse then) " :" t) (string (deparse ex) " ? " (deparse then) " : " t))))
(list 'if ex then (parse-eq* s)))))
(else ex))))

(define (parse-arrow s) (parse-RtoL s parse-or is-prec-arrow? (eq? t '-->) parse-arrow))
Expand Down

0 comments on commit 4f193e0

Please sign in to comment.