Function: c-parse-ps-state-to-cache

c-parse-ps-state-to-cache is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-parse-ps-state-to-cache STATE)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
;; Note that as of 2019-05-27, the forms involving CHAR-1 are no longer used.
(defun c-parse-ps-state-to-cache (state)
  ;; Convert STATE, a `parse-partial-sexp' state valid at POINT, to an element
  ;; for the `c-lit-pos-cache' cache.  This is one of
  ;;   o - POINT (when point is not in a literal);
  ;;   o - (POINT CHAR-1) (when the last character before point is potentially
  ;;       the first of a two-character construct
  ;;   o - (POINT TYPE STARTING-POS) (when in a literal);
  ;;   o - (POINT TYPE STARTING-POS CHAR-1) (Combination of the previous two),
  ;; where TYPE is the type of the literal (either 'c, or 'c++, or the
  ;; character which closes the string), STARTING-POS is the starting
  ;; position of the comment or string.  CHAR-1 is either the character
  ;; potentially forming the first half of a two-char construct (in Emacs <=
  ;; 25 and XEmacs) or the syntax of the character (in Emacs >= 26).
  (if (memq 'pps-extended-state c-emacs-features)
      ;; Emacs >= 26.
      (let ((basic
	     (cond
	      ((nth 3 state)		; A string
	       (list (point) (nth 3 state) (nth 8 state)))
	      ((and (nth 4 state)		 ; A comment
		    (not (eq (nth 7 state) 'syntax-table))) ; but not a pseudo comment.
	       (list (point)
		     (if (eq (nth 7 state) 1) 'c++ 'c)
		     (nth 8 state)))
	      (t			; Neither string nor comment.
	       (point)))))
	(if (nth 10 state)
	    (append (if (consp basic)
			basic
		      (list basic))
		    (list (nth 10 state)))
	  basic))

    ;; Emacs <= 25, XEmacs.
    (cond
     ((nth 3 state)			; A string
      (if (eq (char-before) ?\\)
	  (list (point) (nth 3 state) (nth 8 state) ?\\)
	(list (point) (nth 3 state) (nth 8 state))))
     ((and (nth 4 state)		; comment
	   (not (eq (nth 7 state) 'syntax-table)))
      (if (and (eq (char-before) ?*)
	       (> (- (point) (nth 8 state)) 2)) ; not "/*/".
	  (list (point)
		(if (eq (nth 7 state) 1) 'c++ 'c)
		(nth 8 state)
		?*)
	(list (point)
		(if (eq (nth 7 state) 1) 'c++ 'c)
		(nth 8 state))))
     (t (if (memq (char-before) '(?/ ?\\))
	    (list (point) (char-before))
	  (point))))))