184
184
185
185
# flisp: disallow-space
186
186
function bump_disallowed_space (ps)
187
- if peek_token (ps). had_whitespace
187
+ if preceding_whitespace ( peek_token (ps))
188
188
bump_trivia (ps, TRIVIA_FLAG, skip_newlines= false ,
189
189
error= " whitespace is not allowed here" )
190
190
end
@@ -561,7 +561,7 @@ function parse_assignment_with_initial_ex(ps::ParseState, mark, down, equals_is_
561
561
return NO_POSITION
562
562
end
563
563
if k == K " ~"
564
- if ps. space_sensitive && ! peek_token (ps, 2 ). had_whitespace
564
+ if ps. space_sensitive && ! preceding_whitespace ( peek_token (ps, 2 ))
565
565
# Unary ~ in space sensitive context is not assignment precedence
566
566
# [a ~b] ==> (hcat a (call ~ b))
567
567
return NO_POSITION
@@ -626,21 +626,21 @@ function parse_cond(ps::ParseState)
626
626
if kind (t) != K " ?"
627
627
return
628
628
end
629
- if ! t . had_whitespace
629
+ if ! preceding_whitespace (t)
630
630
# a? b : c => (if a (error-t) b c)
631
631
bump_invisible (ps, K " error" , TRIVIA_FLAG,
632
632
error= " space required before `?` operator" )
633
633
end
634
634
bump (ps, TRIVIA_FLAG) # ?
635
635
t = peek_token (ps)
636
- if ! t . had_whitespace
636
+ if ! preceding_whitespace (t)
637
637
# a ?b : c
638
638
bump_invisible (ps, K " error" , TRIVIA_FLAG,
639
639
error= " space required after `?` operator" )
640
640
end
641
641
parse_eq_star (ParseState (ps, range_colon_enabled= false ))
642
642
t = peek_token (ps)
643
- if ! t . had_whitespace
643
+ if ! preceding_whitespace (t)
644
644
# a ? b: c ==> (if a [ ] [?] [ ] b (error-t) [:] [ ] c)
645
645
bump_invisible (ps, K " error" , TRIVIA_FLAG,
646
646
error= " space required before `:` in `?` expression" )
@@ -652,7 +652,7 @@ function parse_cond(ps::ParseState)
652
652
bump_invisible (ps, K " error" , TRIVIA_FLAG, error= " `:` expected in `?` expression" )
653
653
end
654
654
t = peek_token (ps)
655
- if ! t . had_whitespace
655
+ if ! preceding_whitespace (t)
656
656
# a ? b :c ==> (if a [ ] [?] [ ] b [ ] [:] (error-t) c)
657
657
bump_invisible (ps, K " error" , TRIVIA_FLAG,
658
658
error= " space required after `:` in `?` expression" )
@@ -799,15 +799,15 @@ function parse_range(ps::ParseState)
799
799
n_colons = 0
800
800
while peek (ps) == K " :"
801
801
if ps. space_sensitive &&
802
- peek_token (ps). had_whitespace &&
803
- ! peek_token (ps, 2 ). had_whitespace
802
+ preceding_whitespace ( peek_token (ps)) &&
803
+ ! preceding_whitespace ( peek_token (ps, 2 ))
804
804
# Tricky cases in space sensitive mode
805
805
# [1 :a] ==> (hcat 1 (quote a))
806
806
# [1 2:3 :a] ==> (hcat 1 (call-i 2 : 3) (quote a))
807
807
break
808
808
end
809
809
t2 = peek_token (ps,2 )
810
- if kind (t2) in KSet ` < >` && ! t2 . had_whitespace
810
+ if kind (t2) in KSet ` < >` && ! preceding_whitespace (t2)
811
811
# Error heuristic: we found `:>` or `:<` which are invalid lookalikes
812
812
# for `<:` and `>:`. Attempt to recover by treating them as a
813
813
# comparison operator.
@@ -887,9 +887,9 @@ function parse_with_chains(ps::ParseState, down, is_op, chain_ops)
887
887
mark = position (ps)
888
888
down (ps)
889
889
while (t = peek_token (ps); is_op (kind (t)))
890
- if ps. space_sensitive && t . had_whitespace &&
890
+ if ps. space_sensitive && preceding_whitespace (t) &&
891
891
is_both_unary_and_binary (t) &&
892
- ! peek_token (ps, 2 ). had_whitespace
892
+ ! preceding_whitespace ( peek_token (ps, 2 ))
893
893
# The following is two elements of a hcat
894
894
# [x +y] ==> (hcat x (call + y))
895
895
# [x+y +z] ==> (hcat (call-i x + y) (call + z))
917
917
# flisp: parse-chain
918
918
function parse_chain (ps:: ParseState , down, op_kind)
919
919
while (t = peek_token (ps); kind (t) == op_kind && ! is_decorated (t))
920
- if ps. space_sensitive && t . had_whitespace &&
920
+ if ps. space_sensitive && preceding_whitespace (t) &&
921
921
is_both_unary_and_binary (t) &&
922
- ! peek_token (ps, 2 ). had_whitespace
922
+ ! preceding_whitespace ( peek_token (ps, 2 ))
923
923
# [x +y] ==> (hcat x (call + y))
924
924
break
925
925
end
@@ -1024,7 +1024,7 @@ function is_juxtapose(ps, prev_k, t)
1024
1024
# x' y ==> x
1025
1025
# x 'y ==> x
1026
1026
1027
- return ! t . had_whitespace &&
1027
+ return ! preceding_whitespace (t) &&
1028
1028
(is_number (prev_k) ||
1029
1029
(! is_number (k) && # disallow "x.3" and "sqrt(2)2"
1030
1030
k != K " @" && # disallow "x@time"
@@ -1098,7 +1098,7 @@ function parse_unary(ps::ParseState)
1098
1098
end
1099
1099
if k in KSet ` - +`
1100
1100
t2 = peek_token (ps, 2 )
1101
- if ! t2 . had_whitespace && kind (t2) in KSet ` Integer Float`
1101
+ if ! preceding_whitespace (t2) && kind (t2) in KSet ` Integer Float`
1102
1102
k3 = peek (ps, 3 )
1103
1103
if is_prec_power (k3) || k3 in KSet ` [ {`
1104
1104
# `[`, `{` (issue #18851) and `^` have higher precedence than
@@ -1190,7 +1190,7 @@ function parse_unary_call(ps::ParseState)
1190
1190
# The precedence between unary + and any following infix ^ depends on
1191
1191
# whether the parens are a function call or not
1192
1192
if is_call
1193
- if t2 . had_whitespace
1193
+ if preceding_whitespace (t2)
1194
1194
# Whitespace not allowed before prefix function call bracket
1195
1195
# + (a,b) ==> (call + (error) a b)
1196
1196
reset_node! (ps, ws_error_pos, kind= K " error" )
@@ -1392,7 +1392,7 @@ function parse_call_chain(ps::ParseState, mark, is_macrocall=false)
1392
1392
this_iter_valid_macroname = false
1393
1393
t = peek_token (ps)
1394
1394
k = kind (t)
1395
- if is_macrocall && (t . had_whitespace || is_closing_token (ps, k))
1395
+ if is_macrocall && (preceding_whitespace (t) || is_closing_token (ps, k))
1396
1396
# Macro calls with space-separated arguments
1397
1397
# @foo a b ==> (macrocall @foo a b)
1398
1398
# @foo (x) ==> (macrocall @foo x)
@@ -1427,7 +1427,7 @@ function parse_call_chain(ps::ParseState, mark, is_macrocall=false)
1427
1427
emit (ps, mark, K " macrocall" )
1428
1428
end
1429
1429
break
1430
- elseif (ps. space_sensitive && t . had_whitespace &&
1430
+ elseif (ps. space_sensitive && preceding_whitespace (t) &&
1431
1431
k in KSet ` ( [ { \ Char " """ \` \`\`\` ` )
1432
1432
# [f (x)] ==> (hcat f x)
1433
1433
# [f "x"] ==> (hcat f "x")
@@ -1605,7 +1605,7 @@ function parse_call_chain(ps::ParseState, mark, is_macrocall=false)
1605
1605
emit (ps, mark, K " curly" )
1606
1606
end
1607
1607
elseif k in KSet ` " """ \` \`\`\` ` &&
1608
- ! t . had_whitespace && valid_macroname
1608
+ ! preceding_whitespace (t) && valid_macroname
1609
1609
# Custom string and command literals
1610
1610
# x"str" ==> (macrocall @x_str "str")
1611
1611
# x`str` ==> (macrocall @x_cmd "str")
@@ -1623,7 +1623,7 @@ function parse_call_chain(ps::ParseState, mark, is_macrocall=false)
1623
1623
parse_string (ps, true )
1624
1624
t = peek_token (ps)
1625
1625
k = kind (t)
1626
- if ! t . had_whitespace && (k == K " Identifier" || is_keyword (k) || is_word_operator (k) || is_number (k))
1626
+ if ! preceding_whitespace (t) && (k == K " Identifier" || is_keyword (k) || is_word_operator (k) || is_number (k))
1627
1627
# Macro sufficies can include keywords and numbers
1628
1628
# x"s"y ==> (macrocall @x_str "s" "y")
1629
1629
# x"s"end ==> (macrocall @x_str "s" "end")
@@ -2248,7 +2248,7 @@ function parse_imports(ps::ParseState)
2248
2248
k = kind (t)
2249
2249
has_import_prefix = false # true if we have `prefix:` in `import prefix: stuff`
2250
2250
has_comma = false
2251
- if k == K " :" && ! t . had_whitespace
2251
+ if k == K " :" && ! preceding_whitespace (t)
2252
2252
bump (ps, TRIVIA_FLAG)
2253
2253
has_import_prefix = true
2254
2254
if initial_as
@@ -2368,7 +2368,7 @@ function parse_import_path(ps::ParseState)
2368
2368
# path, not operators
2369
2369
# import A.== ==> (import (. A ==))
2370
2370
# import A.⋆.f ==> (import (. A ⋆ f))
2371
- if t . had_whitespace
2371
+ if preceding_whitespace (t)
2372
2372
# Whitespace in import path allowed but discouraged
2373
2373
# import A .== ==> (import (. A ==))
2374
2374
emit_diagnostic (ps, whitespace= true ,
@@ -2537,7 +2537,7 @@ end
2537
2537
# flisp: parse-generator
2538
2538
function parse_generator (ps:: ParseState , mark, flatten= false )
2539
2539
t = peek_token (ps)
2540
- if ! t . had_whitespace
2540
+ if ! preceding_whitespace (t)
2541
2541
# [(x)for x in xs] ==> (comprehension (generator x (error) (= x xs)))
2542
2542
bump_invisible (ps, K " error" , TRIVIA_FLAG,
2543
2543
error= " Expected space before `for` in generator" )
@@ -2707,7 +2707,7 @@ function parse_array_separator(ps, array_order)
2707
2707
if kind (t) != K " ;"
2708
2708
break
2709
2709
end
2710
- if t . had_whitespace
2710
+ if preceding_whitespace (t)
2711
2711
bump_disallowed_space (ps)
2712
2712
end
2713
2713
n_semis += 1
@@ -2751,7 +2751,7 @@ function parse_array_separator(ps, array_order)
2751
2751
bump (ps, TRIVIA_FLAG, error= " unexpected comma in array expression" )
2752
2752
return (1 , - 1 )
2753
2753
else
2754
- if t . had_whitespace && ! is_closing_token (ps, k)
2754
+ if preceding_whitespace (t) && ! is_closing_token (ps, k)
2755
2755
if array_order[] === :column_major
2756
2756
# Can't mix multiple ;'s and spaces
2757
2757
# v1.7: [a ;; b c] ==> (ncat-2 a (row b (error-t) c))
@@ -3252,15 +3252,15 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3252
3252
# : foo ==> (quote (error-t) foo)
3253
3253
t = peek_token (ps, 2 )
3254
3254
k = kind (t)
3255
- if is_closing_token (ps, k) && (! is_keyword (k) || t . had_whitespace )
3255
+ if is_closing_token (ps, k) && (! is_keyword (k) || preceding_whitespace (t) )
3256
3256
# : is a literal colon in some circumstances
3257
3257
# :) ==> :
3258
3258
# : end ==> :
3259
3259
bump (ps) # K":"
3260
3260
return
3261
3261
end
3262
3262
bump (ps, TRIVIA_FLAG) # K":"
3263
- if t . had_whitespace
3263
+ if preceding_whitespace (t)
3264
3264
# : a ==> (quote (error-t) a))
3265
3265
# ===
3266
3266
# :
@@ -3306,7 +3306,7 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3306
3306
end
3307
3307
elseif is_keyword (leading_kind)
3308
3308
if leading_kind == K " var" && (t = peek_token (ps,2 );
3309
- kind (t) == K "\" " && ! t . had_whitespace )
3309
+ kind (t) == K "\" " && ! preceding_whitespace (t) )
3310
3310
# var"x" ==> x
3311
3311
# Raw mode unescaping
3312
3312
# var"" ==>
@@ -3333,7 +3333,7 @@ function parse_atom(ps::ParseState, check_identifiers=true)
3333
3333
end
3334
3334
t = peek_token (ps)
3335
3335
k = kind (t)
3336
- if t . had_whitespace || is_operator (k) ||
3336
+ if preceding_whitespace (t) || is_operator (k) ||
3337
3337
k in KSet ` ( ) [ ] { } , ; @ EndMarker`
3338
3338
# var"x"+ ==> x
3339
3339
# var"x") ==> x
0 commit comments