semver.scm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ;;; guile-semver --- Semantic Version tooling for guile
  2. ;;; Copyright © 2017 Jelle Dirk Licht <jlicht@fsfe.org>
  3. ;;;
  4. ;;; This file is part of guile-semver.
  5. ;;;
  6. ;;; guile-semver is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; guile-semver is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;;; General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with guile-semver. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (semver)
  19. #:use-module (semver parser)
  20. #:use-module (semver parser-range)
  21. #:use-module (semver matcher)
  22. #:use-module (semver comparator)
  23. #:export (parse-semver
  24. valid?
  25. satisfies
  26. gt
  27. lt))
  28. (define (parse-semver str)
  29. (let ((ast (parse-string str)))
  30. (ast->semantic-version ast)))
  31. (define (valid? version-str)
  32. (parse-semver version-str))
  33. (define (satisfies version-str range-str)
  34. (let ((range (parse-semver-range range-str))
  35. (version (parse-semver version-str)))
  36. ((semver-range-matcher range) version)))
  37. (define (gt version-str1 version-str2)
  38. (= 1 (semantic-version-compare (parse-semver version-str1)
  39. (parse-semver version-str2))))
  40. (define (lt version-str1 version-str2)
  41. (= -1 (semantic-version-compare (parse-semver version-str1)
  42. (parse-semver version-str2))))