[ fix #1148 ] Support hyphenated package names (#1151)

This commit is contained in:
Stefan Höck 2021-03-04 20:09:15 +01:00 committed by GitHub
parent d952741563
commit 4c7d0db4bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 17 deletions

View File

@ -109,6 +109,7 @@ modules =
Libraries.Data.LengthMatch,
Libraries.Data.List.Extra,
Libraries.Data.List.Lazy,
Libraries.Data.List1,
Libraries.Data.NameMap,
Libraries.Data.SortedMap,
Libraries.Data.SortedSet,

View File

@ -86,6 +86,13 @@ export
snoc : (xs : List1 a) -> (x : a) -> List1 a
snoc xs x = append xs (singleton x)
public export
unsnoc : (xs : List1 a) -> (List a, a)
unsnoc (h ::: Nil) = (Nil, h)
unsnoc (h ::: (x :: xs)) =
let (ini,lst) = unsnoc (x ::: xs)
in (h :: ini, lst)
------------------------------------------------------------------------
-- Reverse

View File

@ -6,6 +6,7 @@ import Core.Metadata
import Core.Options
import Core.Unify
import Libraries.Utils.Path
import Libraries.Data.List1 as Lib
import Idris.CommandLine
import Idris.REPL
@ -33,23 +34,26 @@ candidateDirs dname pkg bounds
| Left err => pure []
getFiles d []
where
toVersionNum : String -> List Nat
toVersionNum str
= case span (/= '.') str of
(num, rest) =>
case strM rest of
StrNil => [stringToNatOrZ num]
StrCons _ rest =>
(stringToNatOrZ num :: toVersionNum rest)
toVersion : String -> Maybe PkgVersion
toVersion = map MkPkgVersion
. traverse parsePositive
. forget
. split (== '.')
getVersion : String -> (String, PkgVersion)
getVersion str
= case span (/= '-') str of
(name, ver) => case strM ver of
StrNil => (name, MkPkgVersion [0])
StrCons _ ver =>
(name, MkPkgVersion (toVersionNum ver))
_ => (str, MkPkgVersion [0])
getVersion str =
-- Split the dir name into parts concatenated by "-"
-- treating the last part as the version number
-- and the initial parts as the package name.
-- For reasons of backwards compatibility, we also
-- accept hyphenated directory names without a part
-- corresponding to a version number.
case Lib.unsnoc $ split (== '-') str of
(Nil, last) => (last, MkPkgVersion [0])
(init,last) =>
case toVersion last of
Just v => (concat $ intersperse "-" init, v)
Nothing => (str, MkPkgVersion [0])
-- Return a list of paths that match the version spec
-- (full name, version string)

View File

@ -0,0 +1,14 @@
module Libraries.Data.List1
import public Data.List1
%default total
-- TODO: Remove this, once Data.List1.unsnoc from base is available
-- to the compiler
export
unsnoc : (xs : List1 a) -> (List a, a)
unsnoc (h ::: Nil) = (Nil, h)
unsnoc (h ::: (x :: xs)) =
let (ini,lst) = Libraries.Data.List1.unsnoc (x ::: xs)
in (h :: ini, lst)

View File

@ -0,0 +1,2 @@
package bar-baz
version = 1.0.1

View File

@ -0,0 +1,2 @@
package foo-bar
version = 1.3.1

View File

@ -0,0 +1,2 @@
package quux
version = 0.0.0

View File

@ -1,3 +1,3 @@
package test1
depends = foo, bar
depends = foo, bar, foo-bar, quux, bar-baz

View File

@ -1,4 +1,8 @@
package test2
depends = foo >= 0.5 && < 0.6,
bar >= 1
bar >= 1,
foo-bar == 1.3.1,
quux == 0,
bar-baz == 0