Function: semantic-c-parse-lexical-token
semantic-c-parse-lexical-token is a byte-compiled function defined in
c.el.gz.
Signature
(semantic-c-parse-lexical-token LEXICALTOKEN NONTERMINAL DEPTH RETURNONERROR)
Documentation
Do a region parse on the contents of LEXICALTOKEN.
Presumably, this token has a string in it from a macro. The text of the token is inserted into a different buffer, and parsed there. Argument NONTERMINAL, DEPTH, and RETURNONERROR are passed into the regular parser.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/bovine/c.el.gz
(defun semantic-c-parse-lexical-token (lexicaltoken nonterminal depth
returnonerror)
"Do a region parse on the contents of LEXICALTOKEN.
Presumably, this token has a string in it from a macro.
The text of the token is inserted into a different buffer, and
parsed there.
Argument NONTERMINAL, DEPTH, and RETURNONERROR are passed into
the regular parser."
(let* ((semantic-c-parse-token-hack-depth (1+ semantic-c-parse-token-hack-depth))
(buf (get-buffer-create (format " *C parse hack %d*"
semantic-c-parse-token-hack-depth)))
(mode major-mode)
(spp-syms semantic-lex-spp-dynamic-macro-symbol-obarray)
(stream nil)
(start (semantic-lex-token-start lexicaltoken))
(end (semantic-lex-token-end lexicaltoken))
(symtext (semantic-lex-token-text lexicaltoken))
(macros (get-text-property 0 'macros symtext))
)
(if (> semantic-c-parse-token-hack-depth 5)
nil
(with-current-buffer buf
(erase-buffer)
(when (not (eq major-mode mode))
(save-match-data
;; Protect against user hooks throwing errors.
(condition-case nil
(funcall mode)
(error
(if (y-or-n-p
(format "There was an error initializing %s in buffer \"%s\". Debug your hooks? "
mode (buffer-name)))
(semantic-c-debug-mode-init mode)
(message "Macro parsing state may be broken...")
(sit-for 1))))
) ; save match data
;; Hack in mode-local
(mode-local--activate-bindings)
;; Setup C parser
(semantic-default-c-setup)
;; CHEATER! The following 3 lines are from
;; `semantic-new-buffer-fcn', but we don't want to turn
;; on all the other annoying modes for this little task.
(setq semantic-new-buffer-fcn-was-run t)
(semantic-lex-init)
(semantic-clear-toplevel-cache)
(remove-hook 'semantic-lex-reset-functions
#'semantic-lex-spp-reset-hook t)
)
;; Get the macro symbol table right.
(setq semantic-lex-spp-dynamic-macro-symbol-obarray spp-syms)
;; (message "%S" macros)
(dolist (sym macros)
(semantic-lex-spp-symbol-set (car sym) (cdr sym)))
(insert symtext)
(setq stream
(semantic-parse-region-default
(point-min) (point-max) nonterminal depth returnonerror))
;; Clean up macro symbols
(dolist (sym macros)
(semantic-lex-spp-symbol-remove (car sym)))
;; Convert the text of the stream.
(dolist (tag stream)
;; Only do two levels here 'cause I'm lazy.
(semantic--tag-set-overlay tag (list start end))
(dolist (stag (semantic-tag-components-with-overlays tag))
(semantic--tag-set-overlay stag (list start end))
))
))
stream))