Coverage report: /home/ellis/comp/core/lib/organ/section.lisp

KindCoveredAll%
expression28110 25.5
branch18 12.5
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; lib/organ/section.lisp --- Org Sections
2
 
3
 ;;
4
 
5
 ;;; Code:
6
 (in-package :organ)
7
 
8
 (defclass org-section () 
9
   ((contents :initform #() :initarg :contents :type (vector org-object)
10
              :accessor org-contents)))
11
 
12
 (defmethod org-create ((type (eql :section)) &rest initargs)
13
   (apply #'make-instance (sym-to-org-class-name type) initargs))
14
 
15
 (defmethod org-parse ((type (eql :section)) (input string))
16
   (unless (sequence:emptyp input)
17
     (org-create :section :contents input)))
18
 
19
 (defmethod org-parse ((type (eql :section)) (input stream))
20
   (let ((content (make-array 0 :element-type 'character :fill-pointer 0)))
21
     (with-output-to-string (content-stream content)
22
       (loop for c = (peek-char nil input nil nil) ; check that this line isn't a headline
23
             until (or (not c) (char= #\* c))
24
             do (let ((l (read-line input)))
25
                  (write-line l content-stream))))
26
     (org-create :section :contents (org-parse :paragraph content))))
27
 
28
 (defclass org-meta-section (org-section) ((keywords :initform #() :initarg :keywords :type (vector org-keyword))))
29
 
30
 (defmethod org-create ((type (eql :meta)) &rest initargs)
31
   (apply #'make-instance 'org-meta-section initargs))
32
 
33
 (defmethod org-parse ((type (eql :meta)) (input string))
34
   (with-input-from-string (s input)
35
     (org-parse :meta s)))
36
 
37
 (defmethod org-parse ((type (eql :meta)) (input stream))
38
   (let ((keywords (make-array 0 :element-type 'org-keyword :adjustable t :fill-pointer 0))
39
         (content (make-array 0 :element-type 'character :fill-pointer 0)))
40
     (with-output-to-string (content-stream content)
41
       (loop for c = (peek-char nil input nil nil) ; check that this line isn't a headline
42
             until (or (not c) (char= #\* c))
43
             do (let ((l (read-line input)))
44
                  (if-let ((kw (org-parse :keyword l))) ;; comments are handled here
45
                    (unless (typep kw 'org-comment)
46
                      (vector-push-extend kw keywords))
47
                    (write-line l content-stream)))))
48
     (org-create :meta :keywords keywords :contents (org-parse :paragraph content))))