5
5
from pygments .lexer import (
6
6
RegexLexer ,
7
7
bygroups ,
8
- include ,
9
8
default ,
9
+ include ,
10
10
)
11
11
from pygments .token import (
12
12
Comment ,
23
23
24
24
__all__ = ['SwiftLexer' , 'SILLexer' , 'SwiftConsoleLexer' ]
25
25
26
+
26
27
class SwiftLexer (RegexLexer ):
27
28
name = 'Swift'
28
29
aliases = ['swift' ]
@@ -33,7 +34,8 @@ class SwiftLexer(RegexLexer):
33
34
_isa = r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(:)(\s*)([A-Z0-9_][a-zA-Z0-9_]*)'
34
35
_isa_comma = r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(:)(\s*)' + \
35
36
'([A-Z0-9_][a-zA-Z0-9_]*)(,\s?)'
36
- _name = u'([@a-zA-Z_\U00000100 -\U00100000 ][a-zA-Z0-9_\U00000100 -\U00100000 ]*)'
37
+ _name = u'([@a-zA-Z_\U00000100 -\U00100000 ]' + \
38
+ u'[a-zA-Z0-9_\U00000100 -\U00100000 ]*)'
37
39
38
40
tokens = {
39
41
@@ -51,7 +53,8 @@ class SwiftLexer(RegexLexer):
51
53
],
52
54
53
55
'func-class-list' : [
54
- (r'\b(func|init|deinit|class func|public func)\s' , Keyword .Declaration , 'func-decl' ),
56
+ (r'\b(func|init|deinit|class func|public func)\s' ,
57
+ Keyword .Declaration , 'func-decl' ),
55
58
],
56
59
57
60
'comment' : [
@@ -66,7 +69,7 @@ class SwiftLexer(RegexLexer):
66
69
'body' : [
67
70
include ('comment' ),
68
71
include ('name' ),
69
- (r'\.{3}' , Generic .Emph ), # emphasize ellipses
72
+ (r'\.{3}' , Generic .Emph ), # emphasize ellipses
70
73
(r'[\~\^\*!%&<>+=/?-]|\.{2}' , Operator ),
71
74
include ('token-list' ),
72
75
(r'[\[\]\(\)\{\}\|:;,.#]' , Punctuation ),
@@ -254,7 +257,8 @@ class SwiftLexer(RegexLexer):
254
257
(_name , Name .Namespace ),
255
258
(r',\s*' , Punctuation ),
256
259
(r' ' , Text .Whitespace ),
257
- (r'(\()(\d+\.\d+)(\))' , bygroups (Punctuation , Number .Float , Punctuation )),
260
+ (r'(\()(\d+\.\d+)(\))' , bygroups (
261
+ Punctuation , Number .Float , Punctuation )),
258
262
default ('#pop' ),
259
263
],
260
264
@@ -266,12 +270,14 @@ class SwiftLexer(RegexLexer):
266
270
Punctuation ,
267
271
Whitespace )),
268
272
include ('class-isa' ),
269
- (r'(\*?)([a-zA-Z_][a-zA-Z0-9_?]*)' , bygroups (Punctuation , Name .Class )),
273
+ (r'(\*?)([a-zA-Z_][a-zA-Z0-9_?]*)' , bygroups (
274
+ Punctuation , Name .Class )),
270
275
(r'\.' , Punctuation ),
271
276
(r'<' , Punctuation , 'generic-type' ),
272
277
(r':' , Punctuation , 'name-list' ),
273
278
(r'\s' , Whitespace ),
274
- (r'\s?(,)(\s*)([A-Z0-9_][a-zA-Z0-9_]*)' , bygroups (Punctuation , Whitespace , Name .Constant )),
279
+ (r'\s?(,)(\s*)([A-Z0-9_][a-zA-Z0-9_]*)' , bygroups (
280
+ Punctuation , Whitespace , Name .Constant )),
275
281
(r'<' , Punctuation , 'generic-type' ),
276
282
(r'where' , Keyword .Reserved ),
277
283
default ("#pop" ),
0 commit comments