Skip to content

Commit 108b6c9

Browse files
authored
Fix parsing of [a~b] (#137)
In space sensitive contexts, `~` is parsed as unary or binary depending on whitespace to the left and right of the `~`. In this case it should be binary and parse as `(ref (call-i ~ a b))`
1 parent 772c288 commit 108b6c9

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/parser.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,15 @@ function parse_assignment_with_initial_ex(ps::ParseState, mark, down::T) where {
566566
return
567567
end
568568
if k == K"~"
569-
if ps.space_sensitive && !preceding_whitespace(peek_token(ps, 2))
569+
if ps.space_sensitive && preceding_whitespace(t) && !preceding_whitespace(peek_token(ps, 2))
570570
# Unary ~ in space sensitive context is not assignment precedence
571571
# [a ~b] ==> (hcat a (call-pre ~ b))
572572
return
573573
end
574574
# ~ is the only non-syntactic assignment-precedence operator.
575575
# a ~ b ==> (call-i a ~ b)
576576
# [a ~ b c] ==> (hcat (call-i a ~ b) c)
577+
# [a~b] ==> (vect (call-i a ~ b))
577578
bump(ps)
578579
parse_assignment(ps, down)
579580
emit(ps, mark, K"call", INFIX_FLAG)

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tests = [
5151
"[a ~b]" => "(hcat a (call-pre ~ b))"
5252
"a ~ b" => "(call-i a ~ b)"
5353
"[a ~ b c]" => "(hcat (call-i a ~ b) c)"
54+
"[a~b]" => "(vect (call-i a ~ b))"
5455
],
5556
JuliaSyntax.parse_pair => [
5657
"a => b" => "(call-i a => b)"

0 commit comments

Comments
 (0)