From 9970edc66951af7b13da9c04f31fb83d30b95595 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 30 May 2016 23:40:11 -0400 Subject: [PATCH] fix some parsing issues fix #16609, better error for `1.im` fix #16671, parsing `1.` by itself fix #16672, duplicate line node in block expression --- src/julia-parser.scm | 11 +++++++---- test/parse.jl | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index b1c0b8495925f..44453520452d9 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -325,9 +325,10 @@ r is-float32-literal))) (if (and (eqv? #\. (string.char s (string.dec s (length s)))) (let ((nxt (peek-char port))) - (or (identifier-start-char? nxt) - (memv nxt '(#\( #\[ #\{ #\@ #\` #\~ #\"))))) - (error (string "invalid numeric constant \"" s (peek-char port) "\""))) + (and (not (eof-object? nxt)) + (or (identifier-start-char? nxt) + (memv nxt '(#\( #\[ #\{ #\@ #\` #\~ #\")))))) + (error (string "numeric constant \"" s "\" cannot be implicitly multiplied because it ends with \".\""))) ;; n is #f for integers > typemax(UInt64) (cond (is-hex-float-literal (numchk n s) (double n)) ((eq? pred char-hex?) (fix-uint-neg neg (sized-uint-literal n s 4))) @@ -635,7 +636,9 @@ (and (eqv? (car ops) #\,) (eq? (peek-token s) '=))) (loop ex #f (peek-token s)) - (if add-linenums + (if (and add-linenums + (not (and (pair? (car ex)) + (eq? (caar ex) 'line)))) (let ((loc (line-number-node s))) (loop (list* (down s) loc ex) #f (peek-token s))) (loop (cons (down s) ex) #f (peek-token s)))))))))) diff --git a/test/parse.jl b/test/parse.jl index 63f81b4dd5096..16609948b80eb 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -450,3 +450,14 @@ add_method_to_glob_fn!() @test (try error(); catch 0; end) === 0 @test (try error(); catch false; end) === false # false and true are Bool literals, not variables @test (try error(); catch true; end) === true + +# issue #16671 +@test parse("1.") === 1.0 + +# issue #16672 +let isline(x) = isa(x,Expr) && x.head === :line + @test count(isline, parse("begin end").args) == 1 + @test count(isline, parse("begin; end").args) == 1 + @test count(isline, parse("begin; x+2; end").args) == 1 + @test count(isline, parse("begin; x+2; y+1; end").args) == 2 +end