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
(define-private (blah)
;; TODO: do something useful here
(= 23 5))
or
(define-private ;; make this public maybe?
(blah)
(let (
(enigma 23) ;; snicker
(laws ;; this is a terrible example
5))
;; inside the let body
(= enigma
;; todo: constant folding?
laws)))
How do I get instaparse to handle that?
Stripping comments is trivial -- I can use something like this:
(defparser ws-or-comments
"ws-or-comments = #'\\s+' | comment+
comment = #';+[^\n]*'
" :auto-whitespace :standard)
(defparser my-parser ... :auto-whitespace ws-or-comments)