@@ -607,6 +607,15 @@ STATE is Elsa local state."
607
607
(elsa-state-add-defvar state
608
608
(elsa-defvar :name (elsa-get-name (cadr (oref reader-form sequence)))
609
609
:type (eval `(elsa-make-type ,@(cddr comment-form))))))
610
+ ; ; slot annotation in defclass
611
+ ((and (elsa-locate-dominating-form reader-form 'defclass )
612
+ (elsa-form-function-call-p reader-form (car comment-form)))
613
+ (oset reader-form annotation comment-form))
614
+ ; ; annotations for let bindings
615
+ ((and (elsa-locate-dominating-form
616
+ reader-form '(let let* when-let when-let* if-let if-let*))
617
+ (elsa-form-function-call-p reader-form (car comment-form)))
618
+ (oset reader-form annotation comment-form))
610
619
((eq annotation-name 'var )
611
620
(oset reader-form annotation comment-form))
612
621
(t
@@ -681,37 +690,42 @@ for the analysis."
681
690
((functionp form) (elsa--read-function form state))
682
691
(t (error " Invalid form " )))))
683
692
(elsa--set-line-and-column reader-form)
684
- ; ; check if there is a comment atached to this form
685
- ; ; TODO: this is really inefficient because it checks the same
686
- ; ; line multiple times. We should only do this parsing for the
687
- ; ; first form on a line.
688
- (save-excursion
689
- (goto-char (oref reader-form start))
690
- (forward-line -1 )
691
- (skip-chars-forward " \t\n\r " )
692
- (let ((line-end (line-end-position )))
693
- (when (and (re-search-forward
694
- (rx " (" (+ (+? (or (syntax word) (syntax symbol))) (+ space)) " :: " )
695
- line-end t )
696
- (nth 4 (syntax-ppss )))
697
- ; ; we are inside a comment and inside a form starting with
698
- ; ; (elsa
699
- (search-backward " (" )
700
- (let ((comment-form (read (current-buffer ))))
701
- ; ; we must end on the same line, that way we can be sure
702
- ; ; the entire read form was inside a comment.
703
- (when (<= (point ) line-end)
704
- ; ; handle defun type declaration
705
- (elsa--process-annotation reader-form comment-form state))))))
706
693
reader-form))
707
694
708
695
(defun elsa-read-form (state )
709
696
" Read form at point."
710
697
(while (forward-comment 1 ))
711
698
(unless (eobp )
712
699
(let* ((form (save-excursion
713
- (read (current-buffer )))))
714
- (while (forward-comment 1 ))
715
- (elsa--read-form form state))))
700
+ (read (current-buffer ))))
701
+ (elsa-form (progn
702
+ (while (forward-comment 1 ))
703
+ (elsa--read-form form state))))
704
+
705
+
706
+ ; ; Process annotations attached to subforms in this top-level
707
+ ; ; form. We have to do it here after the entire form is read to
708
+ ; ; be able to make use of parent/previous relations.
709
+ (elsa-form-visit elsa-form
710
+ (lambda (ef )
711
+ (save-excursion
712
+ (goto-char (oref ef start))
713
+ (forward-line -1 )
714
+ (skip-chars-forward " \t\n\r " )
715
+ (let ((line-end (line-end-position )))
716
+ (when (and (re-search-forward
717
+ (rx " (" (+ (+? (or (syntax word) (syntax symbol))) (+ space)) " :: " )
718
+ line-end t )
719
+ (nth 4 (syntax-ppss )))
720
+ ; ; we are inside a comment and inside a form starting with
721
+ ; ; (elsa
722
+ (search-backward " (" )
723
+ (let ((comment-form (read (current-buffer ))))
724
+ ; ; we must end on the same line, that way we can be sure
725
+ ; ; the entire read form was inside a comment.
726
+ (when (<= (point ) line-end)
727
+ ; ; handle defun type declaration
728
+ (elsa--process-annotation ef comment-form state))))))))
729
+ elsa-form)))
716
730
717
731
(provide 'elsa-reader )
0 commit comments