<commit_before>(in-package :vari.cl)

(defvar *vari-additional-form-docs*
  (make-hash-table :test #'eq))

(defun janky-parse-name (str)
  (flet ((inner (str)
           (let* ((pos (position #\: str :test #'char=)))
             (cond
               ((null pos) (find-symbol str *package*))
               ((= pos 0) (find-symbol (subseq str 1) :keyword))
               (t
                (let ((pkg (find-package (subseq str 0 pos))))
                  (when pkg
                    (find-symbol (subseq str (1+ pos)) pkg))))))))
    (values
     (or (inner str)
         (inner (string-upcase str))))))

(defun vari-describe (name &optional (stream *standard-output*))
  (flet ((get-overload-signatures (symb-name func-set)
           (let ((funcs (when func-set (functions func-set))))
             (loop
                :for func :in funcs
                :for spec := (v-argument-spec func)
                :for sig := (handler-case
                                (cons symb-name
                                      (loop :for type :in spec :collect
                                         (type->type-spec type)))
                              (error () nil))
                :when sig :collect sig)))
         (format-glsl-func-doc (glsl-doc)
           (let* ((decl (search "Declaration" glsl-doc))
                  (param (search "Parameters" glsl-doc)))
             (if (and decl param)
                 (format nil "Official GLSL Documentaion:~%~%~a~a"
                         (subseq glsl-doc 0 decl)
                         (subseq glsl-doc param))
                 (format nil "Official GLSL Documentaion:~%~%~a" glsl-doc))))
         (try-get-var-type (name)
           (let ((spec
                  (loop :for (nil . vars) :in varjo.internals::*glsl-variables*
                     :for match := (find name vars :key #'first)
                     :when match :return (third match))))
             (varjo.internals::alternate-name-for spec))))

    (let* ((name (if (stringp name)
                     (janky-parse-name name)
                     name))
           (var (gethash name glsl-docs:*variables*))
           (form-binding-set
            (unless var
              (varjo.internals::find-global-form-binding-by-literal name t))))
      (cond
        (var
         (format stream
                 "~a~%~%~@[Type:~%~%~s~%~%~]Official GLSL Documentaion:~%~%~a"
                 name
                 (try-get-var-type name)
                 var))
        (form-binding-set
         (let* ((glsl-doc (gethash name glsl-docs:*functions*))
                (v-doc (gethash name *vari-additional-form-docs*))
                (overloads (get-overload-signatures name form-binding-set))
                (doc (cond
                       (v-doc v-doc)
                       (glsl-doc
                        (format-glsl-func-doc glsl-doc)))))
           (format stream "~a~%~%~@[Overloads:~%~{~s~%~}~]~@[~%~a~]"
                   name
                   overloads
                   doc)))))))

(setf (gethash '* *vari-additional-form-docs*)
      "Return the product of its arguments. With no args, returns 1.")

(setf (gethash '+ *vari-additional-form-docs*)
      "Return the sum of its arguments. With no args, returns 0.")

(setf (gethash '- *vari-additional-form-docs*)
      "Subtract the second and all subsequent arguments from the first;
  or with one argument, negate the first argument.")

(setf (gethash '/ *vari-additional-form-docs*)
      "Divide the first argument by each of the following arguments, in turn.
  With one argument, return reciprocal.")

(setf (gethash '/= *vari-additional-form-docs*)
      "Return T if no two of its arguments are numerically equal, NIL otherwise.")<commit_msg>fixes for vari-describe<commit_after>(in-package :vari.cl)

(defvar *vari-additional-form-docs*
  (make-hash-table :test #'eq))

(defun janky-parse-name (str)
  (flet ((inner (str)
           (let* ((pos (position #\: str :test #'char=)))
             (cond
               ((null pos) (find-symbol str *package*))
               ((= pos 0) (find-symbol (subseq str 1) :keyword))
               (t
                (let ((pkg (find-package (subseq str 0 pos))))
                  (when pkg
                    (find-symbol (subseq str (1+ pos)) pkg))))))))
    (values
     (or (inner str)
         (inner (string-upcase str))
         (let ((*package* (find-package "GLSL-SYMBOLS")))
           (or (inner str)
               (inner (string-upcase str))))))))

(defun vari-describe (name &optional (stream *standard-output*))
  (flet ((get-overload-signatures (symb-name form-set)
           (if (typep form-set 'v-function-set)
               (loop
                  :for binding :in (functions form-set)
                  :for spec := (v-argument-spec binding)
                  :for sig := (handler-case
                                  (cons symb-name
                                        (loop :for type :in spec :collect
                                           (type->type-spec type)))
                                (error () nil))
                  :when sig :collect sig)
               (arguments form-set)))
         (format-glsl-func-doc (glsl-doc)
           (let* ((decl (search "Declaration" glsl-doc))
                  (param (search "Parameter" glsl-doc))
                  (see-also (search "See Also" glsl-doc))
                  (copyright (search "Copyright" glsl-doc)))
             (cond
               ((and decl param see-also copyright)
                (format nil "Official GLSL Documentaion:~%~%~a~a~a"
                        (subseq glsl-doc 0 decl)
                        (subseq glsl-doc param see-also)
                        (subseq glsl-doc copyright)))
               ((and decl param)
                (format nil "Official GLSL Documentaion:~%~%~a~a"
                        (subseq glsl-doc 0 decl)
                        (subseq glsl-doc param)))
               (t (format nil "Official GLSL Documentaion:~%~%~a" glsl-doc)))))
         (format-glsl-var-doc (glsl-doc)
           (let* ((decl (search "Declaration" glsl-doc))
                  (desc (search "Description" glsl-doc))
                  (see-also (search "See Also" glsl-doc))
                  (copyright (search "Copyright" glsl-doc)))
             (cond
               ((and decl desc see-also copyright)
                (format nil "Official GLSL Documentaion:~%~%~a~a~a"
                        (subseq glsl-doc 0 decl)
                        (subseq glsl-doc desc see-also)
                        (subseq glsl-doc copyright)))
               ((and decl desc)
                (format nil "Official GLSL Documentaion:~%~%~a~a"
                        (subseq glsl-doc 0 decl)
                        (subseq glsl-doc desc)))
               (t (format nil "Official GLSL Documentaion:~%~%~a" glsl-doc)))))
         (try-get-var-type (name)
           (let ((spec
                  (loop :for (nil . vars) :in varjo.internals::*glsl-variables*
                     :for match := (find name vars :key #'first)
                     :when match :return (third match))))
             (varjo.internals::alternate-name-for spec))))

    (let* ((name (if (stringp name)
                     (janky-parse-name name)
                     name))
           (var (gethash name glsl-docs:*variables*))
           (form-binding-set
            (unless (or var (string= name :declare))
              (varjo.internals::find-global-form-binding-by-literal name t))))
      (cond
        (var
         (format stream
                 "~a~%~%~@[Type:~%~%~s~%~%~]~a"
                 name
                 (try-get-var-type name)
                 (format-glsl-var-doc var)))
        (form-binding-set
         (let* ((glsl-doc (gethash name glsl-docs:*functions*))
                (v-doc (gethash name *vari-additional-form-docs*))
                (overloads (get-overload-signatures name form-binding-set))
                (doc (cond
                       (v-doc v-doc)
                       (glsl-doc
                        (format-glsl-func-doc glsl-doc)))))
           (format stream "~a~%~%~@[Overloads:~%~{~s~%~}~]~@[~%~a~]"
                   name
                   overloads
                   doc)))))))

(setf (gethash '* *vari-additional-form-docs*)
      "Return the product of its arguments. With no args, returns 1.")

(setf (gethash '+ *vari-additional-form-docs*)
      "Return the sum of its arguments. With no args, returns 0.")

(setf (gethash '- *vari-additional-form-docs*)
      "Subtract the second and all subsequent arguments from the first;
  or with one argument, negate the first argument.")

(setf (gethash '/ *vari-additional-form-docs*)
      "Divide the first argument by each of the following arguments, in turn.
  With one argument, return reciprocal.")

(setf (gethash '/= *vari-additional-form-docs*)
      "Return T if no two of its arguments are numerically equal, NIL otherwise.")
{'fraction_non_alphanumeric': 0.1380580357142857, 'fraction_numerical': 0.0018973214285714286, 'mean_word_length': 1.527072758037225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4854237', 'n_tokens_mistral': 2675, 'n_tokens_neox': 2557, 'n_words': 704}