Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bool-vector type not supported by elsa-reader #228

Open
wtianyi opened this issue May 9, 2024 · 3 comments · May be fixed by #229
Open

Bool-vector type not supported by elsa-reader #228

wtianyi opened this issue May 9, 2024 · 3 comments · May be fixed by #229

Comments

@wtianyi
Copy link

wtianyi commented May 9, 2024

When processing ansi-color.el, e.g.

(elsa-process-file "/opt/homebrew/Cellar/emacs-mac/emacs-29.1-mac-10.0/share/emacs/29.1/lisp/ansi-color.el.gz")

A bool vector #&8"\0" at line 975 is not recognized, leading to an error "Invalid form" is thrown

(t (error "Invalid form")))))

It seems that bool-vector-p can be used to check whether it's a bool vector, and the corresponding type does exist in Elsa:

(defclass elsa-type-bool-vector (elsa-type elsa-simple-type eieio-singleton) ())

However, I lack the knowledge to add the elsa-form- class and the reader for it.

@wtianyi wtianyi linked a pull request May 9, 2024 that will close this issue
@wtianyi
Copy link
Author

wtianyi commented May 9, 2024

It seems easier than I initially expected, so I took a stab. #229

Being new to ELisp, I have a remotely related and probably dumb question: How come the elsa-form-*-p predicates work without being explicitly defined? What keyword should I search if I would like to learn more on this?

@Fuco1
Copy link
Member

Fuco1 commented May 9, 2024

The predicates come from the defclass. For example

(defclass elsa-form-number (elsa-form-atom)
  ((value :type number :initarg :value)))

expands to

(progn
  (defalias 'elsa-form-number-p
    (eieio-make-class-predicate 'elsa-form-number))
  (defalias 'elsa-form-number--eieio-childp
    (eieio-make-child-predicate 'elsa-form-number))
  (define-symbol-prop 'elsa-form-number 'cl-deftype-satisfies
    (function elsa-form-number--eieio-childp))
  (eieio-defclass-internal 'elsa-form-number
                           '(elsa-form-atom)
                           '((value :type number :initarg :value))
                           'nil)
  (defun elsa-form-number
      (&rest slots)
    "Create a new object of class type `elsa-form-number'."
    (declare
     (compiler-macro
      (lambda
        (whole)
        (if
            (not
             (stringp
              (car slots)))
            whole
          (macroexp-warn-and-return
           (format "Obsolete name arg %S to constructor %S"
                   (car slots)
                   (car whole))
           `(,(car whole)
             (identity ,(car slots))
             ,@(cdr slots)))))))
    (apply
     (function make-instance)
     'elsa-form-number slots)))

There's a package called macrostep which you can use to expand macros.

@wtianyi
Copy link
Author

wtianyi commented May 9, 2024

Thank you! This is very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants