From c70b231f31c9d7d7353aa1c3feef09230ad053f6 Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Thu, 26 Jan 2017 18:27:46 -0500 Subject: [PATCH] Consider all whitespace in space-sensitive context --- src/julia-parser.scm | 11 +++++++---- test/parse.jl | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index deacd61d90f70..370aca386a562 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -529,6 +529,9 @@ (begin0 (ts:last-tok s) (ts:set-tok! s #f)))) +(define (space-before-next-token? s) + (or (skip-ws (ts:port s) #f) (eqv? #\newline (peek-char (ts:port s))))) + ;; --- misc --- (define (syntax-deprecation s what instead) @@ -703,7 +706,7 @@ ((and range-colon-enabled (eq? t ':)) (take-token s) (if (and space-sensitive spc - (or (peek-token s) #t) (not (ts:space? s))) + (not (space-before-next-token? s))) ;; "a :b" in space sensitive mode (begin (ts:put-back! s ':) ex) @@ -751,7 +754,7 @@ (begin (take-token s) (if (eq? t '~) (if (and space-sensitive (ts:space? s) - (not (eqv? (peek-char (ts:port s)) #\ ))) + (not (space-before-next-token? s))) (begin (ts:put-back! s t) ex) (list 'call t ex (parse-assignment s down))) @@ -785,7 +788,7 @@ (begin (take-token s) (cond ((and space-sensitive spc (memq t unary-and-binary-ops) - (not (eqv? (peek-char (ts:port s)) #\ ))) + (not (space-before-next-token? s))) ;; here we have "x -y" (ts:put-back! s t) (reverse! chain)) @@ -803,7 +806,7 @@ (begin (take-token s) (cond ((and space-sensitive spc (memq t unary-and-binary-ops) - (not (eqv? (peek-char (ts:port s)) #\ ))) + (not (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 35b0e5f96a56f..bb27fa63fd12f 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]""")