I am trying to write a parser for an s-expression-based language. It has the usual
; to the end of line comments. My problem is that I don't want to strip the comments (my original goal was to write a pretty-printer/formatter), and the comments can appear anywhere in the code.
For example, I can have
;; pretty normal -- this function does blah blah blah
;; TODO: do something useful here
(= 23 5))
(define-private ;; make this public maybe?
(enigma 23) ;; snicker
(laws ;; this is a terrible example
;; inside the let body
;; todo: constant folding?
How do I get instaparse to handle that?
Stripping comments is trivial -- I can use something like this:
"ws-or-comments = #'\\s+' | comment+
comment = #';+[^\n]*'
" :auto-whitespace :standard)
(defparser my-parser ... :auto-whitespace ws-or-comments)