From 4f193e0ece22c4677da9fa2a03d3d5e4df3289b9 Mon Sep 17 00:00:00 2001 From: Carlo Baldassi Date: Fri, 7 Jul 2017 19:38:33 +0200 Subject: [PATCH] Deprecate no spaces around ternary operators * 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 --- base/grisu/bignum.jl | 2 +- base/libgit2/repository.jl | 2 +- base/linalg/matmul.jl | 2 +- base/linalg/special.jl | 2 +- base/parse.jl | 2 +- base/version.jl | 2 +- src/julia-parser.scm | 17 +++++++++++++---- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/base/grisu/bignum.jl b/base/grisu/bignum.jl index 734dbefca1f1a..2f1d67ce292ed 100644 --- a/base/grisu/bignum.jl +++ b/base/grisu/bignum.jl @@ -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) diff --git a/base/libgit2/repository.jl b/base/libgit2/repository.jl index 3cf3295c55f90..84e7c70681665 100644 --- a/base/libgit2/repository.jl +++ b/base/libgit2/repository.jl @@ -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 diff --git a/base/linalg/matmul.jl b/base/linalg/matmul.jl index 0fce02cbb699f..553ec886a3933 100644 --- a/base/linalg/matmul.jl +++ b/base/linalg/matmul.jl @@ -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' diff --git a/base/linalg/special.jl b/base/linalg/special.jl index d57ff0f23520a..e7ba87788d40b 100644 --- a/base/linalg/special.jl +++ b/base/linalg/special.jl @@ -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) diff --git a/base/parse.jl b/base/parse.jl index 03d460d0585b8..543429ce142d9 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -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 diff --git a/base/version.jl b/base/version.jl index 08938b3f48af9..e7268f9a9fe21 100644 --- a/base/version.jl +++ b/base/version.jl @@ -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 diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 49c5e6cfd40c1..a5c4e665633b9 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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))