Function: semantic-lex-spp-lex-text-string
semantic-lex-spp-lex-text-string is a byte-compiled function defined
in lex-spp.el.gz.
Signature
(semantic-lex-spp-lex-text-string TEXT)
Documentation
Lex the text string TEXT using the current buffer's state.
Use this to parse text extracted from a macro as if it came from the current buffer. Since the lexer is designed to only work in a buffer, we need to create a new buffer, and populate it with rules and variable state from the current buffer.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/lex-spp.el.gz
(defun semantic-lex-spp-lex-text-string (text)
"Lex the text string TEXT using the current buffer's state.
Use this to parse text extracted from a macro as if it came from
the current buffer. Since the lexer is designed to only work in
a buffer, we need to create a new buffer, and populate it with rules
and variable state from the current buffer."
(let* ((semantic-lex-spp-hack-depth (1+ semantic-lex-spp-hack-depth))
(buf (get-buffer-create (format " *SPP parse hack %d*"
semantic-lex-spp-hack-depth)))
(mode major-mode)
(fresh-toks nil)
(toks nil)
(origbuff (current-buffer))
;; (analyzer semantic-lex-analyzer)
(important-vars '(semantic-lex-spp-macro-symbol-obarray
semantic-lex-spp-project-macro-symbol-obarray
semantic-lex-spp-dynamic-macro-symbol-obarray
semantic-lex-spp-dynamic-macro-symbol-obarray-stack
semantic-lex-spp-expanded-macro-stack
))
)
(if (> semantic-lex-spp-hack-depth 5)
nil
(with-current-buffer buf
(erase-buffer)
;; Below is a painful hack to make sure everything is setup correctly.
(when (not (eq major-mode mode))
(save-match-data
;; Protect against user-hooks that throw errors.
(condition-case nil
(funcall mode)
(error nil))
;; Hack in mode-local
(mode-local--activate-bindings)
;; Call the major mode's setup function
(let ((entry (assq major-mode semantic-new-buffer-setup-functions)))
(when entry
(funcall (cdr entry))))
;; 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)
))
;; Second Cheat: copy key variables regarding macro state from the
;; the originating buffer we are parsing. We need to do this every time
;; since the state changes.
(dolist (V important-vars)
(set V (buffer-local-value V origbuff)))
(insert text)
(goto-char (point-min))
(setq fresh-toks (semantic-lex-spp-stream-for-macro (point-max))))
(dolist (tok fresh-toks)
(when (memq (semantic-lex-token-class tok) '(symbol semantic-list))
(setq toks (cons tok toks)))))
(nreverse toks)))