Skip to content

Commit 98ee67c

Browse files
authored
Improve error message for trailing colon in certain situations (JuliaLang#34756)
The expression ``` function test_function(inputs): ... end ``` currently gives the following syntax error ``` ERROR: syntax: space not allowed after ":" used for quoting ``` This can be a bit confusing for users who do not know about quoting and do not intend it to be used as such. Since this kind of mistake is common for users coming from Python, try to give an improved error message.
1 parent bc2fbef commit 98ee67c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/julia-parser.scm

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,10 +1219,11 @@
12191219
((eqv? (peek-token s) ':)
12201220
(begin
12211221
(take-token s)
1222-
(if (or (eqv? (peek-token s) #\newline)
1223-
(ts:space? s)) ;; uses side effect of previous peek-token
1224-
(error "space not allowed after \":\" used for quoting"))
1225-
`(|.| ,ex (quote ,(parse-atom s #f)))))
1222+
(cond ((eqv? (peek-token s) #\newline)
1223+
(error "newline not allowed after \":\" used for quoting"))
1224+
((ts:space? s) ;; uses side effect of previous peek-token
1225+
(error "whitespace not allowed after \":\" used for quoting"))
1226+
(else `(|.| ,ex (quote ,(parse-atom s #f)))))))
12261227
((eq? (peek-token s) '$)
12271228
(take-token s)
12281229
(let ((dollarex (parse-atom s)))
@@ -2286,12 +2287,14 @@
22862287
(or (not (symbol? nxt))
22872288
(ts:space? s)))
22882289
':
2289-
(if (or (ts:space? s) (eqv? nxt #\newline))
2290-
(error "space not allowed after \":\" used for quoting")
2291-
(list 'quote
2290+
(cond ((ts:space? s)
2291+
(error "whitespace not allowed after \":\" used for quoting"))
2292+
((eqv? nxt #\newline)
2293+
(error "newline not allowed after \":\" used for quoting"))
2294+
(else (list 'quote
22922295
;; being inside quote makes `end` non-special again. issue #27690
22932296
(with-bindings ((end-symbol #f))
2294-
(parse-atom s #f)))))))
2297+
(parse-atom s #f))))))))
22952298

22962299
;; misplaced =
22972300
((eq? t '=) (error "unexpected \"=\""))

0 commit comments

Comments
 (0)