Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-matcher uppercase (in #\A #\Z))
- (define-matcher numerals (in #\0 #\9))
- (defun read-bracket ()
- "Reads fragments of funny notation inside brackets"
- (consume)
- (loop for next = (peek)
- while (and next (char/= next #\]))
- collect (read-piece)
- finally (consume)))
- (defun read-piece ()
- "Reads a fragment of funny notation up to a landmark (rN rNN cpR4, up to a capital letter + opt. digit)"
- (let ((tag (consume-until (make-matcher (or :uppercase (any #\[ #\])))))
- (next (peek)))
- (format t "~a & ~s, " tag next)
- (case next
- (#\[ (cons tag (read-bracket)))
- (#\] tag)
- ;; Issue: reader consumes too many repeated letters ("WWW" doesn't get parsed into "WW" "W")
- (T (format NIL "~a~:[~;~:*~a~]" tag (consume-until
- (make-matcher
- (not
- (or (is (string next)) :numerals)))))))))
- (defun funny-notation->parsed-fragments (string)
- (with-lexer-environment (string)
- (loop while (peek)
- collect (read-piece))))
Advertisement
Add Comment
Please, Sign In to add comment