Function: c-awk-font-lock-invalid-namespace-separators

c-awk-font-lock-invalid-namespace-separators is a byte-compiled function defined in cc-awk.el.gz.

Signature

(c-awk-font-lock-invalid-namespace-separators LIMIT)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-awk.el.gz
;; The following section of the code is to do with font-locking.  The biggest
;; problem for font-locking is deciding whether a / is a regular expression
;; delimiter or a division sign - determining precisely where strings and
;; regular expressions start and stop is also troublesome.  This is the
;; purpose of the function c-awk-set-syntax-table-properties and the myriad
;; elisp regular expressions it uses.
;;
;; Because AWK is a line oriented language, I felt the normal cc-mode strategy
;; for font-locking unterminated strings (i.e. font-locking the buffer up to
;; the next string delimiter as a string) was inappropriate.  Instead,
;; unbalanced string/regexp delimiters are given the warning font, being
;; refonted with the string font as soon as the matching delimiter is entered.
;;
;; This requires the region processed by the current font-lock after-change
;; function to have access to the start of the string/regexp, which may be
;; several lines back.  The elisp "advice" feature is used on these functions
;; to allow this.

(defun c-awk-font-lock-invalid-namespace-separators (limit)
  ;; This function will be called from font-lock for a region bounded by POINT
  ;; and LIMIT, as though it were to identify a keyword for
  ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
  ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
  ;; Fontification".
  ;;
  ;; This function gives invalid GAWK namespace separators (::)
  ;; font-lock-warning-face.  "Invalid" here means there are spaces, etc.,
  ;; around a separator, or there are more than one of them in an identifier.
  ;; Invalid separators inside function declaration parentheses are handled
  ;; elsewhere.
  (while (and
	  (< (point) limit)
	  (c-syntactic-re-search-forward
	   (eval-when-compile
	     (concat "\\([^" (c-lang-const c-symbol-chars awk) "]::\\)"
		     "\\|"
		     ;; "\\(::[^" (c-lang-const c-symbol-start awk) "]\\)"
		     "\\(::[^" c-alpha "_" "]\\)"
		     "\\|"
		     "\\(::[" (c-lang-const c-symbol-chars awk) "]*::\\)"))
	   limit 'bound))
    (cond
     ((match-beginning 1)               ; " ::"
      (c-put-font-lock-face (1+ (match-beginning 1)) (match-end 1)
			    'font-lock-warning-face)
      (goto-char (- (match-end 1) 2)))
     ((match-beginning 2)		; ":: "
      (c-put-font-lock-face (match-beginning 2) (1- (match-end 2))
			    'font-lock-warning-face)
      (goto-char (1- (match-end 2))))
     (t					; "::foo::"
      (c-put-font-lock-face (match-beginning 3) (+ 2 (match-beginning 3))
			    'font-lock-warning-face)
      (c-put-font-lock-face (- (match-end 3) 2) (match-end 3)
			    'font-lock-warning-face)
      (goto-char (- (match-end 3) 2)))))
    nil)