Skip to content

Commit

Permalink
Consider all whitespace in space-sensitive context
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed Feb 5, 2017
1 parent ae20130 commit c70b231
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]""")

0 comments on commit c70b231

Please sign in to comment.