successfull parse to typed list
including preformat specification!
This commit is contained in:
parent
306780b08b
commit
622b580c90
13
design.org
13
design.org
|
@ -55,3 +55,16 @@ A node is a data structure containing the following elements:
|
|||
+ Type (typeval)
|
||||
+ Text component (optional textval)
|
||||
+ Preformat (boolean)
|
||||
* Preformat calculation
|
||||
The currently visited node should be marked "preformat" when:
|
||||
| *current preformat mode* | *visited node type* | *preformat?* |
|
||||
|--------------------------+---------------------+--------------|
|
||||
| t | preformat | nil |
|
||||
| nil | preformat | t |
|
||||
| t | any other | t |
|
||||
| nil | any other | nil |
|
||||
|
||||
a := current preformat mode is t
|
||||
b := newly visited node is a PREFORMAT node
|
||||
|
||||
(not a and b) or (a and not b)
|
||||
|
|
|
@ -36,15 +36,25 @@
|
|||
(defun type-of-file (filename)
|
||||
(map 'list #'type-of-line (read-file filename)))
|
||||
|
||||
(defun line-to-node (line preformat)
|
||||
;; TODO: Handle preformat mode termination lines
|
||||
(defun xor (a b)
|
||||
(or (and (not a) b) (and a (not b))))
|
||||
|
||||
(defun line-to-node (line type preformat)
|
||||
(make-node
|
||||
:preformat preformat
|
||||
|
||||
))
|
||||
;; TODO: Split line on first whitespace; use cdr for text component
|
||||
:type type
|
||||
:text-component ""))
|
||||
|
||||
(defun parse-gemtext-file ()
|
||||
t)
|
||||
(defun parse-gemtext-file (line-list preformat-mode)
|
||||
(if (= (length line-list) 0)
|
||||
nil
|
||||
;; Parse the line. If this line is a PREFORMAT, toggle the boolean moving forward.
|
||||
(let ((line-type (type-of-line (car line-list))))
|
||||
(cons (line-to-node (car line-list) line-type (if (eq line-type :preformat) nil preformat-mode))
|
||||
(parse-gemtext-file (cdr line-list) (if (eq line-type :preformat) (not preformat-mode) preformat-mode))))))
|
||||
|
||||
(defun start () t)
|
||||
(defun start (filename)
|
||||
(let ((file-contents (read-file filename)))
|
||||
(parse-gemtext-file file-contents nil)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue