Skip to content

Commit

Permalink
Merge pull request JuliaLang#12502 from JuliaLang/yyc/doc-str
Browse files Browse the repository at this point in the history
Only treat true string literals as doc string
  • Loading branch information
JeffBezanson committed Aug 9, 2015
2 parents 5793ddf + 1baab60 commit 5150121
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,12 @@

(define (parse-block s (down parse-eq))
(parse-Nary s down '(#\newline #\;) 'block
'(end else elseif catch finally) #t))
'(end else elseif catch finally) #t))

;; ";" at the top level produces a sequence of top level expressions
(define (parse-stmts s)
(let ((ex (parse-Nary s (lambda (s) (parse-docstring s parse-eq))
'(#\;) 'toplevel '(#\newline) #t)))
'(#\;) 'toplevel '(#\newline) #t)))
;; check for unparsed junk after an expression
(let ((t (peek-token s)))
(if (not (or (eof-object? t) (eqv? t #\newline) (eq? t #f)))
Expand Down Expand Up @@ -2072,16 +2072,19 @@
(define (doc-string-literal? e)
(or (simple-string-literal? e)
(and (length= e 3) (eq? (car e) 'macrocall)
(simple-string-literal? (caddr e))
(eq? (cadr e) '@doc_str))))
(simple-string-literal? (caddr e))
(eq? (cadr e) '@doc_str))))

(define (parse-docstring s production)
(let* ((isstr (eqv? (peek-token s) #\"))
(ex (production s)))
(if (and (or isstr (doc-string-literal? ex))
(not (closing-token? (peek-token s))))
`(macrocall (|.| Base (quote @doc)) ,ex ,(production s))
ex)))
(let* ((ex (production s)))
(if (and (doc-string-literal? ex)
(let loop ((t (peek-token s)))
(cond
((closing-token? t) #f)
((newline? t) (take-token s) (loop (peek-token s)))
(else #t))))
`(macrocall (|.| Base (quote @doc)) ,ex ,(production s))
ex)))

; --- main entry point ---

Expand Down
12 changes: 12 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,15 @@ for T in (UInt8,UInt16,UInt32,UInt64)
end

@test parse("1 == 2|>3") == Expr(:comparison, 1, :(==), Expr(:call, :(|>), 2, 3))

# issue #12501 and pr #12502
parse("""
baremodule A
"a" in b
end
""")
parse("""
baremodule A
"a"
end
""")

0 comments on commit 5150121

Please sign in to comment.