From 77c6ffc9c3071546c70de734bca23cd2cd727189 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Fri, 7 Aug 2015 07:48:33 -0400 Subject: [PATCH 1/3] Only treat true string literals as doc string instead of looking for quote. This should be fine now after we change how tripple quote strings are parsed. Fix #12501 --- src/julia-parser.scm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 62a53517c95ac..25ed1cbdc643e 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -2072,16 +2072,14 @@ (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) (not (closing-token? (peek-token s)))) + `(macrocall (|.| Base (quote @doc)) ,ex ,(production s)) + ex))) ; --- main entry point --- From 0e82bb6518a96917c31870a8f002d9bc3bdb9c43 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Fri, 7 Aug 2015 08:40:55 -0400 Subject: [PATCH 2/3] Skip newlines before looking for closing tokens. --- src/julia-parser.scm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 25ed1cbdc643e..c34e1103b0fa2 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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))) @@ -2077,7 +2077,12 @@ (define (parse-docstring s production) (let* ((ex (production s))) - (if (and (doc-string-literal? ex) (not (closing-token? (peek-token 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))) From 1baab60d063262920acaad8878e1c1d4adf3e72e Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Fri, 7 Aug 2015 09:01:13 -0400 Subject: [PATCH 3/3] Add test for incorrect parsing of doc strings --- test/parse.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/parse.jl b/test/parse.jl index beadf905b848d..a28c82e0f1a4a 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -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 + """)