From 65fcebf64569bc0dba71cd7b3b7b25edd0fe2329 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 11 Aug 2018 12:56:41 +0100 Subject: [PATCH] fix #28576, parsing `?` at end of input in conditional expression (cherry picked from commit d7e45841de3101283af91ac744e7e0c7b10c1608) --- src/julia-parser.scm | 4 ++-- test/syntax.jl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index e319d9cc3eccae..9d832894f9bb1b 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -779,7 +779,7 @@ (begin (if (not (ts:space? s)) (error "space required before \"?\" operator")) (take-token s) ; take the ? - (let ((t (with-whitespace-newline (without-range-colon (peek-token s))))) + (let ((t (with-whitespace-newline (without-range-colon (require-token s))))) (if (not (ts:space? s)) (error "space required after \"?\" operator"))) (let ((then (without-range-colon (parse-eq* s)))) @@ -788,7 +788,7 @@ (if (not (ts:space? s)) (error "space required before colon in \"?\" expression")) (take-token s) ; take the : - (let ((t (with-whitespace-newline (peek-token s)))) + (let ((t (with-whitespace-newline (require-token s)))) (if (not (ts:space? s)) (error "space required after colon in \"?\" expression"))) (list 'if ex then (parse-eq* s))))) diff --git a/test/syntax.jl b/test/syntax.jl index 935c7ce58add50..4e4417dd5a3b6e 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -1642,3 +1642,7 @@ end for ex in [:([x=1]), :(T{x=1})] @test Meta.lower(@__MODULE__, ex) == Expr(:error, string("misplaced assignment statement in \"", ex, "\"")) end + +# issue #28576 +@test Meta.isexpr(Meta.parse("1 == 2 ?"), :incomplete) +@test Meta.isexpr(Meta.parse("1 == 2 ? 3 :"), :incomplete)