File tree Expand file tree Collapse file tree 3 files changed +23
-13
lines changed Expand file tree Collapse file tree 3 files changed +23
-13
lines changed Original file line number Diff line number Diff line change @@ -435,6 +435,22 @@ julia> text = "x = \"\"\"\n \$a\n b\"\"\""
435
435
21:23 │ """ "\"\"\""
436
436
```
437
437
438
+ ### Less redundant ` block ` s
439
+
440
+ Sometimes ` Expr ` needs to contain redundant block constructs in order to have a
441
+ place to store ` LineNumberNode ` s, but we don't need these and avoid adding them
442
+ in several cases:
443
+ * The right hand side of short form function syntax
444
+ * The conditional in ` elseif `
445
+ * The body of anonymous functions after the ` -> `
446
+
447
+ ### Distinct conditional ternary expression
448
+
449
+ The syntax ` a ? b : c ` is the same as ` if a b else c ` in ` Expr ` so macros can't
450
+ distinguish these cases. Instead, we use a distinct expression head ` K"?" ` and
451
+ lower to ` Expr(:if) ` during ` Expr ` conversion.
452
+
453
+
438
454
## More about syntax kinds
439
455
440
456
We generally track the type of syntax nodes with a syntax "kind", stored
Original file line number Diff line number Diff line change @@ -3244,7 +3244,6 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3244
3244
if leading_kind == K " :"
3245
3245
# symbol/expression quote
3246
3246
# :foo ==> (quote foo)
3247
- # : foo ==> (quote (error-t) foo)
3248
3247
t = peek_token (ps, 2 )
3249
3248
k = kind (t)
3250
3249
if is_closing_token (ps, k) && (! is_keyword (k) || preceding_whitespace (t))
@@ -3256,19 +3255,12 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3256
3255
end
3257
3256
bump (ps, TRIVIA_FLAG) # K":"
3258
3257
if preceding_whitespace (t)
3259
- # : a ==> (quote (error-t) a))
3260
- # ===
3261
- # :
3262
- # a
3263
- # ==> (quote (error))
3264
- bump_trivia (ps, TRIVIA_FLAG,
3258
+ # : foo ==> (quote (error-t) foo)
3259
+ # :\nfoo ==> (quote (error-t) foo)
3260
+ bump_trivia (ps, TRIVIA_FLAG, skip_newlines= true ,
3265
3261
error= " whitespace not allowed after `:` used for quoting" )
3266
3262
# Heuristic recovery
3267
- if kind (t) == K " NewlineWs"
3268
- bump_invisible (ps, K " error" )
3269
- else
3270
- bump (ps)
3271
- end
3263
+ bump (ps)
3272
3264
else
3273
3265
# Being inside quote makes keywords into identifiers at at the
3274
3266
# first level of nesting
Original file line number Diff line number Diff line change @@ -568,10 +568,12 @@ tests = [
568
568
],
569
569
JuliaSyntax. parse_atom => [
570
570
" :foo" => " (quote foo)"
571
- " : foo" => " (quote (error-t) foo)"
572
571
# Literal colons
573
572
" :)" => " :"
574
573
" : end" => " :"
574
+ # Whitespace after quoting colon
575
+ " : foo" => " (quote (error-t) foo)"
576
+ " :\n foo" => " (quote (error-t) foo)"
575
577
# plain equals
576
578
" =" => " (error =)"
577
579
# Identifiers
You can’t perform that action at this time.
0 commit comments