xref: /vim-8.2.3635/runtime/syntax/objc.vim (revision 6c35beaa)
1" Vim syntax file
2" Language:	    Objective C
3" Maintainer:	    Kazunobu Kuriyama <[email protected]>
4" Ex-maintainer:    Anthony Hodsdon <[email protected]>
5" First Author:	    Valentino Kyriakides <[email protected]>
6" Last Change:	    2012 Apr 30
7
8" For version 5.x: Clear all syntax items
9" For version 6.x: Quit when a syntax file was already loaded
10if version < 600
11  syntax clear
12elseif exists("b:current_syntax")
13  finish
14endif
15let s:keepcpo= &cpo
16set cpo&vim
17
18if &filetype != 'objcpp'
19  " Read the C syntax to start with
20  if version < 600
21    source <sfile>:p:h/c.vim
22  else
23    runtime! syntax/c.vim
24  endif
25endif
26
27" Objective C extentions follow below
28"
29" NOTE: Objective C is abbreviated to ObjC/objc
30" and uses *.h, *.m as file extensions!
31
32
33" ObjC keywords, types, type qualifiers etc.
34syn keyword objcStatement	self super _cmd
35syn keyword objcType		id Class SEL IMP BOOL
36syn keyword objcTypeModifier	bycopy in out inout oneway
37syn keyword objcConstant	nil Nil
38
39" Match the ObjC #import directive (like C's #include)
40syn region objcImported display contained start=+"+  skip=+\\\\\|\\"+  end=+"+
41syn match  objcImported display contained "<[-_0-9a-zA-Z.\/]*>"
42syn match  objcImport display "^\s*\(%:\|#\)\s*import\>\s*["<]" contains=objcImported
43
44" Match the important ObjC directives
45syn match  objcScopeDecl    "@public\|@private\|@protected"
46syn match  objcDirective    "@interface\|@implementation"
47syn match  objcDirective    "@class\|@end\|@defs"
48syn match  objcDirective    "@encode\|@protocol\|@selector"
49syn match  objcDirective    "@try\|@catch\|@finally\|@throw\|@synchronized"
50
51" Match the ObjC method types
52"
53" NOTE: here I match only the indicators, this looks
54" much nicer and reduces cluttering color highlightings.
55" However, if you prefer full method declaration matching
56" append .* at the end of the next two patterns!
57"
58syn match objcInstMethod    "^\s*-\s*"
59syn match objcFactMethod    "^\s*+\s*"
60
61" To distinguish from a header inclusion from a protocol list.
62syn match objcProtocol display "<[_a-zA-Z][_a-zA-Z0-9]*>" contains=objcType,cType,Type
63
64
65" To distinguish labels from the keyword for a method's parameter.
66syn region objcKeyForMethodParam display
67    \ start="^\s*[_a-zA-Z][_a-zA-Z0-9]*\s*:\s*("
68    \ end=")\s*[_a-zA-Z][_a-zA-Z0-9]*"
69    \ contains=objcType,objcTypeModifier,cType,cStructure,cStorageClass,Type
70
71" Objective-C Constant Strings
72syn match objcSpecial display "%@" contained
73syn region objcString start=+\(@"\|"\)+ skip=+\\\\\|\\"+ end=+"+ contains=cFormat,cSpecial,objcSpecial
74
75" Objective-C Message Expressions
76syn region objcMessage display start="\[" end="\]" contains=objcMessage,objcStatement,objcType,objcTypeModifier,objcString,objcConstant,objcDirective,cType,cStructure,cStorageClass,cString,cCharacter,cSpecialCharacter,cNumbers,cConstant,cOperator,cComment,cCommentL,Type
77
78syn cluster cParenGroup add=objcMessage
79syn cluster cPreProcGroup add=objcMessage
80
81" Define the default highlighting.
82" For version 5.7 and earlier: only when not done already
83" For version 5.8 and later: only when an item doesn't have highlighting yet
84if version >= 508 || !exists("did_objc_syntax_inits")
85  if version < 508
86    let did_objc_syntax_inits = 1
87    command -nargs=+ HiLink hi link <args>
88  else
89    command -nargs=+ HiLink hi def link <args>
90  endif
91
92  HiLink objcImport		Include
93  HiLink objcImported		cString
94  HiLink objcTypeModifier	objcType
95  HiLink objcType		Type
96  HiLink objcScopeDecl		Statement
97  HiLink objcInstMethod		Function
98  HiLink objcFactMethod		Function
99  HiLink objcStatement		Statement
100  HiLink objcDirective		Statement
101  HiLink objcKeyForMethodParam	None
102  HiLink objcString		cString
103  HiLink objcSpecial		Special
104  HiLink objcProtocol		None
105  HiLink objcConstant		cConstant
106
107  delcommand HiLink
108endif
109
110let b:current_syntax = "objc"
111
112let &cpo = s:keepcpo
113unlet s:keepcpo
114
115" vim: ts=8
116