@@ -53,10 +53,10 @@ function normal_context(ps::ParseState)
53
53
whitespace_newline= false )
54
54
end
55
55
56
- function with_space_sensitive (f :: Function , ps:: ParseState )
57
- f ( ParseState (ps,
58
- space_sensitive= true ,
59
- whitespace_newline= false ) )
56
+ function with_space_sensitive (ps:: ParseState )
57
+ ParseState (ps,
58
+ space_sensitive= true ,
59
+ whitespace_newline= false )
60
60
end
61
61
62
62
# Convenient wrappers for ParseStream
@@ -1176,20 +1176,20 @@ function parse_unary_call(ps::ParseState)
1176
1176
mark_before_paren = position (ps)
1177
1177
bump (ps, TRIVIA_FLAG) # (
1178
1178
initial_semi = peek (ps) == K " ;"
1179
- is_call = false
1180
- is_block = false
1179
+ is_call = Ref ( false )
1180
+ is_block = Ref ( false )
1181
1181
parse_brackets (ps, K " )" ) do had_commas, had_splat, num_semis, num_subexprs
1182
- is_call = had_commas || had_splat || initial_semi
1183
- is_block = ! is_call && num_semis > 0
1182
+ is_call[] = had_commas || had_splat || initial_semi
1183
+ is_block[] = ! is_call[] && num_semis > 0
1184
1184
bump_closing_token (ps, K " )" )
1185
- return (needs_parameters= is_call,
1186
- eq_is_kw_before_semi= is_call,
1187
- eq_is_kw_after_semi= is_call)
1185
+ return (needs_parameters= is_call[] ,
1186
+ eq_is_kw_before_semi= is_call[] ,
1187
+ eq_is_kw_after_semi= is_call[] )
1188
1188
end
1189
1189
1190
1190
# The precedence between unary + and any following infix ^ depends on
1191
1191
# whether the parens are a function call or not
1192
- if is_call
1192
+ if is_call[]
1193
1193
if preceding_whitespace (t2)
1194
1194
# Whitespace not allowed before prefix function call bracket
1195
1195
# + (a,b) ==> (call + (error) a b)
@@ -1211,7 +1211,7 @@ function parse_unary_call(ps::ParseState)
1211
1211
parse_factor_with_initial_ex (ps, mark)
1212
1212
else
1213
1213
# Unary function calls with brackets as grouping, not an arglist
1214
- if is_block
1214
+ if is_block[]
1215
1215
# +(a;b) ==> (call + (block a b))
1216
1216
emit (ps, mark_before_paren, K " block" )
1217
1217
end
@@ -1400,7 +1400,7 @@ function parse_call_chain(ps::ParseState, mark, is_macrocall=false)
1400
1400
# a().@x y ==> (macrocall (error (. (call a) (quote x))) y)
1401
1401
# [@foo "x"] ==> (vect (macrocall @foo "x"))
1402
1402
finish_macroname (ps, mark, valid_macroname, macro_name_position)
1403
- with_space_sensitive (ps) do ps
1403
+ let ps = with_space_sensitive (ps)
1404
1404
# Space separated macro arguments
1405
1405
# A.@foo a b ==> (macrocall (. A (quote @foo)) a b)
1406
1406
# @A.foo a b ==> (macrocall (. A (quote @foo)) a b)
@@ -1779,8 +1779,10 @@ function parse_resword(ps::ParseState)
1779
1779
bump (ps, TRIVIA_FLAG)
1780
1780
@check peek (ps) == K " type"
1781
1781
bump (ps, TRIVIA_FLAG)
1782
- with_space_sensitive (parse_subtype_spec, ps)
1783
- with_space_sensitive (parse_cond, ps)
1782
+ let ps = with_space_sensitive (ps)
1783
+ parse_subtype_spec (ps)
1784
+ parse_cond (ps)
1785
+ end
1784
1786
bump_semicolon_trivia (ps)
1785
1787
bump_closing_token (ps, K " end" )
1786
1788
emit (ps, mark, K " primitive" )
@@ -1975,7 +1977,7 @@ function parse_function(ps::ParseState)
1975
1977
word = peek (ps)
1976
1978
@check word in KSet ` macro function`
1977
1979
is_function = word == K " function"
1978
- is_anon_func:: Bool = false
1980
+ is_anon_func = false
1979
1981
bump (ps, TRIVIA_FLAG)
1980
1982
bump_trivia (ps)
1981
1983
@@ -2005,13 +2007,15 @@ function parse_function(ps::ParseState)
2005
2007
#
2006
2008
# The flisp parser disambiguates this case quite differently,
2007
2009
# producing less consistent syntax for anonymous functions.
2010
+ is_anon_func_ = Ref (is_anon_func)
2008
2011
parse_brackets (ps, K " )" ) do _, _, _, _
2009
2012
bump_closing_token (ps, K " )" )
2010
- is_anon_func = peek (ps) != K " ("
2011
- return (needs_parameters = is_anon_func ,
2012
- eq_is_kw_before_semi = is_anon_func ,
2013
- eq_is_kw_after_semi = is_anon_func )
2013
+ is_anon_func_[] = peek (ps) != K " ("
2014
+ return (needs_parameters = is_anon_func_[] ,
2015
+ eq_is_kw_before_semi = is_anon_func_[] ,
2016
+ eq_is_kw_after_semi = is_anon_func_[] )
2014
2017
end
2018
+ is_anon_func = is_anon_func_[]
2015
2019
if is_anon_func
2016
2020
# function (x) body end ==> (function (tuple x) (block body))
2017
2021
# function (x,y) end ==> (function (tuple x y) (block))
@@ -2209,8 +2213,8 @@ function parse_macro_name(ps::ParseState)
2209
2213
# @! x ==> (macrocall @! x)
2210
2214
# @.. x ==> (macrocall @.. x)
2211
2215
# @$ x ==> (macrocall @$ x)
2212
- with_space_sensitive (ps) do ps1
2213
- parse_atom (ps1 , false )
2216
+ let ps = with_space_sensitive (ps)
2217
+ parse_atom (ps , false )
2214
2218
end
2215
2219
end
2216
2220
end
@@ -2263,13 +2267,14 @@ function parse_imports(ps::ParseState)
2263
2267
# import A, y ==> (import (. A) (. y))
2264
2268
# import A: x, y ==> (import (: (. A) (. x) (. y)))
2265
2269
# import A: +, == ==> (import (: (. A) (. +) (. ==)))
2266
- parse_comma_separated (ps, ps1-> parse_import (ps1, word, has_import_prefix))
2270
+ has_import_prefix_ = has_import_prefix
2271
+ parse_comma_separated (ps, ps1-> parse_import (ps1, word, has_import_prefix_))
2267
2272
if peek (ps) == K " :"
2268
2273
# Error recovery
2269
2274
# import A: x, B: y ==> (import (: (. A) (. x) (. B) (error-t (. y))))
2270
2275
emark = position (ps)
2271
2276
bump (ps, TRIVIA_FLAG)
2272
- parse_comma_separated (ps, ps1-> parse_import (ps1, word, has_import_prefix ))
2277
+ parse_comma_separated (ps, ps1-> parse_import (ps1, word, has_import_prefix_ ))
2273
2278
emit (ps, emark, K " error" , TRIVIA_FLAG,
2274
2279
error= " `:` can only be used when importing a single module. Split imports into multiple lines" )
2275
2280
end
@@ -2436,7 +2441,7 @@ function parse_iteration_spec(ps::ParseState)
2436
2441
mark = position (ps)
2437
2442
k = peek (ps)
2438
2443
# Handle `outer` contextual keyword
2439
- with_space_sensitive (parse_pipe_lt, ps )
2444
+ parse_pipe_lt ( with_space_sensitive (ps) )
2440
2445
if peek_behind (ps). orig_kind == K " outer"
2441
2446
if peek_skip_newline_in_gen (ps) in KSet ` = in ∈`
2442
2447
# Not outer keyword
@@ -2465,19 +2470,18 @@ end
2465
2470
2466
2471
# flisp: parse-space-separated-exprs
2467
2472
function parse_space_separated_exprs (ps:: ParseState )
2468
- with_space_sensitive (ps) do ps
2469
- n_sep = 0
2470
- while true
2471
- k = peek (ps)
2472
- if is_closing_token (ps, k) || k == K " NewlineWs" ||
2473
- (ps. for_generator && k == K " for" )
2474
- break
2475
- end
2476
- parse_eq (ps)
2477
- n_sep += 1
2473
+ ps = with_space_sensitive (ps)
2474
+ n_sep = 0
2475
+ while true
2476
+ k = peek (ps)
2477
+ if is_closing_token (ps, k) || k == K " NewlineWs" ||
2478
+ (ps. for_generator && k == K " for" )
2479
+ break
2478
2480
end
2479
- return n_sep
2481
+ parse_eq (ps)
2482
+ n_sep += 1
2480
2483
end
2484
+ return n_sep
2481
2485
end
2482
2486
2483
2487
# like parse-arglist, but with `for` parsed as a generator
@@ -2858,18 +2862,18 @@ function parse_paren(ps::ParseState, check_identifiers=true)
2858
2862
# Deal with all other cases of tuple or block syntax via the generic
2859
2863
# parse_brackets
2860
2864
initial_semi = peek (ps) == K " ;"
2861
- is_tuple = false
2862
- is_block = false
2865
+ is_tuple = Ref ( false )
2866
+ is_block = Ref ( false )
2863
2867
parse_brackets (ps, K " )" ) do had_commas, had_splat, num_semis, num_subexprs
2864
- is_tuple = had_commas || (had_splat && num_semis >= 1 ) ||
2868
+ is_tuple[] = had_commas || (had_splat && num_semis >= 1 ) ||
2865
2869
(initial_semi && (num_semis == 1 || num_subexprs > 0 ))
2866
- is_block = num_semis > 0
2870
+ is_block[] = num_semis > 0
2867
2871
bump_closing_token (ps, K " )" )
2868
- return (needs_parameters= is_tuple,
2872
+ return (needs_parameters= is_tuple[] ,
2869
2873
eq_is_kw_before_semi= false ,
2870
- eq_is_kw_after_semi= is_tuple)
2874
+ eq_is_kw_after_semi= is_tuple[] )
2871
2875
end
2872
- if is_tuple
2876
+ if is_tuple[]
2873
2877
# Tuple syntax with commas
2874
2878
# (x,) ==> (tuple x)
2875
2879
# (x,y) ==> (tuple x y)
@@ -2886,7 +2890,7 @@ function parse_paren(ps::ParseState, check_identifiers=true)
2886
2890
# (a; b; c,d) ==> (tuple a (parameters b (parameters c d)))
2887
2891
# (a=1, b=2; c=3) ==> (tuple (= a 1) (= b 2) (parameters (kw c 3)))
2888
2892
emit (ps, mark, K " tuple" )
2889
- elseif is_block
2893
+ elseif is_block[]
2890
2894
# Blocks
2891
2895
# (;;) ==> (block)
2892
2896
# (a=1;) ==> (block (= a 1))
0 commit comments