I suppose I should have posted this as a challenge but it is a problem that I am trying to solve but have only been partially successful at. I would like to be able to read a line of AutoLISP code and break it up into its syntactic units. I would like to feed a string of code and get back a list of two elements, the first element is a list of the actual code broken up into units and the second element is the code commenting (if any). In the list of syntactic units I would like each string in its own list so that I can identify them separate from the other pieces. Some examples, would probably be clearer:
"(+ 2 3)" -> (list (list "(" "+" "2" "3" ")") nil)
"(abs 4);absolute value" -> (list (list "(" "abs" "4" ")") ";absolute value")
"(strcase (strcat "cat" "dog"))"
-> (list (list "(" "strcase" "(" "strcat" ("cat")("dog") "))") nil)
Note that parentheses are to be pulled away from the functions and elements that they enclose. I'm finding all this tricky because it is not immediately clear to me how one can properly recognize both quotes and semicolons in their proper context. Separating comments seems simple until you start wondering how best to go about it. Simply finding the first semicolon is not enough because you must consider whether it is between quotes or not. I'm hoping some of you gurus might have already tackled this problem and might want to share your wisdom on it.