Skip to content

Commit d57c648

Browse files
authored
fix #36196, failure to give expected "end" error in parser (#36198)
1 parent cb41bbb commit d57c648

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/julia-parser.scm

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -662,16 +662,13 @@
662662
(first? #t)
663663
(t (peek-token s)))
664664
(if (not (memv t ops))
665-
(begin
666-
(if (not (or (eof-object? t) (eqv? t #\newline) (closer? t)))
667-
(error (string "extra token \"" t "\" after end of expression")))
668-
(if (or (null? ex) (pair? (cdr ex)) (not first?))
669-
;; () => (head)
670-
;; (ex2 ex1) => (head ex1 ex2)
671-
;; (ex1) if operator appeared => (head ex1) (handles "x;")
672-
(cons head (reverse! ex))
673-
;; (ex1) => ex1
674-
(car ex)))
665+
(if (or (null? ex) (pair? (cdr ex)) (not first?))
666+
;; () => (head)
667+
;; (ex2 ex1) => (head ex1 ex2)
668+
;; (ex1) if operator appeared => (head ex1) (handles "x;")
669+
(cons head (reverse! ex))
670+
;; (ex1) => ex1
671+
(car ex))
675672
(begin (take-token s)
676673
;; allow input to end with the operator, as in a;b;
677674
(if (or (eof-object? (peek-token s))
@@ -1270,15 +1267,18 @@
12701267

12711268
(define (expect-end s word)
12721269
(let ((t (peek-token s)))
1273-
(cond ((eq? t 'end) (take-token s))
1274-
((eof-object? t)
1275-
(error (string "incomplete: \"" word "\" at " ; NOTE: changing this may affect code in base/client.jl
1276-
current-filename ":" expect-end-current-line
1277-
" requires end")))
1278-
(else
1279-
(error (string "\"" word "\" at "
1280-
current-filename ":" expect-end-current-line
1281-
" expected \"end\", got \"" t "\""))))))
1270+
(if (eq? t 'end)
1271+
(take-token s)
1272+
(expect-end-error t word))))
1273+
1274+
(define (expect-end-error t word)
1275+
(if (eof-object? t)
1276+
(error (string "incomplete: \"" word "\" at " ; NOTE: changing this may affect code in base/client.jl
1277+
current-filename ":" expect-end-current-line
1278+
" requires end"))
1279+
(error (string "\"" word "\" at "
1280+
current-filename ":" expect-end-current-line
1281+
" expected \"end\", got \"" t "\""))))
12821282

12831283
(define (parse-subtype-spec s)
12841284
(parse-comparison s))
@@ -1469,10 +1469,10 @@
14691469
(expect-end (take-lineendings s) "primitive type"))))))
14701470

14711471
((try)
1472-
(let ((try-block (if (memq (require-token s) '(catch finally))
1472+
(let ((try-block (if (memq (peek-token s) '(catch finally))
14731473
'(block)
14741474
(parse-block s))))
1475-
(let loop ((nxt (require-token s))
1475+
(let loop ((nxt (peek-token s))
14761476
(catchb #f)
14771477
(catchv #f)
14781478
(finalb #f))
@@ -1519,7 +1519,7 @@
15191519
catchb
15201520
catchv
15211521
fb)))
1522-
(else (error (string "unexpected \"" nxt "\"")))))))
1522+
(else (expect-end-error nxt 'try))))))
15231523
((return) (let ((t (peek-token s)))
15241524
(if (or (eqv? t #\newline) (closing-token? t))
15251525
(list 'return '(null))

test/syntax.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,3 +2264,7 @@ x = let var"'"(x) = 2x
22642264
3'
22652265
end
22662266
@test x == 6
2267+
2268+
# issue #36196
2269+
@test_throws ParseError("\"for\" at none:1 expected \"end\", got \")\"") Meta.parse("(for i=1; println())")
2270+
@test_throws ParseError("\"try\" at none:1 expected \"end\", got \")\"") Meta.parse("(try i=1; println())")

0 commit comments

Comments
 (0)