guix: opam: Fix syntax.

* guix/import/opam.scm (STRCHR, comment, choice): Fix syntax.
(group-pat): Add syntax.
(opam->guix-package): Suppport "archive" keyword.
This commit is contained in:
Julien Lepiller 2020-10-01 15:05:05 +02:00
parent d40c9f6c85
commit f4390d391b
No known key found for this signature in database
GPG key ID: 53D457B2D636EE82

View file

@ -49,16 +49,19 @@ (define-module (guix import opam)
condition)) condition))
;; Define a PEG parser for the opam format ;; Define a PEG parser for the opam format
(define-peg-pattern comment none (and "#" (* STRCHR) "\n")) (define-peg-pattern comment none (and "#" (* COMMCHR) "\n"))
(define-peg-pattern SP none (or " " "\n" comment)) (define-peg-pattern SP none (or " " "\n" comment))
(define-peg-pattern SP2 body (or " " "\n")) (define-peg-pattern SP2 body (or " " "\n"))
(define-peg-pattern QUOTE none "\"") (define-peg-pattern QUOTE none "\"")
(define-peg-pattern QUOTE2 body "\"") (define-peg-pattern QUOTE2 body "\"")
(define-peg-pattern COLON none ":") (define-peg-pattern COLON none ":")
;; A string character is any character that is not a quote, or a quote preceded by a backslash. ;; A string character is any character that is not a quote, or a quote preceded by a backslash.
(define-peg-pattern COMMCHR none
(or " " "!" "\\" "\"" (range #\# #\頋)))
(define-peg-pattern STRCHR body (define-peg-pattern STRCHR body
(or " " "!" "\n" (and (ignore "\\") "\"") (or " " "!" "\n" (and (ignore "\\") "\"")
(and (ignore "\\") "\\") (range #\# #\頋))) (ignore "\\\n") (and (ignore "\\") "\\")
(range #\# #\頋)))
(define-peg-pattern operator all (or "=" "!" "<" ">")) (define-peg-pattern operator all (or "=" "!" "<" ">"))
(define-peg-pattern records body (* (and (or record weird-record) (* SP)))) (define-peg-pattern records body (* (and (or record weird-record) (* SP))))
@ -69,8 +72,12 @@ (define-peg-pattern value body (and (or conditional-value ground-value operator)
(define-peg-pattern choice-pat all (and (ignore "(") (* SP) choice (* SP) (ignore ")"))) (define-peg-pattern choice-pat all (and (ignore "(") (* SP) choice (* SP) (ignore ")")))
(define-peg-pattern choice body (define-peg-pattern choice body
(or (and (or conditional-value ground-value) (* SP) (ignore "|") (* SP) choice) (or (and (or conditional-value ground-value) (* SP) (ignore "|") (* SP) choice)
group-pat
conditional-value conditional-value
ground-value)) ground-value))
(define-peg-pattern group-pat body
(and ground-value (* SP) (ignore "&") (* SP)
(or group-pat conditional-value ground-value)))
(define-peg-pattern ground-value body (and (or multiline-string string-pat choice-pat list-pat var) (* SP))) (define-peg-pattern ground-value body (and (or multiline-string string-pat choice-pat list-pat var) (* SP)))
(define-peg-pattern conditional-value all (and ground-value (* SP) condition)) (define-peg-pattern conditional-value all (and ground-value (* SP) condition))
(define-peg-pattern string-pat all (and QUOTE (* STRCHR) QUOTE)) (define-peg-pattern string-pat all (and QUOTE (* STRCHR) QUOTE))
@ -258,7 +265,8 @@ (define* (opam->guix-package name #:key (repository (get-opam-repository)))
(version (assoc-ref opam-file "version")) (version (assoc-ref opam-file "version"))
(opam-content (assoc-ref opam-file "metadata")) (opam-content (assoc-ref opam-file "metadata"))
(url-dict (metadata-ref opam-content "url")) (url-dict (metadata-ref opam-content "url"))
(source-url (metadata-ref url-dict "src")) (source-url (or (metadata-ref url-dict "src")
(metadata-ref url-dict "archive")))
(requirements (metadata-ref opam-content "depends")) (requirements (metadata-ref opam-content "depends"))
(dependencies (dependency-list->names requirements)) (dependencies (dependency-list->names requirements))
(native-dependencies (depends->native-inputs requirements)) (native-dependencies (depends->native-inputs requirements))
@ -308,7 +316,7 @@ (define* (opam->guix-package name #:key (repository (get-opam-repository)))
(filter (filter
(lambda (name) (lambda (name)
(not (member name '("dune" "jbuilder")))) (not (member name '("dune" "jbuilder"))))
dependencies)))))))) dependencies))))))))
(define (opam-recursive-import package-name) (define (opam-recursive-import package-name)
(recursive-import package-name #f (recursive-import package-name #f