diff --git a/src/julia-parser.scm b/src/julia-parser.scm index fece65ee370d2c..eec62a34457236 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -528,6 +528,10 @@ (begin0 (ts:last-tok s) (ts:set-tok! s #f)))) +(define (no-space-before-next-token? s) + (let ((t (peek-token s))) + (not (or (ts:space? s) (newline? t))))) + ;; --- misc --- (define (syntax-deprecation s what instead) @@ -701,7 +705,7 @@ ((and range-colon-enabled (eq? t ':)) (take-token s) (if (and space-sensitive spc - (or (peek-token s) #t) (not (ts:space? s))) + (no-space-before-next-token? s)) ;; "a :b" in space sensitive mode (begin (ts:put-back! s ':) ex) @@ -749,7 +753,7 @@ (begin (take-token s) (if (eq? t '~) (if (and space-sensitive (ts:space? s) - (not (eqv? (peek-char (ts:port s)) #\ ))) + (no-space-before-next-token? s)) (begin (ts:put-back! s t) ex) (let ((args (parse-chain s down '~))) @@ -785,7 +789,7 @@ (begin (take-token s) (cond ((and space-sensitive spc (memq t unary-and-binary-ops) - (not (eqv? (peek-char (ts:port s)) #\ ))) + (no-space-before-next-token? s)) ;; here we have "x -y" (ts:put-back! s t) (reverse! chain)) @@ -803,7 +807,7 @@ (begin (take-token s) (cond ((and space-sensitive spc (memq t unary-and-binary-ops) - (not (eqv? (peek-char (ts:port s)) #\ ))) + (no-space-before-next-token? s)) ;; here we have "x -y" (ts:put-back! s t) ex) diff --git a/test/parse.jl b/test/parse.jl index 8b25df99b53659..db17839dea0637 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -933,3 +933,24 @@ end # a :block for its body short_where_call = :(f(x::T) where T = T) @test short_where_call.args[2].head == :block + +# issue #16594 +@test length(:(@test 1 + + 1 == 2).args) == 2 +@test [1 + + 1] == [2] +@test [1 +1] == [1 1] +@test length(:(@x 1 +1 -1).args) == 4 +@test length(:(@x 1 + 1 -1).args) == 3 +@test length(:(@x 1 + 1 - 1).args) == 2 +@test length(:(@x 1 + + 1 - + 1).args) == 2 +@test length(:(@x 1 + + 1 + + 1).args) == 2 +@test length(:([x .+ + y]).args) == 1 + +# line break in : expression disallowed +@test_throws ParseError parse("[1 :\n2] == [1:2]""")