Skip to content

Commit 8cf8727

Browse files
authored
Parse standalone .& as (. &) (#14)
1 parent ee771f8 commit 8cf8727

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/parser.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@ function is_both_unary_and_binary(t)
304304
end
305305

306306
# operators handled by parse_unary at the start of an expression
307-
function is_initial_operator(k)
308-
k = kind(k)
307+
function is_initial_operator(t)
308+
k = kind(t)
309309
# TODO(jb): `?` should probably not be listed here except for the syntax hack in osutils.jl
310310
is_operator(k) &&
311311
!is_word_operator(k) &&
312312
!(k in KSet`: ' .' ?`) &&
313-
!is_syntactic_unary_op(k) &&
313+
!(is_syntactic_unary_op(k) && !is_dotted(t)) &&
314314
!is_syntactic_operator(k)
315315
end
316316

@@ -1078,8 +1078,9 @@ end
10781078
function parse_unary(ps::ParseState)
10791079
mark = position(ps)
10801080
bump_trivia(ps)
1081-
k = peek(ps)
1082-
if !is_initial_operator(k)
1081+
t = peek_token(ps)
1082+
k = kind(t)
1083+
if !is_initial_operator(t)
10831084
# :T ==> (quote T)
10841085
# in::T ==> (:: in T)
10851086
# isa::T ==> (:: isa T)
@@ -1128,16 +1129,17 @@ function parse_unary_call(ps::ParseState)
11281129
k2 = kind(t2)
11291130
if is_closing_token(ps, k2) || k2 in KSet`NewlineWs =`
11301131
if is_dotted(op_t)
1131-
# standalone dotted operators are parsed as (|.| op)
1132+
# Standalone dotted operators are parsed as (|.| op)
11321133
# .+ ==> (. +)
11331134
# .+\n ==> (. +)
11341135
# .+ = ==> (. +)
11351136
# .+) ==> (. +)
1137+
# .& ==> (. &)
11361138
bump_trivia(ps)
11371139
bump_split(ps, (1, K".", TRIVIA_FLAG), (0, op_k, EMPTY_FLAGS))
11381140
emit(ps, mark, K".")
11391141
else
1140-
# return operator by itself, as in
1142+
# Standalone non-dotted operators
11411143
# +) ==> +
11421144
bump(ps)
11431145
end

test/parser.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ tests = [
156156
".+\n" => "(. +)"
157157
".+ =" => "(. +)"
158158
".+)" => "(. +)"
159+
".&" => "(. &)"
160+
# Standalone non-dotted operators
159161
"+)" => "+"
160162
# Call with type parameters or non-unary prefix call
161163
"+{T}(x::T)" => "(call (curly + T) (:: x T))"

0 commit comments

Comments
 (0)