@@ -3023,18 +3023,17 @@ function parse_paren(ps::ParseState, check_identifiers=true)
3023
3023
emit (ps, mark, K " tuple" , PARENS_FLAG)
3024
3024
elseif is_syntactic_operator (k)
3025
3025
# allow :(=) etc in unchecked contexts, eg quotes
3026
- # :(=) ==> (quote =)
3027
- if check_identifiers && ! is_valid_identifier (k)
3028
- bump (ps, error= " invalid identifier" )
3029
- else
3030
- bump (ps)
3031
- end
3026
+ # :(=) ==> (quote (parens =))
3027
+ parse_atom (ps, check_identifiers)
3032
3028
bump_closing_token (ps, K " )" )
3033
- elseif ! check_identifiers && k == K " ::" && peek (ps, 2 , skip_newlines= true ) == K " )"
3029
+ emit (ps, mark, K " parens" )
3030
+ elseif ! check_identifiers && k == K " ::" &&
3031
+ peek (ps, 2 , skip_newlines= true ) == K " )"
3034
3032
# allow :(::) as a special case
3035
- # :(::) ==> (quote :: )
3033
+ # :(::) ==> (quote (parens ::) )
3036
3034
bump (ps)
3037
3035
bump (ps, TRIVIA_FLAG, skip_newlines= true )
3036
+ emit (ps, mark, K " parens" )
3038
3037
else
3039
3038
# Deal with all other cases of tuple or block syntax via the generic
3040
3039
# parse_brackets
@@ -3393,7 +3392,11 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3393
3392
mark = position (ps)
3394
3393
leading_kind = peek (ps)
3395
3394
# todo: Reorder to put most likely tokens first?
3396
- if leading_kind == K " '"
3395
+ if is_error (leading_kind)
3396
+ # Errors for bad tokens are emitted in validate_tokens() rather than
3397
+ # here.
3398
+ bump (ps)
3399
+ elseif leading_kind == K " '"
3397
3400
# char literal
3398
3401
bump (ps, TRIVIA_FLAG)
3399
3402
k = peek (ps)
@@ -3436,27 +3439,24 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3436
3439
# :\nfoo ==> (quote (error-t) foo)
3437
3440
bump_trivia (ps, TRIVIA_FLAG, skip_newlines= true ,
3438
3441
error= " whitespace not allowed after `:` used for quoting" )
3439
- # Heuristic recovery
3440
- bump (ps)
3441
- else
3442
- # Being inside quote makes keywords into identifiers at the
3443
- # first level of nesting
3444
- # :end ==> (quote end)
3445
- # :(end) ==> (quote (parens (error-t)))
3446
- # Being inside quote makes end non-special again (issue #27690)
3447
- # a[:(end)] ==> (ref a (quote (error-t end)))
3448
- parse_atom (ParseState (ps, end_symbol= false ), false )
3449
3442
end
3443
+ # Being inside quote makes keywords into identifiers at the
3444
+ # first level of nesting
3445
+ # :end ==> (quote end)
3446
+ # :(end) ==> (quote (parens (error-t)))
3447
+ # Being inside quote makes end non-special again (issue #27690)
3448
+ # a[:(end)] ==> (ref a (quote (error-t end)))
3449
+ parse_atom (ParseState (ps, end_symbol= false ), false )
3450
3450
emit (ps, mark, K " quote" )
3451
- elseif leading_kind == K " =" && is_plain_equals (peek_token (ps))
3451
+ elseif check_identifiers && leading_kind == K " =" && is_plain_equals (peek_token (ps))
3452
3452
# = ==> (error =)
3453
3453
bump (ps, error= " unexpected `=`" )
3454
3454
elseif leading_kind == K " Identifier"
3455
3455
# xx ==> xx
3456
3456
# x₁ ==> x₁
3457
3457
bump (ps)
3458
3458
elseif is_operator (leading_kind)
3459
- if check_identifiers && is_syntactic_operator (leading_kind)
3459
+ if check_identifiers && ! is_valid_identifier (leading_kind)
3460
3460
# += ==> (error +=)
3461
3461
# .+= ==> (error .+=)
3462
3462
bump (ps, error= " invalid identifier" )
@@ -3558,10 +3558,6 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3558
3558
" premature end of input" :
3559
3559
" unexpected closing token"
3560
3560
bump_invisible (ps, K " error" , error= msg)
3561
- elseif is_error (leading_kind)
3562
- # Errors for bad tokens are emitted in validate_tokens() rather than
3563
- # here.
3564
- bump (ps)
3565
3561
else
3566
3562
bump (ps, error= " invalid syntax atom" )
3567
3563
end
0 commit comments