Skip to content

Commit

Permalink
Consider newlines as spaces for space-sensitive parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed Jan 26, 2017
1 parent 876549f commit e3e8b5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 '~)))
Expand Down Expand Up @@ -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))
Expand All @@ -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)
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 e3e8b5f

Please sign in to comment.