(require 'font-lock)
(defvar font-lock-special-comment-face 'font-lock-special-comment-face
"Don't even think of using this.")
(defface font-lock-special-comment-face
'((((class color) (background dark)) (:foreground "gray80"))
(((class color) (background light)) (:foreground "blue4"))
(((class grayscale) (background light))
(:foreground "DimGray" :bold t :italic t))
(((class grayscale) (background dark))
(:foreground "LightGray" :bold t :italic t))
(t (:bold t)))
"Font Lock mode face used to highlight special comments."
:group 'font-lock-faces)
(defvar font-lock-special-keyword-face 'font-lock-special-keyword-face
"Don't even think of using this.")
(defface font-lock-special-keyword-face
'((((class color) (background dark)) (:foreground "cyan"))
(((class color) (background light)) (:foreground "red4"))
(((class grayscale) (background light)) (:foreground "LightGray" :bold t))
(((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
(t (:bold t)))
"Font Lock mode face used to highlight special keywords."
:group 'font-lock-faces)
(defvar font-lock-warning-face 'font-lock-warning-face
"Don't even think of using this.")
(defface font-lock-warning-face
'((((class color) (background light)) (:foreground "Red" :bold t))
(((class color) (background dark)) (:foreground "Pink" :bold t))
(t (:inverse-video t :bold t)))
"Font Lock mode face used to highlight warnings."
:group 'font-lock-faces)
(setq font-lock-face-list (append font-lock-face-list
'(font-lock-special-comment-face
font-lock-special-keyword-face)))
:-::(let*
((common-keywords
(concat "asm\\|do\\|virtual\\|typeid\\|case\\|"
"class\\|struct\\|enum\\|union\\|explicit\\|mutable\\|"
"static\\|extern\\|auto\\|register\\|new\\|delete\\|"
"using\\|namespace\\|type\\(name\\|def\\)\\|"
"else\\|for\\|if\\|template\\|friend\\|inline\\|"
"p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|malloc\\|free\\|"
"s\\(izeof\\|witch\\)\\|this\\|while"))
(special-keywords
(concat "DEBUG_PRINT\\|DebugIsEnabled\\|DEBUGGING\\|DEBUG\\|"
"DEBUG_ENTER\\|GET_DEBUG_FLAGS\\|SET_DEBUG_FLAGS\\|"
"DEBUG_EXIT\\|DEBUG_INIT\\|FLDEBUG\\|ASSERT_ALWAYS\\|"
"ASSERT\\|assert"))
(warning-keywords
(concat "Warn\\|Die\\|Fatal\\|FATAL\\|Warning\\|exit\\|return\\|break"
"\\|continue\\|throw\\|try\\|catch"))
(ws* "[ \t]*")
(ws+ "[ \t]+")
(ws+-or-$ (concat "\\(?:" ws+ "\\|$\\)"))
(template-ext "\\(?:<\\(?:>\\|[^ >\n][^>\n]*>\\| .* >\\)\\)")
(name-prefix (concat "\\(?:\\<\\sw+" template-ext "?::\\)"))
(name-suffix (concat "\\<\\sw+" template-ext "?"))
(name (concat "\\(?:" name-prefix "\\{0,2\\}\\|::\\)" name-suffix))
(array-ext-no-parens "\\(?:\\[[^,=;\n.-]*\\]\\)")
(array-ext (concat "\\(" array-ext-no-parens "\\)"))
(type-name name)
(type-quals
(concat
"\\(?:\\(?:\\(?:static\\|extern\\|auto\\|register\\|inline\\|friend\\)"
ws+ "\\)?"
"\\(?:\\(?:volatile\\|const\\|mutable\\)" ws+ "\\)?"
"\\(?:\\(?:struct\\|class\\|enum\\|union\\|typename"
"\\|signed\\|unsigned\\)" ws+ "\\)?\\)"))
(type-extra
(concat "\\(?:" ws+
"\\(?:long\\|int\\|char\\|short\\|double\\)\\>\\)?"))
(type
(concat "\\(" type-quals type-name type-extra "\\(?:"
"\\(?:[*&]+\\(?:" ws* "\\(?:volatile\\|const\\)\\>\\)?" ws+-or-$ "\\)"
"\\|"
"\\(?:" ws+ "[*&]+\\(?:" ws* "\\(?:volatile\\|const\\)\\>" ws+-or-$ "\\)?\\)"
"\\|\\(?:" ws+-or-$ "\\)\\)\\)"
))
(type-cast
(concat "\\(?:" type-quals type-name type-extra ws* "[*&]*"
"\\(?:" ws* "\\(?:volatile\\|const\\)\\>\\)?" ws*
array-ext-no-parens "?\\)"
))
(var-name
(concat "\\(" name "\\)"))
(var-normal
(concat var-name array-ext "?"))
(var-fcn-ptr
(concat "(\\(" name-prefix "\\{0,2\\}[*]\\)" ws*
var-name ")(\\([^)\n]*\\))"))
(var-decl
(concat type "\\(?:" var-normal "\\|" var-fcn-ptr "\\)"))
(var-multi
(concat "\\(?:," ws* "\\([*]*\\)" ws* var-name array-ext "?\\)"))
(fcn-normal-suffix
(concat "\\(?:~?\\<\\sw+\\>\\)"))
(fcn-opr-suffix
(concat "\\(?:\\<operator\\(?:\\(?:..?" ws* "\\)\\|\\(?:"
ws+ type-cast "\\(?:\\[\\]\\)?\\)\\)\\)"))
(fcn-name
(concat "\\(\\(?:\\(?:" name-prefix "\\{0,2\\}\\)\\|::\\)\\(?:"
fcn-opr-suffix "\\|" fcn-normal-suffix "\\)\\(?:"
ws* template-ext "\\)?\\)")))
(defsubst compute-type-face (end type fcn-name)
(save-excursion
(save-match-data
(if (ignore-errors (up-list -1) t)
(if (looking-at "(")
(progn
(skip-chars-backward "^{:\n")
(if (search-backward-regexp ")[ \t]*:" (point-at-bol) t)
(get-face 'default)
(skip-chars-backward "^{;\n")
(if (looking-at "^[ \t]+\\(?:if\\>\\|while\\>\\|for\\>\\)")
(progn
(goto-char end)
(if (looking-at "[ \t]*=")
(get-face 'default)
font-lock-type-face))
(if (ignore-errors (up-list -1) t)
(progn
(search-backward-regexp
(concat "^[ \t]*\\(?:\\(class\\|struct"
"\\|namespace\\|extern\\)\\>"
"\\|\\(?:virtual[ \t]+\\)?"
"\\(?:" type "\\)?"
fcn-name "[ \t]*(\\)")
(point-min) t)
(if (looking-at
(concat "^[ \t]*\\(class\\|struct"
"\\|namespace\\|extern\\)\\>"))
font-lock-type-face
(get-face 'default)))
font-lock-type-face))))
(search-backward-regexp "^[ \t]*\\sw+" (point-min) t)
(if (looking-at "[ \t]*enum\\>")
font-lock-variable-name-face
(goto-char end)
(if (and (looking-at "[,;]")
(looking-at "[^\n>]*;"))
font-lock-variable-name-face
(get-face 'default))))
(get-face 'default)))))
(setq c-font-lock-keywords-3
(list
'("^#[ \t]*include[ \t]+<\\([^>\"\n]+\\)>" 1 font-lock-string-face)
'("^#[ \T]*define[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face)
'("^#[ \t]*if\\>"
("\\<\\(defined\\)\\>[ \t]*(\\(\\sw+\\)?" nil nil
(1 font-lock-preprocessor-face) (2 font-lock-reference-face nil t)))
'("^\\(#[ \t]*ifndef\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-preprocessor-face) (2 font-lock-reference-face nil t))
'("^\\(#[ \t]*ifdef\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-preprocessor-face) (2 font-lock-reference-face nil t))
(list "^\\(#[ \t]*\\(?:if\\|elif\\)\\)\\>[ \t]*\\(.*\\)?"
'(1 font-lock-preprocessor-face)
'(2 font-lock-reference-face keep t))
'("^\\(#[ \t]*\\(?:define\\|undef\\)\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t))
'("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(.*\\)?"
(1 font-lock-preprocessor-face) (2 font-lock-special-keyword-face nil t))
'("\\(--- .*? ---\\)" 1 font-lock-special-comment-face t)
(list (concat "\\(XXX:\\(?:" ws* "<\\(" name "\\)>\\)?.*\\)")
'(1 font-lock-special-comment-face t)
'(2 font-lock-doc-string-face t t))
(cons (concat "\\<\\(" common-keywords "\\)\\>") 'font-lock-keyword-face)
(cons (concat "\\<\\(" special-keywords "\\)\\>")
'font-lock-special-keyword-face)
(cons (concat "\\<\\(" warning-keywords "\\)\\>")
'font-lock-warning-face)
'("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
(1 font-lock-warning-face keep) (2 font-lock-reference-face nil t))
'("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face)
(list (concat "\\<new" ws+ "\\(?:(\\(" ws* name ws* "\\))" ws* "\\)?\\("
type-cast "\\)")
'(1 font-lock-reference-face nil t)
'(2 font-lock-type-face keep))
::operator (list (concat "\\W\\(::operator\\)" ws+) 1 font-lock-keyword-face)
(list (concat "\\(?:sizeof\\|typeid\\)(\\(" type-cast "\\))")
1 font-lock-type-face 'keep)
(list (concat "^" ws* "\\<typedef" ws+ "\\(?:"
"\\(\\(?:\\(?:const\\|volatile\\)" ws+ "\\)?"
"\\(?:\\(?:typename\\)" ws+ "\\)?"
"\\(?:struct\\|class\\|enum\\|union\\)" ws+ "\\){"
"\\|\\(?:" var-decl "\\(" ws* "{\\)?\\)\\)")
'(1 font-lock-type-face keep t)
'(2 font-lock-type-face keep t)
'(3 (if (match-beginning 8) font-lock-type-face
font-lock-variable-name-face) nil t)
'(4 font-lock-type-face nil t)
'(5 font-lock-type-face nil t)
'(6 (if (match-beginning 8) font-lock-type-face
font-lock-variable-name-face) nil t)
'(7 font-lock-type-face nil t))
(list (concat "\\<\\(?:struct\\|class\\|enum\\|union\\)" ws+
"\\(" name "\\)?" ws* "\\([{;:,=>]\\|$\\)")
'(1 (if (string-match "[,=>]" (match-string 2))
(if (ignore-errors (up-list -1) t)
(if (looking-at "(")
font-lock-type-face
font-lock-doc-string-face)
font-lock-doc-string-face)
(save-excursion
(save-match-data
(if (search-backward-regexp "\\<friend\\>"
(point-at-bol) t)
font-lock-type-face
font-lock-reference-face)))) nil t))
(list (concat "}" ws* "\\([*]*\\)" ws* var-name array-ext "?" ws* "[:;]")
'(1 font-lock-type-face nil t)
'(2 (save-excursion
(save-match-data
(goto-char (match-beginning 0))
(if (ignore-errors (up-list -1) t)
(progn
(skip-chars-backward " \t\n")
(beginning-of-line)
(if (looking-at "^[ \t]*typedef\\>")
font-lock-reference-face
font-lock-variable-name-face))
font-lock-reference-face))))
'(3 font-lock-type-face nil t))
(list (concat "\\<\\(?:virtual" ws+ "\\)?"
"\\(?:public\\|protected\\|private\\)" ws+ "\\(" name "\\)")
1 font-lock-type-face 'keep)
(list (concat "^" ws* type ws* "$") 1 font-lock-type-face 'keep)
(list (concat "^\\(" ws+ "\\)?\\(?:virtual" ws+ "\\)?" "\\(?:" type "\\)?"
fcn-name ws* "(\\($\\|)\\|\\(" type-cast
"\\|\\.\\.\\.\\)[,=)/]\\|\\(" var-decl "\\)\\)")
'(2 (save-match-data
(if (and (match-string 2)
(string-match "^operator\\>" (match-string 2)))
font-lock-function-name-face
font-lock-type-face)) keep t)
`(3 (save-excursion
(save-match-data
(let ((context (save-match-data (buffer-syntactic-context))))
(if (not context)
(if (not (match-string 1))
(setq the-face font-lock-function-name-face)
(if (and (match-string 7)
(string-match
"\\<new\\>\\|\\<delete\\>"
(match-string 7)))
(setq the-face font-lock-variable-name-face)
(if (and (match-string 2)
(string-match "\\<extern\\>"
(match-string 2)))
(setq the-face font-lock-function-name-face)
(if (string-match
"^\\<\\(?:for\\|while\\|if\\)\\>"
(match-string 3))
(setq the-face font-lock-keyword-face)
(if (string-match
(concat "\\<\\(?:"
,special-keywords "\\)\\>")
(match-string 3))
(setq the-face
font-lock-special-keyword-face)
(if (string-match
"^\\<\\(?:catch\\|return\\)\\>"
(match-string 3))
(setq the-face font-lock-warning-face)
(goto-char (match-beginning 3))
(if (ignore-errors (up-list -1) t)
(progn
(save-match-data
(search-backward-regexp
(concat
"^[ \t]*\\(?:\\(class\\|struct"
"\\|namespace\\|extern\\)\\>"
"\\|\\(?:virtual[ \t]+\\)?"
"\\(?:" ,type "\\)?"
,fcn-name "[ \t]*(\\)")
(point-min) t))
(if (looking-at
(concat
"^[ \t]*\\(class\\|struct\\|"
"namespace\\|extern\\)\\>"))
(setq the-face
font-lock-function-name-face)
(if (and (match-string 2)
(not (string-match
"^return"
(match-string 2))))
(setq the-face
font-lock-variable-name-face)
(setq the-face
(get-face 'default))))
)
(setq the-face
font-lock-function-name-face))))))))
(case context
(string font-lock-string-face)
(comment font-lock-comment-face)
(block-comment font-lock-comment-face))
)))) t)
'(5 (if (eq the-face font-lock-function-name-face)
font-lock-type-face
(save-match-data
(if (and (eq the-face font-lock-warning-face)
(string-match "\\<catch\\>" (match-string 3))
(match-string 5))
(save-excursion
(save-match-data
(goto-char (match-end 5))
(if (looking-at ")")
font-lock-type-face
(get-face 'default))))
(get-face 'default)))) keep t)
'(7 (save-match-data
(if (and (match-string 7)
(string-match "\\<new\\>\\|\\<delete\\>"
(match-string 7)))
font-lock-keyword-face
font-lock-type-face)) keep t)
'(8 (save-match-data
(if (and (match-string 7)
(string-match "\\<delete\\>" (match-string 7)))
(get-face 'default)
font-lock-variable-name-face)) nil t)
'(9 font-lock-type-face nil t)
'(10 font-lock-type-face nil t)
'(11 font-lock-variable-name-face nil t)
'(12 font-lock-type-face nil t)
(list
(concat "," ws* "\\(" type-cast "\\)")
'(goto-char (or (match-beginning 4)
(match-beginning 5)
(match-beginning 6)))
nil
`(1 (compute-type-face (match-end 1) ,type ,fcn-name) keep)))
(list (concat ")" ws* "\\(const\\>\\)") 1 font-lock-type-face)
(list (concat "[^a-zA-Z0-9_](\\(" type-cast "\\))" ws* "[(_a-zA-Z0-9&]")
'(1 font-lock-type-face keep))
(list
(concat "\\<\\(\\(?:\\(?:const\\|dynamic\\|reinterpret\\|static\\)"
"_cast<\\)\\|auto_ptr<\\)\\(" ws* type-cast ws* "\\)\\(>\\)")
'(1 font-lock-keyword-face) '(2 font-lock-type-face keep)
'(3 font-lock-keyword-face))
(list (concat "^" ws* "friend" ws+ type)
1 font-lock-type-face)
(list (concat "^" ws* "\\(?:using" ws+ "\\)?namespace" ws+
"\\(" name "\\)")
1 font-lock-reference-face)
(list (concat "^" ws+ "\\(" type-cast "\\)" ws* "\\([,=)/]\\)")
`(1 (save-excursion
(save-match-data
(goto-char (match-beginning 1))
(compute-type-face (match-end 1) ,type ,fcn-name))) keep)
(list
(concat "," ws* "\\(" type-cast "\\)")
'(goto-char (match-beginning 2)) nil
`(1 (compute-type-face (match-end 1) ,type ,fcn-name) keep)))
(list (concat "^" ws+ var-decl ws* "\\([,)=]\\)")
(list
(concat "," ws* "\\(" type-cast "\\)")
'(goto-char (match-beginning 7)) nil
`(1 (compute-type-face (match-end 1) ,type ,fcn-name) keep)))
(list (concat "^" ws* "enum\\>[^{]*\\({\\)" ws*)
(list
(concat "[{,]" ws* "\\(" type-cast "\\)")
'(goto-char (match-beginning 1)) nil
`(1 (compute-type-face (match-end 1) ,type ,fcn-name) keep)))
(list (concat "," ws* var-decl)
'(1 font-lock-type-face keep)
'(2 (save-match-data
(if (string-match
"^delete\\>\\|^return\\>\\|typename[ \t]*$"
(match-string 1))
(get-face 'default)
(if (string-match "^asm\\>" (match-string 1))
font-lock-type-face
font-lock-variable-name-face))) nil t)
'(3 font-lock-type-face nil t)
'(4 font-lock-type-face nil t)
'(5 font-lock-variable-name-face nil t)
'(6 font-lock-type-face nil t))
(list (concat "^" ws* "\\(?:template" ws* "<\\)?" var-decl
var-multi "?" var-multi "?")
'(1 (save-match-data
(if (and (match-string 1)
(string-match
"^\\(?:delete\\>\\|return\\>\\|typename[ \t]*$\\)"
(match-string 1)))
(get-face 'default)
font-lock-type-face)) keep t)
'(2 (save-match-data
(let ((ms1 (match-string 1)))
(if (string-match
(concat "^\\(?:delete\\>\\|return\\>"
"\\|throw\\>\\|else\\>\\|inline\\>"
"\\|typedef\\>\\|typename[ \t]*$\\)") ms1)
(if (string-match "\\<throw\\>" ms1)
font-lock-reference-face
(get-face 'default))
(if (string-match "^asm\\>" ms1)
font-lock-type-face
font-lock-variable-name-face)))) nil t)
'(3 (save-match-data
(if (and (match-string 1)
(string-match
"^\\(?:delete\\>\\|return\\>\\|typename[ \t]*$\\)"
(match-string 1)))
(get-face 'default)
font-lock-type-face)) nil t)
'(4 font-lock-type-face nil t)
'(5 font-lock-variable-name-face nil t)
'(6 font-lock-type-face nil t)
'(7 font-lock-type-face nil t)
'(8 font-lock-variable-name-face nil t)
'(9 font-lock-type-face nil t)
'(10 font-lock-type-face nil t)
'(11 font-lock-variable-name-face nil t)
'(12 font-lock-type-face nil t))
(list (concat "^" ws* "\\(extern\\)" ws* "\"") 1 font-lock-keyword-face)
'("\\.\\.\\." . font-lock-type-face)
'("\\<delete\\(\\[\\]\\)" 1 font-lock-keyword-face)))
(setq c++-font-lock-keywords-3 c-font-lock-keywords-3)
)
(setq c-font-lock-keywords c-font-lock-keywords-3)
(setq c++-font-lock-keywords c++-font-lock-keywords-3)
(provide 'c-font-lock-keywords)