using regular express to analyze lisp code
kf9150 at gmail.com
Thu Oct 4 19:13:59 CEST 2007
i've spent couple of hours trying to figure out the correct regular
expression to catch a VisualLisp (it is for AutoCAD and has a syntax
that's similar to common lisp) function body. VisualLisp is case-
insensitive. Any line beginning with ";" is for comment (can have
space(s) before ";").
here is an example of VisualLisp function:
(defun get_obj_app_names (obj / rv)
(foreach app (get_registered_apps (vla-get-document obj))
(if (get_xdata obj app)
(setq rv (cons app rv))
;;"This line is comment (comment)"
;;) This line is also comment
for a function named foo, it is easy to find the beginning part of the
"(defun foo", but it is hard to find the ")" at the end of code block.
if eventually i can't come up with the solution using regular
expression only, what i was thinking is after finding the beginning
part, which is "(defun foo" in this case, i can count the parenthesis,
ignoring anything inside "" and any line for comment, until i find the
not sure if i've made myself understood. thanks for reading.
More information about the Python-list