@@ -1444,21 +1444,6 @@ function parse_unary_prefix(ps::ParseState)
1444
1444
end
1445
1445
end
1446
1446
1447
- # Parse a symbol or interpolation syntax
1448
- function parse_identifier_or_interpolate (ps:: ParseState )
1449
- mark = position (ps)
1450
- parse_unary_prefix (ps)
1451
- b = peek_behind (ps)
1452
- # export (x::T) ==> (export (error (parens (::-i x T))))
1453
- # export outer ==> (export outer)
1454
- # export ($f) ==> (export ($ f))
1455
- ok = (b. is_leaf && (b. kind == K " Identifier" || is_operator (b. kind))) ||
1456
- (! b. is_leaf && b. kind in KSet " $ var" )
1457
- if ! ok
1458
- emit (ps, mark, K " error" , error= " Expected identifier" )
1459
- end
1460
- end
1461
-
1462
1447
# Parses a chain of sufficies at function call precedence, leftmost binding
1463
1448
# tightest. This handles
1464
1449
# * Bracketed calls like a() b[] c{}
@@ -2008,7 +1993,7 @@ function parse_resword(ps::ParseState)
2008
1993
# export \n a ==> (export a)
2009
1994
# export \$a, \$(a*b) ==> (export (\$ a) (\$ (parens (call-i a * b))))
2010
1995
bump (ps, TRIVIA_FLAG)
2011
- parse_comma_separated (ps, parse_atsym)
1996
+ parse_comma_separated (ps, x -> parse_atsym (x, false ) )
2012
1997
emit (ps, mark, K " export" )
2013
1998
elseif word in KSet " import using"
2014
1999
parse_imports (ps)
@@ -2098,7 +2083,7 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
2098
2083
mark = position (ps)
2099
2084
if ! is_function
2100
2085
# Parse macro name
2101
- parse_identifier_or_interpolate (ps)
2086
+ parse_unary_prefix (ps)
2102
2087
kb = peek_behind (ps). orig_kind
2103
2088
if is_initial_reserved_word (ps, kb)
2104
2089
# macro while(ex) end ==> (macro (call (error while) ex) (block))
@@ -2111,7 +2096,9 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
2111
2096
# macro ($f)() end ==> (macro (call (parens ($ f))) (block))
2112
2097
end
2113
2098
else
2114
- if peek (ps) == K " ("
2099
+ if peek (ps) != K " ("
2100
+ parse_unary_prefix (ps)
2101
+ else
2115
2102
# When an initial parenthesis is present, we might either have
2116
2103
# * the function name in parens, followed by (args...)
2117
2104
# * an anonymous function argument list in parens
@@ -2151,14 +2138,12 @@ function parse_function_signature(ps::ParseState, is_function::Bool)
2151
2138
# function (::T)() end ==> (function (call (parens (::-pre T))) (block))
2152
2139
emit (ps, mark, K " parens" , PARENS_FLAG)
2153
2140
end
2154
- else
2155
- parse_unary_prefix (ps)
2156
2141
end
2157
2142
if ! is_anon_func
2158
2143
kb = peek_behind (ps). orig_kind
2159
2144
if is_reserved_word (kb)
2160
2145
# function begin() end ==> (function (call (error begin)) (block))
2161
- emit (ps, mark, K " error" , error= " Invalid function name" )
2146
+ emit (ps, mark, K " error" , error= " invalid function name" )
2162
2147
else
2163
2148
# function f() end ==> (function (call f) (block))
2164
2149
# function type() end ==> (function (call type) (block))
@@ -2335,18 +2320,10 @@ function fix_macro_name_kind!(ps::ParseState, macro_name_position, name_kind=not
2335
2320
if k == K " var"
2336
2321
macro_name_position = first_child_position (ps, macro_name_position)
2337
2322
k = peek_behind (ps, macro_name_position). kind
2338
- elseif k == K " )"
2339
- # @(A) x => (macrocall @A x)
2340
- # TODO : Clean this up when K"parens" is implemented
2341
- while true
2342
- macro_name_position = ParseStreamPosition (macro_name_position. token_index- 1 ,
2343
- macro_name_position. range_index- 1 )
2344
- b = peek_behind (ps, macro_name_position)
2345
- k = b. kind
2346
- if ! has_flags (b. flags, TRIVIA_FLAG)
2347
- break
2348
- end
2349
- end
2323
+ elseif k == K " parens"
2324
+ # @(A) x ==> (macrocall (parens @A) x)
2325
+ macro_name_position = first_child_position (ps, macro_name_position)
2326
+ k = peek_behind (ps, macro_name_position). kind
2350
2327
elseif k == K " error"
2351
2328
# Error already reported in parse_macro_name
2352
2329
return
@@ -2373,12 +2350,12 @@ function parse_macro_name(ps::ParseState)
2373
2350
# @var"#" x ==> (macrocall (var #) @$ x)
2374
2351
bump_disallowed_space (ps)
2375
2352
mark = position (ps)
2376
- k = peek (ps)
2377
2353
parse_atom (ps, false )
2378
- if k == K " ("
2354
+ kb = peek_behind (ps, position (ps)). kind
2355
+ if kb == K " parens"
2379
2356
emit_diagnostic (ps, mark,
2380
2357
warning= " parenthesizing macro names is unnecessary" )
2381
- elseif ! (peek_behind (ps) . kind in KSet " Identifier var" )
2358
+ elseif ! (kb in KSet " Identifier var" )
2382
2359
# @[x] y z ==> (macrocall (error (vect x)) y z)
2383
2360
emit (ps, mark, K " error" , error= " invalid macro name" )
2384
2361
end
@@ -2387,7 +2364,7 @@ end
2387
2364
# Parse an identifier, interpolation or @-prefixed symbol
2388
2365
#
2389
2366
# flisp: parse-atsym
2390
- function parse_atsym (ps:: ParseState )
2367
+ function parse_atsym (ps:: ParseState , allow_quotes = true )
2391
2368
bump_trivia (ps)
2392
2369
if peek (ps) == K " @"
2393
2370
# export @a ==> (export @a)
@@ -2400,7 +2377,30 @@ function parse_atsym(ps::ParseState)
2400
2377
# export a ==> (export a)
2401
2378
# export \n a ==> (export a)
2402
2379
# export $a, $(a*b) ==> (export ($ a) (parens ($ (call * a b))))
2403
- parse_identifier_or_interpolate (ps)
2380
+ # export (x::T) ==> (export (error (parens (::-i x T))))
2381
+ # export outer ==> (export outer)
2382
+ # export ($f) ==> (export ($ f))
2383
+ mark = position (ps)
2384
+ if allow_quotes && peek (ps) == K " :"
2385
+ # import A.:+ ==> (import (. A (quote +)))
2386
+ emit_diagnostic (ps, warning= " quoting with `:` is not required here" )
2387
+ end
2388
+ parse_unary_prefix (ps)
2389
+ pos = position (ps)
2390
+ while peek_behind (ps, pos). kind == K " parens"
2391
+ # import A.(:+) ==> (import (. A (parens (quote +))))
2392
+ pos = first_child_position (ps, pos)
2393
+ emit_diagnostic (ps, mark, warning= " parentheses are not required here" )
2394
+ end
2395
+ if allow_quotes && peek_behind (ps, pos). kind == K " quote"
2396
+ pos = first_child_position (ps, pos)
2397
+ end
2398
+ b = peek_behind (ps, pos)
2399
+ ok = (b. is_leaf && (b. kind == K " Identifier" || is_operator (b. kind))) ||
2400
+ (! b. is_leaf && b. kind in KSet " $ var" )
2401
+ if ! ok
2402
+ emit (ps, mark, K " error" , error= " expected identifier" )
2403
+ end
2404
2404
end
2405
2405
end
2406
2406
@@ -2532,12 +2532,6 @@ function parse_import_path(ps::ParseState)
2532
2532
# import A.B.C ==> (import (. A B C))
2533
2533
bump_disallowed_space (ps)
2534
2534
bump (ps, TRIVIA_FLAG)
2535
- if peek (ps) == K " :"
2536
- # import A.:+ ==> (import (. A +))
2537
- bump_disallowed_space (ps)
2538
- emit_diagnostic (ps, warning= " quoting with `:` in import is unnecessary" )
2539
- bump (ps, TRIVIA_FLAG)
2540
- end
2541
2535
parse_atsym (ps)
2542
2536
elseif is_dotted (t)
2543
2537
# Resolve tokenization ambiguity: In imports, dots are part of the
0 commit comments