@@ -540,7 +540,7 @@ function parse_assignment(ps::ParseState, down, equals_is_kw::Bool)
540
540
parse_assignment_with_initial_ex (ps, mark, down, equals_is_kw)
541
541
end
542
542
543
- function parse_assignment_with_initial_ex (ps:: ParseState , mark, down, equals_is_kw:: Bool )
543
+ function parse_assignment_with_initial_ex (ps:: ParseState , mark, down:: T , equals_is_kw:: Bool ) where {T} # where => specialize on `down`
544
544
t = peek_token (ps)
545
545
k = kind (t)
546
546
if ! is_prec_assignment (k)
@@ -1169,19 +1169,18 @@ function parse_unary_call(ps::ParseState)
1169
1169
mark_before_paren = position (ps)
1170
1170
bump (ps, TRIVIA_FLAG) # (
1171
1171
initial_semi = peek (ps) == K " ;"
1172
- is_call = Ref (false )
1173
- is_block = Ref (false )
1174
- parse_brackets (ps, K " )" ) do had_commas, had_splat, num_semis, num_subexprs
1175
- is_call[] = had_commas || had_splat || initial_semi
1176
- is_block[] = ! is_call[] && num_semis > 0
1177
- return (needs_parameters= is_call[],
1178
- eq_is_kw_before_semi= is_call[],
1179
- eq_is_kw_after_semi= is_call[])
1172
+ opts = parse_brackets (ps, K " )" ) do had_commas, had_splat, num_semis, num_subexprs
1173
+ is_call = had_commas || had_splat || initial_semi
1174
+ return (needs_parameters= is_call,
1175
+ eq_is_kw_before_semi= is_call,
1176
+ eq_is_kw_after_semi= is_call,
1177
+ is_call= is_call,
1178
+ is_block= ! is_call && num_semis > 0 )
1180
1179
end
1181
1180
1182
1181
# The precedence between unary + and any following infix ^ depends on
1183
1182
# whether the parens are a function call or not
1184
- if is_call[]
1183
+ if opts . is_call
1185
1184
if preceding_whitespace (t2)
1186
1185
# Whitespace not allowed before prefix function call bracket
1187
1186
# + (a,b) ==> (call + (error) a b)
@@ -1203,7 +1202,7 @@ function parse_unary_call(ps::ParseState)
1203
1202
parse_factor_with_initial_ex (ps, mark)
1204
1203
else
1205
1204
# Unary function calls with brackets as grouping, not an arglist
1206
- if is_block[]
1205
+ if opts . is_block
1207
1206
# +(a;b) ==> (call + (block a b))
1208
1207
emit (ps, mark_before_paren, K " block" )
1209
1208
end
@@ -1995,14 +1994,14 @@ function parse_function(ps::ParseState)
1995
1994
# distinguish the cases here.
1996
1995
bump (ps, TRIVIA_FLAG)
1997
1996
is_empty_tuple = peek (ps, skip_newlines= true ) == K " )"
1998
- _is_anon_func = Ref (is_anon_func)
1999
- parse_brackets (ps, K " ) " ) do _, _, _, _
2000
- _is_anon_func[] = peek (ps, 2 ) != K " ( "
2001
- return (needs_parameters = _is_anon_func[] ,
2002
- eq_is_kw_before_semi = _is_anon_func[] ,
2003
- eq_is_kw_after_semi = _is_anon_func[] )
1997
+ opts = parse_brackets (ps, K " ) " ) do _, _, _, _
1998
+ _is_anon_func = peek (ps, 2 ) != K " ( "
1999
+ return (needs_parameters = _is_anon_func,
2000
+ eq_is_kw_before_semi = _is_anon_func,
2001
+ eq_is_kw_after_semi = _is_anon_func,
2002
+ is_anon_func = _is_anon_func)
2004
2003
end
2005
- is_anon_func = _is_anon_func[]
2004
+ is_anon_func = opts . is_anon_func
2006
2005
if is_anon_func
2007
2006
# function (x) body end ==> (function (tuple x) (block body))
2008
2007
# function (x,y) end ==> (function (tuple x y) (block))
@@ -2859,17 +2858,16 @@ function parse_paren(ps::ParseState, check_identifiers=true)
2859
2858
# Deal with all other cases of tuple or block syntax via the generic
2860
2859
# parse_brackets
2861
2860
initial_semi = peek (ps) == K " ;"
2862
- is_tuple = Ref (false )
2863
- is_block = Ref (false )
2864
- parse_brackets (ps, K " )" ) do had_commas, had_splat, num_semis, num_subexprs
2865
- is_tuple[] = had_commas || (had_splat && num_semis >= 1 ) ||
2861
+ opts = parse_brackets (ps, K " )" ) do had_commas, had_splat, num_semis, num_subexprs
2862
+ is_tuple = had_commas || (had_splat && num_semis >= 1 ) ||
2866
2863
(initial_semi && (num_semis == 1 || num_subexprs > 0 ))
2867
- is_block[] = num_semis > 0
2868
- return (needs_parameters= is_tuple[],
2864
+ return (needs_parameters= is_tuple,
2869
2865
eq_is_kw_before_semi= false ,
2870
- eq_is_kw_after_semi= is_tuple[])
2866
+ eq_is_kw_after_semi= is_tuple,
2867
+ is_tuple= is_tuple,
2868
+ is_block= num_semis > 0 )
2871
2869
end
2872
- if is_tuple[]
2870
+ if opts . is_tuple
2873
2871
# Tuple syntax with commas
2874
2872
# (x,) ==> (tuple x)
2875
2873
# (x,y) ==> (tuple x y)
@@ -2886,7 +2884,7 @@ function parse_paren(ps::ParseState, check_identifiers=true)
2886
2884
# (a; b; c,d) ==> (tuple a (parameters b (parameters c d)))
2887
2885
# (a=1, b=2; c=3) ==> (tuple (= a 1) (= b 2) (parameters (kw c 3)))
2888
2886
emit (ps, mark, K " tuple" )
2889
- elseif is_block[]
2887
+ elseif opts . is_block
2890
2888
# Blocks
2891
2889
# (;;) ==> (block)
2892
2890
# (a=1;) ==> (block (= a 1))
@@ -3016,6 +3014,7 @@ function parse_brackets(after_parse::Function,
3016
3014
release_positions (ps. stream, params_marks)
3017
3015
release_positions (ps. stream, eq_positions)
3018
3016
bump_closing_token (ps, closing_kind)
3017
+ return actions
3019
3018
end
3020
3019
3021
3020
is_indentation (b:: UInt8 ) = (b == UInt8 (' ' ) || b == UInt8 (' \t ' ))
0 commit comments