Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/objective.py: 64%

67 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers.objective 

3 ~~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for Objective-C family languages. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, include, bygroups, using, this, words, \ 

14 inherit, default 

15from pygments.token import Text, Keyword, Name, String, Operator, \ 

16 Number, Punctuation, Literal, Comment 

17 

18from pygments.lexers.c_cpp import CLexer, CppLexer 

19 

20__all__ = ['ObjectiveCLexer', 'ObjectiveCppLexer', 'LogosLexer', 'SwiftLexer'] 

21 

22 

23def objective(baselexer): 

24 """ 

25 Generate a subclass of baselexer that accepts the Objective-C syntax 

26 extensions. 

27 """ 

28 

29 # Have to be careful not to accidentally match JavaDoc/Doxygen syntax here, 

30 # since that's quite common in ordinary C/C++ files. It's OK to match 

31 # JavaDoc/Doxygen keywords that only apply to Objective-C, mind. 

32 # 

33 # The upshot of this is that we CANNOT match @class or @interface 

34 _oc_keywords = re.compile(r'@(?:end|implementation|protocol)') 

35 

36 # Matches [ <ws>? identifier <ws> ( identifier <ws>? ] | identifier? : ) 

37 # (note the identifier is *optional* when there is a ':'!) 

38 _oc_message = re.compile(r'\[\s*[a-zA-Z_]\w*\s+' 

39 r'(?:[a-zA-Z_]\w*\s*\]|' 

40 r'(?:[a-zA-Z_]\w*)?:)') 

41 

42 class GeneratedObjectiveCVariant(baselexer): 

43 """ 

44 Implements Objective-C syntax on top of an existing C family lexer. 

45 """ 

46 

47 tokens = { 

48 'statements': [ 

49 (r'@"', String, 'string'), 

50 (r'@(YES|NO)', Number), 

51 (r"@'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), 

52 (r'@(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), 

53 (r'@(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), 

54 (r'@0x[0-9a-fA-F]+[Ll]?', Number.Hex), 

55 (r'@0[0-7]+[Ll]?', Number.Oct), 

56 (r'@\d+[Ll]?', Number.Integer), 

57 (r'@\(', Literal, 'literal_number'), 

58 (r'@\[', Literal, 'literal_array'), 

59 (r'@\{', Literal, 'literal_dictionary'), 

60 (words(( 

61 '@selector', '@private', '@protected', '@public', '@encode', 

62 '@synchronized', '@try', '@throw', '@catch', '@finally', 

63 '@end', '@property', '@synthesize', '__bridge', '__bridge_transfer', 

64 '__autoreleasing', '__block', '__weak', '__strong', 'weak', 'strong', 

65 'copy', 'retain', 'assign', 'unsafe_unretained', 'atomic', 'nonatomic', 

66 'readonly', 'readwrite', 'setter', 'getter', 'typeof', 'in', 

67 'out', 'inout', 'release', 'class', '@dynamic', '@optional', 

68 '@required', '@autoreleasepool', '@import'), suffix=r'\b'), 

69 Keyword), 

70 (words(('id', 'instancetype', 'Class', 'IMP', 'SEL', 'BOOL', 

71 'IBOutlet', 'IBAction', 'unichar'), suffix=r'\b'), 

72 Keyword.Type), 

73 (r'@(true|false|YES|NO)\n', Name.Builtin), 

74 (r'(YES|NO|nil|self|super)\b', Name.Builtin), 

75 # Carbon types 

76 (r'(Boolean|UInt8|SInt8|UInt16|SInt16|UInt32|SInt32)\b', Keyword.Type), 

77 # Carbon built-ins 

78 (r'(TRUE|FALSE)\b', Name.Builtin), 

79 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), 

80 ('#pop', 'oc_classname')), 

81 (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text), 

82 ('#pop', 'oc_forward_classname')), 

83 # @ can also prefix other expressions like @{...} or @(...) 

84 (r'@', Punctuation), 

85 inherit, 

86 ], 

87 'oc_classname': [ 

88 # interface definition that inherits 

89 (r'([a-zA-Z$_][\w$]*)(\s*:\s*)([a-zA-Z$_][\w$]*)?(\s*)(\{)', 

90 bygroups(Name.Class, Text, Name.Class, Text, Punctuation), 

91 ('#pop', 'oc_ivars')), 

92 (r'([a-zA-Z$_][\w$]*)(\s*:\s*)([a-zA-Z$_][\w$]*)?', 

93 bygroups(Name.Class, Text, Name.Class), '#pop'), 

94 # interface definition for a category 

95 (r'([a-zA-Z$_][\w$]*)(\s*)(\([a-zA-Z$_][\w$]*\))(\s*)(\{)', 

96 bygroups(Name.Class, Text, Name.Label, Text, Punctuation), 

97 ('#pop', 'oc_ivars')), 

98 (r'([a-zA-Z$_][\w$]*)(\s*)(\([a-zA-Z$_][\w$]*\))', 

99 bygroups(Name.Class, Text, Name.Label), '#pop'), 

100 # simple interface / implementation 

101 (r'([a-zA-Z$_][\w$]*)(\s*)(\{)', 

102 bygroups(Name.Class, Text, Punctuation), ('#pop', 'oc_ivars')), 

103 (r'([a-zA-Z$_][\w$]*)', Name.Class, '#pop') 

104 ], 

105 'oc_forward_classname': [ 

106 (r'([a-zA-Z$_][\w$]*)(\s*,\s*)', 

107 bygroups(Name.Class, Text), 'oc_forward_classname'), 

108 (r'([a-zA-Z$_][\w$]*)(\s*;?)', 

109 bygroups(Name.Class, Text), '#pop') 

110 ], 

111 'oc_ivars': [ 

112 include('whitespace'), 

113 include('statements'), 

114 (';', Punctuation), 

115 (r'\{', Punctuation, '#push'), 

116 (r'\}', Punctuation, '#pop'), 

117 ], 

118 'root': [ 

119 # methods 

120 (r'^([-+])(\s*)' # method marker 

121 r'(\(.*?\))?(\s*)' # return type 

122 r'([a-zA-Z$_][\w$]*:?)', # begin of method name 

123 bygroups(Punctuation, Text, using(this), 

124 Text, Name.Function), 

125 'method'), 

126 inherit, 

127 ], 

128 'method': [ 

129 include('whitespace'), 

130 # TODO unsure if ellipses are allowed elsewhere, see 

131 # discussion in Issue 789 

132 (r',', Punctuation), 

133 (r'\.\.\.', Punctuation), 

134 (r'(\(.*?\))(\s*)([a-zA-Z$_][\w$]*)', 

135 bygroups(using(this), Text, Name.Variable)), 

136 (r'[a-zA-Z$_][\w$]*:', Name.Function), 

137 (';', Punctuation, '#pop'), 

138 (r'\{', Punctuation, 'function'), 

139 default('#pop'), 

140 ], 

141 'literal_number': [ 

142 (r'\(', Punctuation, 'literal_number_inner'), 

143 (r'\)', Literal, '#pop'), 

144 include('statement'), 

145 ], 

146 'literal_number_inner': [ 

147 (r'\(', Punctuation, '#push'), 

148 (r'\)', Punctuation, '#pop'), 

149 include('statement'), 

150 ], 

151 'literal_array': [ 

152 (r'\[', Punctuation, 'literal_array_inner'), 

153 (r'\]', Literal, '#pop'), 

154 include('statement'), 

155 ], 

156 'literal_array_inner': [ 

157 (r'\[', Punctuation, '#push'), 

158 (r'\]', Punctuation, '#pop'), 

159 include('statement'), 

160 ], 

161 'literal_dictionary': [ 

162 (r'\}', Literal, '#pop'), 

163 include('statement'), 

164 ], 

165 } 

166 

167 def analyse_text(text): 

168 if _oc_keywords.search(text): 

169 return 1.0 

170 elif '@"' in text: # strings 

171 return 0.8 

172 elif re.search('@[0-9]+', text): 

173 return 0.7 

174 elif _oc_message.search(text): 

175 return 0.8 

176 return 0 

177 

178 def get_tokens_unprocessed(self, text, stack=('root',)): 

179 from pygments.lexers._cocoa_builtins import COCOA_INTERFACES, \ 

180 COCOA_PROTOCOLS, COCOA_PRIMITIVES 

181 

182 for index, token, value in \ 

183 baselexer.get_tokens_unprocessed(self, text, stack): 

184 if token is Name or token is Name.Class: 

185 if value in COCOA_INTERFACES or value in COCOA_PROTOCOLS \ 

186 or value in COCOA_PRIMITIVES: 

187 token = Name.Builtin.Pseudo 

188 

189 yield index, token, value 

190 

191 return GeneratedObjectiveCVariant 

192 

193 

194class ObjectiveCLexer(objective(CLexer)): 

195 """ 

196 For Objective-C source code with preprocessor directives. 

197 """ 

198 

199 name = 'Objective-C' 

200 url = 'https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html' 

201 aliases = ['objective-c', 'objectivec', 'obj-c', 'objc'] 

202 filenames = ['*.m', '*.h'] 

203 mimetypes = ['text/x-objective-c'] 

204 priority = 0.05 # Lower than C 

205 

206 

207class ObjectiveCppLexer(objective(CppLexer)): 

208 """ 

209 For Objective-C++ source code with preprocessor directives. 

210 """ 

211 

212 name = 'Objective-C++' 

213 aliases = ['objective-c++', 'objectivec++', 'obj-c++', 'objc++'] 

214 filenames = ['*.mm', '*.hh'] 

215 mimetypes = ['text/x-objective-c++'] 

216 priority = 0.05 # Lower than C++ 

217 

218 

219class LogosLexer(ObjectiveCppLexer): 

220 """ 

221 For Logos + Objective-C source code with preprocessor directives. 

222 

223 .. versionadded:: 1.6 

224 """ 

225 

226 name = 'Logos' 

227 aliases = ['logos'] 

228 filenames = ['*.x', '*.xi', '*.xm', '*.xmi'] 

229 mimetypes = ['text/x-logos'] 

230 priority = 0.25 

231 

232 tokens = { 

233 'statements': [ 

234 (r'(%orig|%log)\b', Keyword), 

235 (r'(%c)\b(\()(\s*)([a-zA-Z$_][\w$]*)(\s*)(\))', 

236 bygroups(Keyword, Punctuation, Text, Name.Class, Text, Punctuation)), 

237 (r'(%init)\b(\()', 

238 bygroups(Keyword, Punctuation), 'logos_init_directive'), 

239 (r'(%init)(?=\s*;)', bygroups(Keyword)), 

240 (r'(%hook|%group)(\s+)([a-zA-Z$_][\w$]+)', 

241 bygroups(Keyword, Text, Name.Class), '#pop'), 

242 (r'(%subclass)(\s+)', bygroups(Keyword, Text), 

243 ('#pop', 'logos_classname')), 

244 inherit, 

245 ], 

246 'logos_init_directive': [ 

247 (r'\s+', Text), 

248 (',', Punctuation, ('logos_init_directive', '#pop')), 

249 (r'([a-zA-Z$_][\w$]*)(\s*)(=)(\s*)([^);]*)', 

250 bygroups(Name.Class, Text, Punctuation, Text, Text)), 

251 (r'([a-zA-Z$_][\w$]*)', Name.Class), 

252 (r'\)', Punctuation, '#pop'), 

253 ], 

254 'logos_classname': [ 

255 (r'([a-zA-Z$_][\w$]*)(\s*:\s*)([a-zA-Z$_][\w$]*)?', 

256 bygroups(Name.Class, Text, Name.Class), '#pop'), 

257 (r'([a-zA-Z$_][\w$]*)', Name.Class, '#pop') 

258 ], 

259 'root': [ 

260 (r'(%subclass)(\s+)', bygroups(Keyword, Text), 

261 'logos_classname'), 

262 (r'(%hook|%group)(\s+)([a-zA-Z$_][\w$]+)', 

263 bygroups(Keyword, Text, Name.Class)), 

264 (r'(%config)(\s*\(\s*)(\w+)(\s*=)(.*?)(\)\s*)', 

265 bygroups(Keyword, Text, Name.Variable, Text, String, Text)), 

266 (r'(%ctor)(\s*)(\{)', bygroups(Keyword, Text, Punctuation), 

267 'function'), 

268 (r'(%new)(\s*)(\()(.*?)(\))', 

269 bygroups(Keyword, Text, Keyword, String, Keyword)), 

270 (r'(\s*)(%end)(\s*)', bygroups(Text, Keyword, Text)), 

271 inherit, 

272 ], 

273 } 

274 

275 _logos_keywords = re.compile(r'%(?:hook|ctor|init|c\()') 

276 

277 def analyse_text(text): 

278 if LogosLexer._logos_keywords.search(text): 

279 return 1.0 

280 return 0 

281 

282 

283class SwiftLexer(RegexLexer): 

284 """ 

285 For Swift source. 

286 

287 .. versionadded:: 2.0 

288 """ 

289 name = 'Swift' 

290 url = 'https://www.swift.org/' 

291 filenames = ['*.swift'] 

292 aliases = ['swift'] 

293 mimetypes = ['text/x-swift'] 

294 

295 tokens = { 

296 'root': [ 

297 # Whitespace and Comments 

298 (r'\n', Text), 

299 (r'\s+', Text), 

300 (r'//', Comment.Single, 'comment-single'), 

301 (r'/\*', Comment.Multiline, 'comment-multi'), 

302 (r'#(if|elseif|else|endif|available)\b', Comment.Preproc, 'preproc'), 

303 

304 # Keywords 

305 include('keywords'), 

306 

307 # Global Types 

308 (words(( 

309 'Array', 'AutoreleasingUnsafeMutablePointer', 'BidirectionalReverseView', 

310 'Bit', 'Bool', 'CFunctionPointer', 'COpaquePointer', 'CVaListPointer', 

311 'Character', 'ClosedInterval', 'CollectionOfOne', 'ContiguousArray', 

312 'Dictionary', 'DictionaryGenerator', 'DictionaryIndex', 'Double', 

313 'EmptyCollection', 'EmptyGenerator', 'EnumerateGenerator', 

314 'EnumerateSequence', 'FilterCollectionView', 

315 'FilterCollectionViewIndex', 'FilterGenerator', 'FilterSequenceView', 

316 'Float', 'Float80', 'FloatingPointClassification', 'GeneratorOf', 

317 'GeneratorOfOne', 'GeneratorSequence', 'HalfOpenInterval', 'HeapBuffer', 

318 'HeapBufferStorage', 'ImplicitlyUnwrappedOptional', 'IndexingGenerator', 

319 'Int', 'Int16', 'Int32', 'Int64', 'Int8', 'LazyBidirectionalCollection', 

320 'LazyForwardCollection', 'LazyRandomAccessCollection', 

321 'LazySequence', 'MapCollectionView', 'MapSequenceGenerator', 

322 'MapSequenceView', 'MirrorDisposition', 'ObjectIdentifier', 'OnHeap', 

323 'Optional', 'PermutationGenerator', 'QuickLookObject', 

324 'RandomAccessReverseView', 'Range', 'RangeGenerator', 'RawByte', 'Repeat', 

325 'ReverseBidirectionalIndex', 'ReverseRandomAccessIndex', 'SequenceOf', 

326 'SinkOf', 'Slice', 'StaticString', 'StrideThrough', 'StrideThroughGenerator', 

327 'StrideTo', 'StrideToGenerator', 'String', 'UInt', 'UInt16', 'UInt32', 

328 'UInt64', 'UInt8', 'UTF16', 'UTF32', 'UTF8', 'UnicodeDecodingResult', 

329 'UnicodeScalar', 'Unmanaged', 'UnsafeBufferPointer', 

330 'UnsafeBufferPointerGenerator', 'UnsafeMutableBufferPointer', 

331 'UnsafeMutablePointer', 'UnsafePointer', 'Zip2', 'ZipGenerator2', 

332 # Protocols 

333 'AbsoluteValuable', 'AnyObject', 'ArrayLiteralConvertible', 

334 'BidirectionalIndexType', 'BitwiseOperationsType', 

335 'BooleanLiteralConvertible', 'BooleanType', 'CVarArgType', 

336 'CollectionType', 'Comparable', 'DebugPrintable', 

337 'DictionaryLiteralConvertible', 'Equatable', 

338 'ExtendedGraphemeClusterLiteralConvertible', 

339 'ExtensibleCollectionType', 'FloatLiteralConvertible', 

340 'FloatingPointType', 'ForwardIndexType', 'GeneratorType', 'Hashable', 

341 'IntegerArithmeticType', 'IntegerLiteralConvertible', 'IntegerType', 

342 'IntervalType', 'MirrorType', 'MutableCollectionType', 'MutableSliceable', 

343 'NilLiteralConvertible', 'OutputStreamType', 'Printable', 

344 'RandomAccessIndexType', 'RangeReplaceableCollectionType', 

345 'RawOptionSetType', 'RawRepresentable', 'Reflectable', 'SequenceType', 

346 'SignedIntegerType', 'SignedNumberType', 'SinkType', 'Sliceable', 

347 'Streamable', 'Strideable', 'StringInterpolationConvertible', 

348 'StringLiteralConvertible', 'UnicodeCodecType', 

349 'UnicodeScalarLiteralConvertible', 'UnsignedIntegerType', 

350 '_ArrayBufferType', '_BidirectionalIndexType', '_CocoaStringType', 

351 '_CollectionType', '_Comparable', '_ExtensibleCollectionType', 

352 '_ForwardIndexType', '_Incrementable', '_IntegerArithmeticType', 

353 '_IntegerType', '_ObjectiveCBridgeable', '_RandomAccessIndexType', 

354 '_RawOptionSetType', '_SequenceType', '_Sequence_Type', 

355 '_SignedIntegerType', '_SignedNumberType', '_Sliceable', '_Strideable', 

356 '_SwiftNSArrayRequiredOverridesType', '_SwiftNSArrayType', 

357 '_SwiftNSCopyingType', '_SwiftNSDictionaryRequiredOverridesType', 

358 '_SwiftNSDictionaryType', '_SwiftNSEnumeratorType', 

359 '_SwiftNSFastEnumerationType', '_SwiftNSStringRequiredOverridesType', 

360 '_SwiftNSStringType', '_UnsignedIntegerType', 

361 # Variables 

362 'C_ARGC', 'C_ARGV', 'Process', 

363 # Typealiases 

364 'Any', 'AnyClass', 'BooleanLiteralType', 'CBool', 'CChar', 'CChar16', 

365 'CChar32', 'CDouble', 'CFloat', 'CInt', 'CLong', 'CLongLong', 'CShort', 

366 'CSignedChar', 'CUnsignedInt', 'CUnsignedLong', 'CUnsignedShort', 

367 'CWideChar', 'ExtendedGraphemeClusterType', 'Float32', 'Float64', 

368 'FloatLiteralType', 'IntMax', 'IntegerLiteralType', 'StringLiteralType', 

369 'UIntMax', 'UWord', 'UnicodeScalarType', 'Void', 'Word', 

370 # Foundation/Cocoa 

371 'NSErrorPointer', 'NSObjectProtocol', 'Selector'), suffix=r'\b'), 

372 Name.Builtin), 

373 # Functions 

374 (words(( 

375 'abs', 'advance', 'alignof', 'alignofValue', 'assert', 'assertionFailure', 

376 'contains', 'count', 'countElements', 'debugPrint', 'debugPrintln', 

377 'distance', 'dropFirst', 'dropLast', 'dump', 'enumerate', 'equal', 

378 'extend', 'fatalError', 'filter', 'find', 'first', 'getVaList', 'indices', 

379 'insert', 'isEmpty', 'join', 'last', 'lazy', 'lexicographicalCompare', 

380 'map', 'max', 'maxElement', 'min', 'minElement', 'numericCast', 'overlaps', 

381 'partition', 'precondition', 'preconditionFailure', 'prefix', 'print', 

382 'println', 'reduce', 'reflect', 'removeAll', 'removeAtIndex', 'removeLast', 

383 'removeRange', 'reverse', 'sizeof', 'sizeofValue', 'sort', 'sorted', 

384 'splice', 'split', 'startsWith', 'stride', 'strideof', 'strideofValue', 

385 'suffix', 'swap', 'toDebugString', 'toString', 'transcode', 

386 'underestimateCount', 'unsafeAddressOf', 'unsafeBitCast', 'unsafeDowncast', 

387 'withExtendedLifetime', 'withUnsafeMutablePointer', 

388 'withUnsafeMutablePointers', 'withUnsafePointer', 'withUnsafePointers', 

389 'withVaList'), suffix=r'\b'), 

390 Name.Builtin.Pseudo), 

391 

392 # Implicit Block Variables 

393 (r'\$\d+', Name.Variable), 

394 

395 # Binary Literal 

396 (r'0b[01_]+', Number.Bin), 

397 # Octal Literal 

398 (r'0o[0-7_]+', Number.Oct), 

399 # Hexadecimal Literal 

400 (r'0x[0-9a-fA-F_]+', Number.Hex), 

401 # Decimal Literal 

402 (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?[0-9_]+|' 

403 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)', Number.Float), 

404 (r'[0-9][0-9_]*', Number.Integer), 

405 # String Literal 

406 (r'"', String, 'string'), 

407 

408 # Operators and Punctuation 

409 (r'[(){}\[\].,:;=@#`?]|->|[<&?](?=\w)|(?<=\w)[>!?]', Punctuation), 

410 (r'[/=\-+!*%<>&|^?~]+', Operator), 

411 

412 # Identifier 

413 (r'[a-zA-Z_]\w*', Name) 

414 ], 

415 'keywords': [ 

416 (words(( 

417 'as', 'async', 'await', 'break', 'case', 'catch', 'continue', 'default', 'defer', 

418 'do', 'else', 'fallthrough', 'for', 'guard', 'if', 'in', 'is', 

419 'repeat', 'return', '#selector', 'switch', 'throw', 'try', 

420 'where', 'while'), suffix=r'\b'), 

421 Keyword), 

422 (r'@availability\([^)]+\)', Keyword.Reserved), 

423 (words(( 

424 'associativity', 'convenience', 'dynamic', 'didSet', 'final', 

425 'get', 'indirect', 'infix', 'inout', 'lazy', 'left', 'mutating', 

426 'none', 'nonmutating', 'optional', 'override', 'postfix', 

427 'precedence', 'prefix', 'Protocol', 'required', 'rethrows', 

428 'right', 'set', 'throws', 'Type', 'unowned', 'weak', 'willSet', 

429 '@availability', '@autoclosure', '@noreturn', 

430 '@NSApplicationMain', '@NSCopying', '@NSManaged', '@objc', 

431 '@UIApplicationMain', '@IBAction', '@IBDesignable', 

432 '@IBInspectable', '@IBOutlet'), suffix=r'\b'), 

433 Keyword.Reserved), 

434 (r'(as|dynamicType|false|is|nil|self|Self|super|true|__COLUMN__' 

435 r'|__FILE__|__FUNCTION__|__LINE__|_' 

436 r'|#(?:file|line|column|function))\b', Keyword.Constant), 

437 (r'import\b', Keyword.Declaration, 'module'), 

438 (r'(class|enum|extension|struct|protocol)(\s+)([a-zA-Z_]\w*)', 

439 bygroups(Keyword.Declaration, Text, Name.Class)), 

440 (r'(func)(\s+)([a-zA-Z_]\w*)', 

441 bygroups(Keyword.Declaration, Text, Name.Function)), 

442 (r'(var|let)(\s+)([a-zA-Z_]\w*)', bygroups(Keyword.Declaration, 

443 Text, Name.Variable)), 

444 (words(( 

445 'actor', 'associatedtype', 'class', 'deinit', 'enum', 'extension', 'func', 'import', 

446 'init', 'internal', 'let', 'operator', 'private', 'protocol', 'public', 

447 'static', 'struct', 'subscript', 'typealias', 'var'), suffix=r'\b'), 

448 Keyword.Declaration) 

449 ], 

450 'comment': [ 

451 (r':param: [a-zA-Z_]\w*|:returns?:|(FIXME|MARK|TODO):', 

452 Comment.Special) 

453 ], 

454 

455 # Nested 

456 'comment-single': [ 

457 (r'\n', Text, '#pop'), 

458 include('comment'), 

459 (r'[^\n]', Comment.Single) 

460 ], 

461 'comment-multi': [ 

462 include('comment'), 

463 (r'[^*/]', Comment.Multiline), 

464 (r'/\*', Comment.Multiline, '#push'), 

465 (r'\*/', Comment.Multiline, '#pop'), 

466 (r'[*/]', Comment.Multiline) 

467 ], 

468 'module': [ 

469 (r'\n', Text, '#pop'), 

470 (r'[a-zA-Z_]\w*', Name.Class), 

471 include('root') 

472 ], 

473 'preproc': [ 

474 (r'\n', Text, '#pop'), 

475 include('keywords'), 

476 (r'[A-Za-z]\w*', Comment.Preproc), 

477 include('root') 

478 ], 

479 'string': [ 

480 (r'\\\(', String.Interpol, 'string-intp'), 

481 (r'"', String, '#pop'), 

482 (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" 

483 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape), 

484 (r'[^\\"]+', String), 

485 (r'\\', String) 

486 ], 

487 'string-intp': [ 

488 (r'\(', String.Interpol, '#push'), 

489 (r'\)', String.Interpol, '#pop'), 

490 include('root') 

491 ] 

492 } 

493 

494 def get_tokens_unprocessed(self, text): 

495 from pygments.lexers._cocoa_builtins import COCOA_INTERFACES, \ 

496 COCOA_PROTOCOLS, COCOA_PRIMITIVES 

497 

498 for index, token, value in \ 

499 RegexLexer.get_tokens_unprocessed(self, text): 

500 if token is Name or token is Name.Class: 

501 if value in COCOA_INTERFACES or value in COCOA_PROTOCOLS \ 

502 or value in COCOA_PRIMITIVES: 

503 token = Name.Builtin.Pseudo 

504 

505 yield index, token, value