Skip to content

Commit

Permalink
Merge pull request #19732 from stevengj/dotdot
Browse files Browse the repository at this point in the history
fix ability to use .. as an infix operator
  • Loading branch information
JeffBezanson authored Dec 28, 2016
2 parents ed1183b + bb05e88 commit 8ed946b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@
(cadr (caddr e))
e))

(define (dotop? o) (and (symbol? o) (eqv? (string.char (string o) 0) #\.)))
(define (dotop? o) (and (symbol? o) (eqv? (string.char (string o) 0) #\.)
(not (eq? o '|.|))
(not (eqv? (string.char (string o) 1) #\.))))

; convert '.xx to 'xx
(define (undotop op)
Expand All @@ -207,7 +209,9 @@
(define (maybe-undotop e)
(if (symbol? e)
(let ((str (string e)))
(if (eqv? (string.char str 0) #\.)
(if (and (eqv? (string.char str 0) #\.)
(not (eq? e '|.|))
(not (eqv? (string.char str 1) #\.)))
(symbol (string.sub str 1 (length str)))
#f))
(if (pair? e)
Expand Down
3 changes: 1 addition & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@
(define dot-opchar? (Set
(delete-duplicates
(map (lambda (op) (string.char (string op) 1))
(filter (lambda (op) (and (dotop? op) (not (eq? op '|.|))))
operators)))))
(cons `|..| (filter dotop? operators))))))
(define operator? (Set operators))

(define initial-reserved-words '(begin while if for try return break continue
Expand Down
4 changes: 4 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,7 @@ end

@test QualifiedStringMacro.SubModule.x"" === 1
@test QualifiedStringMacro.SubModule.y`` === 2

let ..(x,y) = x + y
@test 3 .. 4 === 7
end

0 comments on commit 8ed946b

Please sign in to comment.