<commit_before>;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
;;;
;;; --- New pathnames.
;;;

(in-package :iolib.pathnames)

;;;-------------------------------------------------------------------------
;;; Classes and Types
;;;-------------------------------------------------------------------------

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defconstant +file-path-host-type+
    #+unix    'unix-path
    #+windows 'unc-path))

(defclass file-path ()
  ((host :initarg :host)
   (device :initarg :device)
   (components :initarg :components
               :initform nil)
   (trailing-delimiter :initarg :trailing-delimiter
                       :initform nil
                       :reader file-path-trailing-delimiter)))

(deftype file-path-designator ()
  `(or ,+file-path-host-type+ string ustring))

(define-condition invalid-file-path (isys:iolib-error)
  ((path :initarg :path :reader invalid-file-path-path)
   (reason :initform nil :initarg :reason :reader invalid-file-path-reason))
  (:report (lambda (condition stream)
             (format stream "Invalid file path: ~S."
                     (ustring-to-string*
                      (ustring
                       (invalid-file-path-path condition))))
             (when-let (reason (invalid-file-path-reason condition))
               (format stream "~%~A." reason)))))



;;;-------------------------------------------------------------------------
;;; Constants
;;;-------------------------------------------------------------------------

(defconstant +directory-delimiter+
  #+unix    (uchar #\/)
  #+windows (uchar #\\))

(defconstant +alternative-delimiter+
  #+unix    nil
  #+windows (uchar #\/))

(defconstant (+directory-delimiters+ :test #'equal)
  (list* +directory-delimiter+ +alternative-delimiter+))

(defconstant +execution-path-delimiter+
  #+unix    (uchar #\:)
  #+windows (uchar #\;))

(declaim (special *default-file-path-defaults*))



;;;-------------------------------------------------------------------------
;;; Generic Functions
;;;-------------------------------------------------------------------------

;;; Accessors

(defgeneric file-path-host (path &key namestring))

(defgeneric file-path-device (path &key namestring))

(defgeneric file-path-components (path &key namestring))

(defgeneric file-path-directory (path &key namestring))

(defgeneric file-path-file (path &key namestring))

(defgeneric file-path-file-name (path))

(defgeneric file-path-file-type (path))

(defgeneric file-path-namestring (path))

;;; Operations

(defgeneric make-file-path (&key host device components defaults))

(defgeneric merge-file-paths (path &optional defaults))

(defgeneric enough-file-path (path &optional defaults))

(defgeneric file-path (pathspec))

(defgeneric parse-file-path (pathspec &key start end as-directory expand-user))

(defgeneric expand-user-directory (path))

;;; Internal functions

(defgeneric %file-path-host-namestring (path))

(defgeneric %file-path-device-namestring (path))

(defgeneric %file-path-components-namestring
    (path &key print-dot trailing-delimiter))

(defgeneric %file-path-directory-namestring (path))

(defgeneric %file-path-file-namestring (path))

(defgeneric %expand-user-directory (pathspec))



;;;-------------------------------------------------------------------------
;;; Accessors
;;;-------------------------------------------------------------------------

(defmethod file-path-host ((path file-path) &key namestring)<commit_msg>Add missing DEFGENERIC.<commit_after>;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
;;;
;;; --- New pathnames.
;;;

(in-package :iolib.pathnames)

;;;-------------------------------------------------------------------------
;;; Classes and Types
;;;-------------------------------------------------------------------------

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defconstant +file-path-host-type+
    #+unix    'unix-path
    #+windows 'unc-path))

(defclass file-path ()
  ((host :initarg :host)
   (device :initarg :device)
   (components :initarg :components
               :initform nil)
   (trailing-delimiter :initarg :trailing-delimiter
                       :initform nil
                       :reader file-path-trailing-delimiter)))

(deftype file-path-designator ()
  `(or ,+file-path-host-type+ string ustring))

(define-condition invalid-file-path (isys:iolib-error)
  ((path :initarg :path :reader invalid-file-path-path)
   (reason :initform nil :initarg :reason :reader invalid-file-path-reason))
  (:report (lambda (condition stream)
             (format stream "Invalid file path: ~S."
                     (ustring-to-string*
                      (ustring
                       (invalid-file-path-path condition))))
             (when-let (reason (invalid-file-path-reason condition))
               (format stream "~%~A." reason)))))



;;;-------------------------------------------------------------------------
;;; Constants
;;;-------------------------------------------------------------------------

(defconstant +directory-delimiter+
  #+unix    (uchar #\/)
  #+windows (uchar #\\))

(defconstant +alternative-delimiter+
  #+unix    nil
  #+windows (uchar #\/))

(defconstant (+directory-delimiters+ :test #'equal)
  (list* +directory-delimiter+ +alternative-delimiter+))

(defconstant +execution-path-delimiter+
  #+unix    (uchar #\:)
  #+windows (uchar #\;))

(declaim (special *default-file-path-defaults*))



;;;-------------------------------------------------------------------------
;;; Generic Functions
;;;-------------------------------------------------------------------------

;;; Accessors

(defgeneric file-path-host (path &key namestring))

(defgeneric file-path-device (path &key namestring))

(defgeneric file-path-components (path &key namestring))

(defgeneric file-path-directory (path &key namestring))

(defgeneric file-path-file (path &key namestring))

(defgeneric file-path-file-name (path))

(defgeneric file-path-file-type (path))

(defgeneric file-path-namestring (path))

;;; Operations

(defgeneric make-file-path (&key host device components defaults))

(defgeneric merge-file-paths (path &optional defaults))

(defgeneric enough-file-path (path &optional defaults))

(defgeneric file-path (pathspec))

(defgeneric parse-file-path (pathspec &key start end as-directory expand-user))

(defgeneric expand-user-directory (path))

;;; Internal functions

(defgeneric file-path-namestring/ustring (path))

(defgeneric %file-path-host-namestring (path))

(defgeneric %file-path-device-namestring (path))

(defgeneric %file-path-components-namestring
    (path &key print-dot trailing-delimiter))

(defgeneric %file-path-directory-namestring (path))

(defgeneric %file-path-file-namestring (path))

(defgeneric %expand-user-directory (pathspec))



;;;-------------------------------------------------------------------------
;;; Accessors
;;;-------------------------------------------------------------------------

(defmethod file-path-host ((path file-path) &key namestring)
{'fraction_non_alphanumeric': 0.2963380281690141, 'fraction_numerical': 0.0, 'mean_word_length': 1.89010989010989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5422304', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1966, 'n_words': 434}