implement typing
This commit is contained in:
parent
acb16f15f8
commit
306780b08b
12
design.org
12
design.org
|
@ -43,3 +43,15 @@ Display text is optional.
|
|||
Whitespace between the line type sigil and target is permitted but optional.
|
||||
|
||||
Whitespace between the target and display text is mandatory if the display text is present.
|
||||
|
||||
* Abstract syntax list
|
||||
The parser parses the file into an _abstract syntax list_. This data structure is a list of nodes.
|
||||
|
||||
Usually, each line of the parsed file will correspond to one node in the abstract syntax list. Preformat-mode content violates this rule.
|
||||
|
||||
Terminating newlines at the end of parsed file lines, ie line separators, are not represented in the text content of nodes. Software which assembles the abstract syntax list back into a discrete file should join the nodes using newline characters.
|
||||
** Node
|
||||
A node is a data structure containing the following elements:
|
||||
+ Type (typeval)
|
||||
+ Text component (optional textval)
|
||||
+ Preformat (boolean)
|
||||
|
|
|
@ -1,10 +1,50 @@
|
|||
(defpackage white-tiger
|
||||
(:use :cl)
|
||||
(:export #:start))
|
||||
;; (defpackage white-tiger
|
||||
;; (:use :cl)
|
||||
;; (:export #:node #:make-node #:node-type #:node-text-component #:node-preformat #:start))
|
||||
|
||||
(in-package white-tiger)
|
||||
;; (in-package white-tiger)
|
||||
|
||||
(defstruct node
|
||||
(type)
|
||||
(text-component "" :type string)
|
||||
(preformat nil :type boolean))
|
||||
|
||||
(defun type-of-line (line)
|
||||
(if (= (length line) 0)
|
||||
:text
|
||||
(case (char line 0)
|
||||
;; Headers
|
||||
(#\# (if (eq (char line 1) #\#)
|
||||
(if (eq (char line 2) #\#)
|
||||
:h3
|
||||
:h2)
|
||||
:h1
|
||||
))
|
||||
;; List item
|
||||
(#\* :list)
|
||||
;; Quote
|
||||
(#\> :quote)
|
||||
;; preformat toggle
|
||||
(#\` (if (and (eql #\` (char line 2)) (eql #\` (char line 1))) :preformat :text))
|
||||
;; Link
|
||||
(#\= (if (eq #\> (char line 1)) :link :text))
|
||||
(otherwise :text))))
|
||||
|
||||
(defun read-file (filename)
|
||||
(uiop:read-file-lines filename))
|
||||
|
||||
(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
|
||||
(make-node
|
||||
:preformat preformat
|
||||
|
||||
))
|
||||
|
||||
(defun parse-gemtext-file ()
|
||||
t)
|
||||
|
||||
(defun start () t)
|
||||
|
||||
|
|
Loading…
Reference in New Issue