Extracting comments
Posted: Sat Jul 07, 2007 5:12 pm
I'm looking for some help in designing an algortihm to extract the comment part of a line of LISP code. In particular, I want to write a function "lisp-comment" that will take a line of LISP code in string format and return a list with the code part and comment part separated from each other. For example:
(lisp-comment "(setq a 3) ;we set a variable"))
would return
("(setq a 3)" ";we set a variable"))
At first it seems like you only have to look for the last semicolon and break from there but it is more complicated than that because a semicolon can be inside a string as well as being followed by quoted words. I'm having difficulty determining what the proper rule for finding the right semicolon is. Is there a regex that will do this?
(lisp-comment "(setq a 3) ;we set a variable"))
would return
("(setq a 3)" ";we set a variable"))
At first it seems like you only have to look for the last semicolon and break from there but it is more complicated than that because a semicolon can be inside a string as well as being followed by quoted words. I'm having difficulty determining what the proper rule for finding the right semicolon is. Is there a regex that will do this?