KSR reader macro syntax for cloze sequences

This commit is contained in:
2022-12-18 00:50:22 +00:00
parent 6d16fc6f0c
commit d22aa9c1bd

View File

@@ -154,3 +154,14 @@
nextToStudy (nth studyList nextIndex)]
(studyList.splice nextIndex 1)
(nextToStudy engine (studyAll.bind engine)))))
(defReaderMacro ["*" "?"] [stream &builder b]
(let [elements []]
(loop
(let [line (expect stream "An element for a cloze sequence" takeLine)]
(case (line.charAt 0)
("*" (elements.push (b.str (line.substr 1))))
("?" (elements.push (b.str line)))
("" (break))
(otherwise (throw "bad element for a cloze sequence: $line")))))
`(cloze ,@elements)))