Skip to content

Commit 1b26c92

Browse files
authored
improve package syntax parsing a bit (#4227)
1 parent cf2d47a commit 1b26c92

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/REPLMode/argument_parsers.jl

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ let url = raw"((git|ssh|http(s)?)|(git@[\w\-\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git
5757
name_uuid = raw"[^@\#\s:]+\s*=\s*[^@\#\s:]+",
5858

5959
# Match a `#BRANCH` branch or tag specifier.
60-
branch = raw"\#\s*[^@\#\s]*",
60+
branch = raw"\#\s*[^@^:\s]+",
6161

6262
# Match an `@VERSION` version specifier.
6363
version = raw"@\s*[^@\#\s]*",
@@ -94,19 +94,34 @@ function parse_package_args(args::Vector{PackageToken}; add_or_dev=false)::Vecto
9494
# check for and apply PackageSpec modifier (e.g. `#foo` or `@v1.0.2`)
9595
function apply_modifier!(pkg::PackageSpec, args::Vector{PackageToken})
9696
(isempty(args) || args[1] isa PackageIdentifier) && return
97-
modifier = popfirst!(args)
98-
if modifier isa Subdir
99-
pkg.subdir = modifier.dir
100-
(isempty(args) || args[1] isa PackageIdentifier) && return
97+
parsed_subdir = false
98+
parsed_version = false
99+
parsed_rev = false
100+
while !isempty(args)
101101
modifier = popfirst!(args)
102-
end
103-
104-
if modifier isa VersionToken
105-
pkg.version = modifier.version
106-
elseif modifier isa Rev
107-
pkg.rev = modifier.rev
108-
else
109-
pkgerror("Package name/uuid must precede subdir specifier `$args`.")
102+
if modifier isa Subdir
103+
if parsed_subdir
104+
pkgerror("Multiple subdir specifiers `$args` found.")
105+
end
106+
pkg.subdir = modifier.dir
107+
(isempty(args) || args[1] isa PackageIdentifier) && return
108+
modifier = popfirst!(args)
109+
parsed_subdir = true
110+
elseif modifier isa VersionToken
111+
if parsed_version
112+
pkgerror("Multiple version specifiers `$args` found.")
113+
end
114+
pkg.version = modifier.version
115+
parsed_version = true
116+
elseif modifier isa Rev
117+
if parsed_rev
118+
pkgerror("Multiple revision specifiers `$args` found.")
119+
end
120+
pkg.rev = modifier.rev
121+
parsed_rev = true
122+
else
123+
pkgerror("Package name/uuid must precede subdir specifier `$args`.")
124+
end
110125
end
111126
end
112127

test/new.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ end
439439
arg = args[1]
440440
@test arg.url == "https://github.com/JuliaLang/Pkg.jl"
441441
@test arg.rev == "aa/gitlab"
442+
443+
api, args, opts = first(Pkg.pkg"add https://github.com/TimG1964/XLSX.jl#Bug-fixing-post-#289:subdir")
444+
arg = args[1]
445+
@test arg.url == "https://github.com/TimG1964/XLSX.jl"
446+
@test arg.rev == "Bug-fixing-post-#289"
447+
@test arg.subdir == "subdir"
442448
end
443449
end
444450

0 commit comments

Comments
 (0)