@@ -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))
@@ -2379,7 +2364,7 @@ end
2379
2364
# Parse an identifier, interpolation or @-prefixed symbol
2380
2365
#
2381
2366
# flisp: parse-atsym
2382
- function parse_atsym (ps:: ParseState )
2367
+ function parse_atsym (ps:: ParseState , allow_quotes = true )
2383
2368
bump_trivia (ps)
2384
2369
if peek (ps) == K " @"
2385
2370
# export @a ==> (export @a)
@@ -2392,7 +2377,30 @@ function parse_atsym(ps::ParseState)
2392
2377
# export a ==> (export a)
2393
2378
# export \n a ==> (export a)
2394
2379
# export $a, $(a*b) ==> (export ($ a) (parens ($ (call * a b))))
2395
- 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
2396
2404
end
2397
2405
end
2398
2406
@@ -2524,12 +2532,6 @@ function parse_import_path(ps::ParseState)
2524
2532
# import A.B.C ==> (import (. A B C))
2525
2533
bump_disallowed_space (ps)
2526
2534
bump (ps, TRIVIA_FLAG)
2527
- if peek (ps) == K " :"
2528
- # import A.:+ ==> (import (. A +))
2529
- bump_disallowed_space (ps)
2530
- emit_diagnostic (ps, warning= " quoting with `:` in import is unnecessary" )
2531
- bump (ps, TRIVIA_FLAG)
2532
- end
2533
2535
parse_atsym (ps)
2534
2536
elseif is_dotted (t)
2535
2537
# Resolve tokenization ambiguity: In imports, dots are part of the
0 commit comments