Re: [CEDET-devel] Bug in semantic-el.el and a nifty new parser for defalias
Brought to you by:
zappo
From: David P. <dav...@wa...> - 2005-01-03 13:08:13
|
Hi Klaus, > The parsing of defstruct fails in some cases. > > The docstring of `defstruct' in GNU Emacs is wrong, because also the > following is allowed: > > (defstruct tramp-file-name multi-method method user host path) > > So the following (current) parser fails: > [...] > > This parser works: > > (semantic-elisp-setup-form-parser > (lambda (form start end) > (semantic-tag-new-type > (symbol-name (if (consp (nth 1 form)) > (car-safe (nth 1 form)) > (nth 1 form))) > "struct" > (semantic-elisp-desymbolify (nthcdr 2 form)) > (cons nil nil) > )) > defstruct > ) > > (see implementation of defstruct to see why this is necessary) This is a good point. The following version also takes into account that the first element of the slot list can be a doc string. (semantic-elisp-setup-form-parser (lambda (form start end) (let ((slots (nthcdr 2 form))) ;; Skip doc string if present. (and (stringp (car slots)) (setq slots (cdr slots))) (semantic-tag-new-type (symbol-name (if (consp (nth 1 form)) (car (nth 1 form)) (nth 1 form))) "struct" (semantic-elisp-desymbolify slots) (cons nil nil) ))) defstruct ) Perhaps could you submit a bug report to the Emacs developers to fix the `defstruct' doc string? > In addition i have added a nifty parser for defalias: > [...] Maybe it would be better to keep the information that this function is an alias of another one. We could use a new :definition attribute that would hold the aliased definition and implicitly indicate that this function is an alias. That should also work for `defvaralias' expressions. Something like this (untested): (semantic-elisp-setup-form-parser (lambda (form start end) (semantic-tag-new-function (symbol-name (if (equal (nth 0 (nth 1 form)) 'quote) (nth 1 (nth 1 form)) ;; if the alias is not a quoted symbol we have to ;; evaluate this code to get the symbol (eval (nth 1 form)))) nil ;; No type for Lisp functions nil ;; The arglist is the one of the aliased function ;; The following attribute hold the aliased definition. When ;; non-nil it also indicates that this function is an alias of ;; another one. :definition (nth 2 form) )) defalias ) Finally not duplicating the arglist in the tag will not unnecessarily increase the size of the tags database, and should please Eric ;) Anyway thanks for your good work! I wish you an happy new year. David |