Skip to content

Commit 7c29bc2

Browse files
authored
Allow the syntax import A.:x for import A.x (#177)
This syntax is unnecessary but does occur ~10 times in the General registry so we should support it.
1 parent eb9fd05 commit 7c29bc2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/parser.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,12 @@ function parse_import_path(ps::ParseState)
25202520
# import A.B.C ==> (import (. A B C))
25212521
bump_disallowed_space(ps)
25222522
bump(ps, TRIVIA_FLAG)
2523+
if peek(ps) == K":"
2524+
# import A.:+ ==> (import (. A +))
2525+
bump_disallowed_space(ps)
2526+
emit_diagnostic(ps, warning="quoting with `:` in import is unnecessary")
2527+
bump(ps, TRIVIA_FLAG)
2528+
end
25232529
parse_atsym(ps)
25242530
elseif is_dotted(t)
25252531
# Resolve tokenization ambiguity: In imports, dots are part of the
@@ -2534,10 +2540,6 @@ function parse_import_path(ps::ParseState)
25342540
end
25352541
bump_trivia(ps)
25362542
bump_split(ps, (1,K".",TRIVIA_FLAG), (1,k,EMPTY_FLAGS))
2537-
# elseif k == K".."
2538-
# # The flisp parser does this, but it's nonsense?
2539-
# # import A.. !=> (import (. A .))
2540-
# bump_split(ps, (1,K".",TRIVIA_FLAG), (1,K".",EMPTY_FLAGS))
25412543
elseif k == K"..."
25422544
# Import the .. operator
25432545
# import A... ==> (import (. A ..))

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ tests = [
614614
"import \$A.@x" => "(import (. (\$ A) @x))"
615615
"import A.B" => "(import (. A B))"
616616
"import A.B.C" => "(import (. A B C))"
617+
"import A.:+" => "(import (. A +))"
617618
"import A.==" => "(import (. A ==))"
618619
"import A.⋆.f" => "(import (. A ⋆ f))"
619620
"import A..." => "(import (. A ..))"

0 commit comments

Comments
 (0)