|
30 | 30 | :format-control "unknown modifier ~s" |
31 | 31 | :format-arguments x)))) |
32 | 32 |
|
| 33 | +(comment |
| 34 | + (ppcre:parse-string |
| 35 | + "@\{(#{1,2}\\s.*?)\}") |
| 36 | + ; => (:SEQUENCE "@{" |
| 37 | + ; (:REGISTER |
| 38 | + ; (:SEQUENCE (:GREEDY-REPETITION 1 2 #\#) #\s |
| 39 | + ; (:NON-GREEDY-REPETITION 0 NIL :EVERYTHING))) |
| 40 | + ; #\}) |
| 41 | + ) |
| 42 | + |
33 | 43 | (defparameter *anchor-pattern* |
34 | | - (ppcre:create-scanner '(:SEQUENCE "@{" (:GREEDY-REPETITION 1 2 #\#) |
35 | | - (:GREEDY-REPETITION 1 NIL :WHITESPACE-CHAR-CLASS) |
36 | | - (:REGISTER (:NON-GREEDY-REPETITION 0 NIL :EVERYTHING)) #\}))) |
| 44 | + (ppcre:create-scanner '(:SEQUENCE "@{" |
| 45 | + (:REGISTER |
| 46 | + (:SEQUENCE (:GREEDY-REPETITION 1 2 #\#) :WHITESPACE-CHAR-CLASS |
| 47 | + (:NON-GREEDY-REPETITION 0 NIL :EVERYTHING))) |
| 48 | + #\}) |
| 49 | + )) |
37 | 50 |
|
38 | 51 | (defun parse-anchor (line) |
39 | 52 | (let ((parts (ppcre:split *anchor-pattern* line :with-registers-p t))) |
40 | 53 | (mapcar-indexed (lambda (string i) |
41 | 54 | (if (evenp i) |
42 | | - (ppcre:regex-replace-all "@@({[^}]+})" string "@\\1") |
43 | | - (list :ANCHOR string))) |
| 55 | + ;; Not sure what to do write here. Should `parse-anchor' have |
| 56 | + ;; the duplicated escape logic? |
| 57 | + ;; I'm leaning towards duplicate the same escape logic from `parse-ref' to here. |
| 58 | + (progn |
| 59 | + string |
| 60 | + ;; or... |
| 61 | + (ppcre:regex-replace-all "@@({[^}]+})" string "@\\1")) |
| 62 | + (list :ANCHOR (if (eql (char string 1) #\#) |
| 63 | + (list :S (ppcre:regex-replace "##\\s+" string "")) |
| 64 | + (list :C (ppcre:regex-replace "#\\s+" string "")))))) |
44 | 65 | parts))) |
45 | 66 |
|
| 67 | + |
46 | 68 | (comment |
47 | | - (let ((line "Foobar @{# Baz} @{buz} @@{fizz}")) |
| 69 | + ;; How should escaping work if we go this route of parse-anchor+parse-ref and parse-repeatedly? |
| 70 | + (let ((line "Foobar @{# Baz} @{## Biz} @{buz} @@{fizz}")) |
48 | 71 | (parse-anchor line)) |
49 | | - ; => ("Foobar " (:ANCHOR "Baz") " @{buz} @{fizz}") |
| 72 | + ; => ("Foobar " (:ANCHOR (:C "Baz")) " " (:ANCHOR (:S "Biz")) " @{buz} @@{fizz}") |
| 73 | + ; => ("Foobar " (:ANCHOR (:C "Baz")) " " (:ANCHOR (:S "Biz")) " @{buz} @{fizz}") |
50 | 74 | ) |
51 | 75 |
|
52 | 76 | (defparameter *ref-pattern* |
|
135 | 159 | Line starts off as a string. After the first parse, it will be a list of regular text and parsed segments. |
136 | 160 |
|
137 | 161 | Example: |
138 | | - \"Some text @{some ref}\" |
| 162 | + \"Some @{# some chapter} text @{some ref}\" |
139 | 163 | will turn into |
140 | | - (\"Some text\" (:INCLUDE \"some ref\")). |
| 164 | + (\"Some \" (:ANCHOR \"#some chapter\") \"text \" (:INCLUDE \"some ref\")). |
141 | 165 |
|
142 | | -The subsequent parsers will be mapped over the result of the first parse." |
| 166 | +The subsequent parsers will be mapped over the result of the first parse. |
| 167 | +
|
| 168 | +NOTE: |
| 169 | +There's at least one issue with this. |
| 170 | +`parse-refs' treats the double `@@' as an escape sequence. |
| 171 | +Instead of turning `@@{# foo}' into `@<a href='# foo'></a>' it turns it into `@{# foo}'. |
| 172 | +So if we first `parse-refs' and turn `@@{# foo}' into `@{# foo}' and then run `parse-anchors' after that |
| 173 | +then we're bypassing our escape mechanism." |
143 | 174 | (cond |
144 | 175 | ((null line) nil) |
145 | 176 | ((null parsers) line) |
@@ -188,25 +219,24 @@ The subsequent parsers will be mapped over the result of the first parse." |
188 | 219 | line))) |
189 | 220 |
|
190 | 221 | (comment |
| 222 | + ;; Testing out the `parse-repeatedly' behavior. |
| 223 | + |
191 | 224 | (parse-prose-line "\\n") |
192 | 225 | ; => ("\\n") |
193 | 226 | (parse-prose-line "") |
194 | 227 | ; => NIL |
195 | 228 | (parse-prose-line "Foobar @{# Baz} \\begin{math}n + m\\end{math} buz @{fizz}") |
196 | | - ; => ("Foobar " (:ANCHOR "Baz") " " (:MATH "n + m") " buz " (:INCLUDE "fizz")) |
| 229 | + ; => ("Foobar " (:ANCHOR (:C "Baz")) " " (:MATH "n + m") " buz " (:INCLUDE "fizz")) |
197 | 230 | (parse-prose-line "Foobar @{fizz} \\begin{math}n + m\\end{math} buz @{# Baz}") |
198 | | - ; => ("Foobar " (:INCLUDE "fizz") " " (:MATH "n + m") " buz " (:ANCHOR "Baz")) |
| 231 | + ; => ("Foobar " (:INCLUDE "fizz") " " (:MATH "n + m") " buz " (:ANCHOR (:C "Baz"))) |
199 | 232 | (parse-prose-line "# Some heading @{with a ref}") |
200 | 233 | ; => ((:C "Some heading @{with a ref}")) |
201 | 234 | (mapcar #'parse-prose-line |
202 | 235 | '("# Foobar" |
203 | 236 | "@{bazz}" |
204 | 237 | "" |
205 | 238 | "@{# Foobar}")) |
206 | | - ; => (((:C "Foobar")) ("" (:INCLUDE "bazz")) NIL ("@{# Foobar}")) <- original |
207 | | - ; => (((:C "Foobar")) ((:INCLUDE "bazz")) NIL ("" (:ANCHOR "Foobar"))) <- new |
208 | | - ; Not sure why this (:INCLUDE...) is different between the two. |
209 | | - ; I think it will still work. And everything else looks the same. |
| 239 | + ; => (((:C "Foobar")) ((:INCLUDE "bazz")) NIL ("" (:ANCHOR (:C "Foobar")))) |
210 | 240 | ) |
211 | 241 |
|
212 | 242 | (defparameter *block-start-pattern* |
@@ -263,6 +293,15 @@ The subsequent parsers will be mapped over the result of the first parse." |
263 | 293 | (textblock-lines (textblockdef-block def))) |
264 | 294 | (go TEXT))) |
265 | 295 |
|
| 296 | +(comment |
| 297 | + ;; Just want to get a feel for what the def-table looks like |
| 298 | + (let* ((file-defs (parse-lit-files '("dev.lit" "scratch.lit"))) |
| 299 | + (weaver (make-weaver-default file-defs))) |
| 300 | + (let ((defs (weaver-def-table weaver))) |
| 301 | + (maphash (lambda (k v) |
| 302 | + (format t "~a ~a~%" k v)) |
| 303 | + defs))) |
| 304 | + ) |
266 | 305 |
|
267 | 306 | (defparameter *math-block-pattern* |
268 | 307 | (ppcre:create-scanner |
|
0 commit comments