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

Add reader for bool-vector type #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions elsa-analyser.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ adds the information that a fallback was used."
(defun elsa--analyse-vector (_form _scope _state)
nil)

(defun elsa--analyse-bool-vector (_form _scope _state)
nil)

(defun elsa--analyse-string (_form _scope _state)
nil)

Expand Down Expand Up @@ -1183,6 +1186,7 @@ FORM is a result of `elsa-read-form'."
((elsa-form-keyword-p form) (elsa--analyse-keyword form scope state))
((elsa-form-symbol-p form) (elsa--analyse-symbol form scope state))
((elsa-form-vector-p form) (elsa--analyse-vector form scope state))
((elsa-form-bool-vector-p form) (elsa--analyse-bool-vector form scope state))
((elsa-form-string-p form) (elsa--analyse-string form scope state))
((elsa-form-list-p form) (elsa--analyse-list form scope state))
((elsa-form-improper-list-p form) (elsa--analyse-improper-list form scope state))
Expand Down
48 changes: 48 additions & 0 deletions elsa-reader.el
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,44 @@ prefix and skipped by the sexp scanner.")
:sequence (-map (lambda (f) (elsa--read-form f state)) form)
:end (progn (up-list) (point))))

(defclass elsa-form-bool-vector (elsa-form-seq)
((sequence :type list :initarg :sequence)))

(cl-defmethod elsa-form-print ((this elsa-form-bool-vector))
(format "[%s]" (mapconcat 'elsa-form-print (oref this sequence) " ")))

(cl-defmethod elsa-form-to-lisp ((this elsa-form-bool-vector))
(apply #'bool-vector (mapcar #'elsa-form-to-lisp (oref this sequence))))

(cl-defmethod elsa-form-foreach ((this elsa-form-bool-vector) fn)
(mapc fn (oref this sequence)))

(cl-defmethod elsa-form-map ((this elsa-form-bool-vector) fn)
(mapcar fn (oref this sequence)))

(cl-defmethod elsa-form-visit ((this elsa-form-bool-vector) fn)
(funcall fn this)
(elsa-form-foreach this (lambda (x) (elsa-form-visit x fn))))

(cl-defmethod elsa-form-sequence ((this elsa-form-bool-vector))
(oref this sequence))

(defsubst elsa--read-bool-vector (form)
(elsa--skip-whitespace-forward)
(let ((end (elsa--forward-sexp)))
(elsa-form-bool-vector
:type (elsa-make-type (vector bool))
:start (point)
:sequence (-map
(lambda (b)
(elsa-form-symbol
:type (elsa-make-type bool)
:start (point)
:end end
:name b))
form)
:end end)))

;;; Conses
(defclass elsa-form-cons (elsa-form) ())

Expand Down Expand Up @@ -861,6 +899,16 @@ for the analysis."
(oset f previous previous)
(setq previous f)))
vector-form))
((bool-vector-p form)
(let ((bool-vector-form (elsa--read-bool-vector form))
(previous nil))
(elsa-form-foreach bool-vector-form
(lambda (f)
(oset f parent bool-vector-form)
;; first one is set to nil
(oset f previous previous)
(setq previous f)))
bool-vector-form))
((functionp form) (elsa--read-function form state))
(t (error "Invalid form")))))
(elsa--set-line-and-column reader-form)
Expand Down