Fix broken doc format.
Many assumptions in the parsing code that could cause infinite
loops, as well as assuming things were non-nil.
(defn skip-line-indent []
(var pos* pos)
(set c (get str pos*))
- (while (and (not= nil c)
+ (while (and c
(not= 10 c)
(= 32 c))
(set c (get str (++ pos*))))
(defn update-levels []
(while (< leading (array/peek levels))
- (array/pop levels)))
+ (array/pop levels)
+ (if (empty? levels) (break))))
(defn start-nl? []
(= 10 (get str pos)))
(defn start-ul? []
(var pos* pos)
(var c* (get str pos*))
- (while (and (not= nil c*)
- (= 32 c*))
+ (while (and c* (= 32 c*))
(set c* (get str (++ pos*))))
(and (or (= 42 c*)
(= 43 c*)
(defn start-ol? []
(var pos* pos)
(var c* (get str pos*))
- (while (and (not= nil c*)
- (= 32 c*))
+ (while (and c* (= 32 c*))
(set c* (get str (++ pos*))))
- (while (and (not= nil c*)
+ (while (and c*
(<= 48 c*)
(>= 57 c*))
(set c* (get str (++ pos*))))
(defn push-line []
(buffer/push-string res (buffer/new-filled indent 32))
(set c (get str pos))
- (while (not= 10 c)
+ (while (and c (not= 10 c))
(buffer/push-byte res c)
(set c (get str (++ pos))))
- (buffer/push-byte res c)
+ (buffer/push-byte res 10)
(++ pos))
(defn push-bullet []
(buffer/push-string line (buffer/new-filled leading 32))
(set c (get str pos*))
# Add bullet
- (while (and (not= nil c) (not= 32 c))
+ (while (and c (not= 32 c))
(buffer/push-byte line c)
(set c (get str (++ pos*))))
# Add item indentation
- (while (and (not= nil c) (= 32 c))
+ (while (= 32 c)
(buffer/push-byte line c)
(set c (get str (++ pos*))))
# Record indentation if necessary
(def word @"")
(var word-len 0)
# Build a word
- (while (and (not= nil c)
+ (while (and c
(not= 10 c)
(not= 32 c))
(buffer/push-byte word c)
(push-bullet)
# Add words
(set c (get str pos))
- (while (and (not= nil c)
+ (while (and c
(not= 10 c))
# Skip spaces
(while (= 32 c)
(defn push-fcb []
(update-levels)
(push-line)
- (while (not (end-fcb?))
+ (while (and (< pos len) (not (end-fcb?)))
(push-line))
(push-line))
(defn push-icb []
(buffer/push-string res (buffer/new-filled leading 32))
(push-line)
- (while (not (start-nl?))
+ (while (and (< pos len) (not (start-nl?)))
(push-line))
(push-nl))
(set line-width para-indent)
# Add words
(set c (get str pos))
- (while (and (not= nil c)
- (not= 10 c))
+ (while (and c (not= 10 c))
# Skip spaces
(while (= 32 c)
(set c (get str (++ pos))))
