ThirdParty/Pygments/pygments/lexers/jvm.py

changeset 4172
4f20dba37ab6
parent 3145
a9de05d4a22f
child 4697
c2e9bf425554
equal deleted inserted replaced
4170:8bc578136279 4172:4f20dba37ab6
3 pygments.lexers.jvm 3 pygments.lexers.jvm
4 ~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~
5 5
6 Pygments lexers for JVM languages. 6 Pygments lexers for JVM languages.
7 7
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 from __future__ import unicode_literals
13
14 import re 12 import re
15 13
16 from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ 14 from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
17 this 15 this, combined, default, words
18 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
19 Number, Punctuation 17 Number, Punctuation
20 from pygments.util import get_choice_opt 18 from pygments.util import shebang_matches
21 from pygments import unistring as uni 19 from pygments import unistring as uni
22 20
23
24 __all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer', 21 __all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer',
25 'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'KotlinLexer', 22 'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'ClojureScriptLexer',
26 'XtendLexer', 'AspectJLexer', 'CeylonLexer'] 23 'KotlinLexer', 'XtendLexer', 'AspectJLexer', 'CeylonLexer',
24 'PigLexer', 'GoloLexer', 'JasminLexer']
27 25
28 26
29 class JavaLexer(RegexLexer): 27 class JavaLexer(RegexLexer):
30 """ 28 """
31 For `Java <http://www.sun.com/java/>`_ source code. 29 For `Java <http://www.sun.com/java/>`_ source code.
34 name = 'Java' 32 name = 'Java'
35 aliases = ['java'] 33 aliases = ['java']
36 filenames = ['*.java'] 34 filenames = ['*.java']
37 mimetypes = ['text/x-java'] 35 mimetypes = ['text/x-java']
38 36
39 flags = re.MULTILINE | re.DOTALL 37 flags = re.MULTILINE | re.DOTALL | re.UNICODE
40 38
41 tokens = { 39 tokens = {
42 'root': [ 40 'root': [
43 # method names
44 (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]<>]*\s+)+?)' # return arguments
45 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
46 r'(\s*)(\()', # signature start
47 bygroups(using(this), Name.Function, Text, Operator)),
48 (r'[^\S\n]+', Text), 41 (r'[^\S\n]+', Text),
49 (r'//.*?\n', Comment.Single), 42 (r'//.*?\n', Comment.Single),
50 (r'/\*.*?\*/', Comment.Multiline), 43 (r'/\*.*?\*/', Comment.Multiline),
51 (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator), 44 # keywords: go before method names to avoid lexing "throw new XYZ"
45 # as a method signature
52 (r'(assert|break|case|catch|continue|default|do|else|finally|for|' 46 (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
53 r'if|goto|instanceof|new|return|switch|this|throw|try|while)\b', 47 r'if|goto|instanceof|new|return|switch|this|throw|try|while)\b',
54 Keyword), 48 Keyword),
49 # method names
50 (r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)' # return arguments
51 r'((?:[^\W\d]|\$)[\w$]*)' # method name
52 r'(\s*)(\()', # signature start
53 bygroups(using(this), Name.Function, Text, Operator)),
54 (r'@[^\W\d][\w.]*', Name.Decorator),
55 (r'(abstract|const|enum|extends|final|implements|native|private|' 55 (r'(abstract|const|enum|extends|final|implements|native|private|'
56 r'protected|public|static|strictfp|super|synchronized|throws|' 56 r'protected|public|static|strictfp|super|synchronized|throws|'
57 r'transient|volatile)\b', Keyword.Declaration), 57 r'transient|volatile)\b', Keyword.Declaration),
58 (r'(boolean|byte|char|double|float|int|long|short|void)\b', 58 (r'(boolean|byte|char|double|float|int|long|short|void)\b',
59 Keyword.Type), 59 Keyword.Type),
60 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)), 60 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
61 (r'(true|false|null)\b', Keyword.Constant), 61 (r'(true|false|null)\b', Keyword.Constant),
62 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text), 'class'), 62 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text), 'class'),
63 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 63 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
64 (r'"(\\\\|\\"|[^"])*"', String), 64 (r'"(\\\\|\\"|[^"])*"', String),
65 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), 65 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
66 (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)), 66 (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Operator, Name.Attribute)),
67 (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label), 67 (r'^\s*([^\W\d]|\$)[\w$]*:', Name.Label),
68 (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), 68 (r'([^\W\d]|\$)[\w$]*', Name),
69 (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), 69 (r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
70 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 70 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
71 (r'0x[0-9a-fA-F]+', Number.Hex), 71 (r'0x[0-9a-fA-F]+', Number.Hex),
72 (r'[0-9]+L?', Number.Integer), 72 (r'[0-9]+(_+[0-9]+)*L?', Number.Integer),
73 (r'\n', Text) 73 (r'\n', Text)
74 ], 74 ],
75 'class': [ 75 'class': [
76 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 76 (r'([^\W\d]|\$)[\w$]*', Name.Class, '#pop')
77 ], 77 ],
78 'import': [ 78 'import': [
79 (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop') 79 (r'[\w.]+\*?', Name.Namespace, '#pop')
80 ], 80 ],
81 } 81 }
82 82
83 83
84 class AspectJLexer(JavaLexer): 84 class AspectJLexer(JavaLexer):
85 """ 85 """
86 For `AspectJ <http://www.eclipse.org/aspectj/>`_ source code. 86 For `AspectJ <http://www.eclipse.org/aspectj/>`_ source code.
87 87
88 *New in Pygments 1.6.* 88 .. versionadded:: 1.6
89 """ 89 """
90 90
91 name = 'AspectJ' 91 name = 'AspectJ'
92 aliases = ['aspectj'] 92 aliases = ['aspectj']
93 filenames = ['*.aj'] 93 filenames = ['*.aj']
94 mimetypes = ['text/x-aspectj'] 94 mimetypes = ['text/x-aspectj']
95 95
96 aj_keywords = [ 96 aj_keywords = set((
97 'aspect', 'pointcut', 'privileged', 'call', 'execution', 97 'aspect', 'pointcut', 'privileged', 'call', 'execution',
98 'initialization', 'preinitialization', 'handler', 'get', 'set', 98 'initialization', 'preinitialization', 'handler', 'get', 'set',
99 'staticinitialization', 'target', 'args', 'within', 'withincode', 99 'staticinitialization', 'target', 'args', 'within', 'withincode',
100 'cflow', 'cflowbelow', 'annotation', 'before', 'after', 'around', 100 'cflow', 'cflowbelow', 'annotation', 'before', 'after', 'around',
101 'proceed', 'throwing', 'returning', 'adviceexecution', 'declare', 101 'proceed', 'throwing', 'returning', 'adviceexecution', 'declare',
102 'parents', 'warning', 'error', 'soft', 'precedence', 'thisJoinPoint', 102 'parents', 'warning', 'error', 'soft', 'precedence', 'thisJoinPoint',
103 'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart', 103 'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart',
104 'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow', 104 'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow',
105 'pertypewithin', 'lock', 'unlock', 'thisAspectInstance' 105 'pertypewithin', 'lock', 'unlock', 'thisAspectInstance'
106 ] 106 ))
107 aj_inter_type = ['parents:', 'warning:', 'error:', 'soft:', 'precedence:'] 107 aj_inter_type = set(('parents:', 'warning:', 'error:', 'soft:', 'precedence:'))
108 aj_inter_type_annotation = ['@type', '@method', '@constructor', '@field'] 108 aj_inter_type_annotation = set(('@type', '@method', '@constructor', '@field'))
109 109
110 def get_tokens_unprocessed(self, text): 110 def get_tokens_unprocessed(self, text):
111 for index, token, value in JavaLexer.get_tokens_unprocessed(self, text): 111 for index, token, value in JavaLexer.get_tokens_unprocessed(self, text):
112 if token is Name and value in self.aj_keywords: 112 if token is Name and value in self.aj_keywords:
113 yield index, Keyword, value 113 yield index, Keyword, value
131 mimetypes = ['text/x-scala'] 131 mimetypes = ['text/x-scala']
132 132
133 flags = re.MULTILINE | re.DOTALL 133 flags = re.MULTILINE | re.DOTALL
134 134
135 # don't use raw unicode strings! 135 # don't use raw unicode strings!
136 op = ('[-~\\^\\*!%&\\\\<>\\|+=:/?@\u00a6-\u00a7\u00a9\u00ac\u00ae\u00b0-\u00b1' 136 op = (u'[-~\\^\\*!%&\\\\<>\\|+=:/?@\u00a6-\u00a7\u00a9\u00ac\u00ae\u00b0-\u00b1'
137 '\u00b6\u00d7\u00f7\u03f6\u0482\u0606-\u0608\u060e-\u060f\u06e9' 137 u'\u00b6\u00d7\u00f7\u03f6\u0482\u0606-\u0608\u060e-\u060f\u06e9'
138 '\u06fd-\u06fe\u07f6\u09fa\u0b70\u0bf3-\u0bf8\u0bfa\u0c7f\u0cf1-\u0cf2' 138 u'\u06fd-\u06fe\u07f6\u09fa\u0b70\u0bf3-\u0bf8\u0bfa\u0c7f\u0cf1-\u0cf2'
139 '\u0d79\u0f01-\u0f03\u0f13-\u0f17\u0f1a-\u0f1f\u0f34\u0f36\u0f38' 139 u'\u0d79\u0f01-\u0f03\u0f13-\u0f17\u0f1a-\u0f1f\u0f34\u0f36\u0f38'
140 '\u0fbe-\u0fc5\u0fc7-\u0fcf\u109e-\u109f\u1360\u1390-\u1399\u1940' 140 u'\u0fbe-\u0fc5\u0fc7-\u0fcf\u109e-\u109f\u1360\u1390-\u1399\u1940'
141 '\u19e0-\u19ff\u1b61-\u1b6a\u1b74-\u1b7c\u2044\u2052\u207a-\u207c' 141 u'\u19e0-\u19ff\u1b61-\u1b6a\u1b74-\u1b7c\u2044\u2052\u207a-\u207c'
142 '\u208a-\u208c\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114\u2116-\u2118' 142 u'\u208a-\u208c\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114\u2116-\u2118'
143 '\u211e-\u2123\u2125\u2127\u2129\u212e\u213a-\u213b\u2140-\u2144' 143 u'\u211e-\u2123\u2125\u2127\u2129\u212e\u213a-\u213b\u2140-\u2144'
144 '\u214a-\u214d\u214f\u2190-\u2328\u232b-\u244a\u249c-\u24e9\u2500-\u2767' 144 u'\u214a-\u214d\u214f\u2190-\u2328\u232b-\u244a\u249c-\u24e9\u2500-\u2767'
145 '\u2794-\u27c4\u27c7-\u27e5\u27f0-\u2982\u2999-\u29d7\u29dc-\u29fb' 145 u'\u2794-\u27c4\u27c7-\u27e5\u27f0-\u2982\u2999-\u29d7\u29dc-\u29fb'
146 '\u29fe-\u2b54\u2ce5-\u2cea\u2e80-\u2ffb\u3004\u3012-\u3013\u3020' 146 u'\u29fe-\u2b54\u2ce5-\u2cea\u2e80-\u2ffb\u3004\u3012-\u3013\u3020'
147 '\u3036-\u3037\u303e-\u303f\u3190-\u3191\u3196-\u319f\u31c0-\u31e3' 147 u'\u3036-\u3037\u303e-\u303f\u3190-\u3191\u3196-\u319f\u31c0-\u31e3'
148 '\u3200-\u321e\u322a-\u3250\u3260-\u327f\u328a-\u32b0\u32c0-\u33ff' 148 u'\u3200-\u321e\u322a-\u3250\u3260-\u327f\u328a-\u32b0\u32c0-\u33ff'
149 '\u4dc0-\u4dff\ua490-\ua4c6\ua828-\ua82b\ufb29\ufdfd\ufe62\ufe64-\ufe66' 149 u'\u4dc0-\u4dff\ua490-\ua4c6\ua828-\ua82b\ufb29\ufdfd\ufe62\ufe64-\ufe66'
150 '\uff0b\uff1c-\uff1e\uff5c\uff5e\uffe2\uffe4\uffe8-\uffee\ufffc-\ufffd]+') 150 u'\uff0b\uff1c-\uff1e\uff5c\uff5e\uffe2\uffe4\uffe8-\uffee\ufffc-\ufffd]+')
151 151
152 letter = ('[a-zA-Z\\$_\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6' 152 letter = (u'[a-zA-Z\\$_\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6'
153 '\u00f8-\u02af\u0370-\u0373\u0376-\u0377\u037b-\u037d\u0386' 153 u'\u00f8-\u02af\u0370-\u0373\u0376-\u0377\u037b-\u037d\u0386'
154 '\u0388-\u03f5\u03f7-\u0481\u048a-\u0556\u0561-\u0587\u05d0-\u05f2' 154 u'\u0388-\u03f5\u03f7-\u0481\u048a-\u0556\u0561-\u0587\u05d0-\u05f2'
155 '\u0621-\u063f\u0641-\u064a\u066e-\u066f\u0671-\u06d3\u06d5' 155 u'\u0621-\u063f\u0641-\u064a\u066e-\u066f\u0671-\u06d3\u06d5'
156 '\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5' 156 u'\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5'
157 '\u07b1\u07ca-\u07ea\u0904-\u0939\u093d\u0950\u0958-\u0961' 157 u'\u07b1\u07ca-\u07ea\u0904-\u0939\u093d\u0950\u0958-\u0961'
158 '\u0972-\u097f\u0985-\u09b9\u09bd\u09ce\u09dc-\u09e1\u09f0-\u09f1' 158 u'\u0972-\u097f\u0985-\u09b9\u09bd\u09ce\u09dc-\u09e1\u09f0-\u09f1'
159 '\u0a05-\u0a39\u0a59-\u0a5e\u0a72-\u0a74\u0a85-\u0ab9\u0abd' 159 u'\u0a05-\u0a39\u0a59-\u0a5e\u0a72-\u0a74\u0a85-\u0ab9\u0abd'
160 '\u0ad0-\u0ae1\u0b05-\u0b39\u0b3d\u0b5c-\u0b61\u0b71\u0b83-\u0bb9' 160 u'\u0ad0-\u0ae1\u0b05-\u0b39\u0b3d\u0b5c-\u0b61\u0b71\u0b83-\u0bb9'
161 '\u0bd0\u0c05-\u0c3d\u0c58-\u0c61\u0c85-\u0cb9\u0cbd\u0cde-\u0ce1' 161 u'\u0bd0\u0c05-\u0c3d\u0c58-\u0c61\u0c85-\u0cb9\u0cbd\u0cde-\u0ce1'
162 '\u0d05-\u0d3d\u0d60-\u0d61\u0d7a-\u0d7f\u0d85-\u0dc6\u0e01-\u0e30' 162 u'\u0d05-\u0d3d\u0d60-\u0d61\u0d7a-\u0d7f\u0d85-\u0dc6\u0e01-\u0e30'
163 '\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0eb0\u0eb2-\u0eb3\u0ebd-\u0ec4' 163 u'\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0eb0\u0eb2-\u0eb3\u0ebd-\u0ec4'
164 '\u0edc-\u0f00\u0f40-\u0f6c\u0f88-\u0f8b\u1000-\u102a\u103f' 164 u'\u0edc-\u0f00\u0f40-\u0f6c\u0f88-\u0f8b\u1000-\u102a\u103f'
165 '\u1050-\u1055\u105a-\u105d\u1061\u1065-\u1066\u106e-\u1070' 165 u'\u1050-\u1055\u105a-\u105d\u1061\u1065-\u1066\u106e-\u1070'
166 '\u1075-\u1081\u108e\u10a0-\u10fa\u1100-\u135a\u1380-\u138f' 166 u'\u1075-\u1081\u108e\u10a0-\u10fa\u1100-\u135a\u1380-\u138f'
167 '\u13a0-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u16ee-\u1711' 167 u'\u13a0-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u16ee-\u1711'
168 '\u1720-\u1731\u1740-\u1751\u1760-\u1770\u1780-\u17b3\u17dc' 168 u'\u1720-\u1731\u1740-\u1751\u1760-\u1770\u1780-\u17b3\u17dc'
169 '\u1820-\u1842\u1844-\u18a8\u18aa-\u191c\u1950-\u19a9\u19c1-\u19c7' 169 u'\u1820-\u1842\u1844-\u18a8\u18aa-\u191c\u1950-\u19a9\u19c1-\u19c7'
170 '\u1a00-\u1a16\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae-\u1baf' 170 u'\u1a00-\u1a16\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae-\u1baf'
171 '\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c77\u1d00-\u1d2b\u1d62-\u1d77' 171 u'\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c77\u1d00-\u1d2b\u1d62-\u1d77'
172 '\u1d79-\u1d9a\u1e00-\u1fbc\u1fbe\u1fc2-\u1fcc\u1fd0-\u1fdb' 172 u'\u1d79-\u1d9a\u1e00-\u1fbc\u1fbe\u1fc2-\u1fcc\u1fd0-\u1fdb'
173 '\u1fe0-\u1fec\u1ff2-\u1ffc\u2071\u207f\u2102\u2107\u210a-\u2113' 173 u'\u1fe0-\u1fec\u1ff2-\u1ffc\u2071\u207f\u2102\u2107\u210a-\u2113'
174 '\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139' 174 u'\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139'
175 '\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c7c' 175 u'\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c7c'
176 '\u2c80-\u2ce4\u2d00-\u2d65\u2d80-\u2dde\u3006-\u3007\u3021-\u3029' 176 u'\u2c80-\u2ce4\u2d00-\u2d65\u2d80-\u2dde\u3006-\u3007\u3021-\u3029'
177 '\u3038-\u303a\u303c\u3041-\u3096\u309f\u30a1-\u30fa\u30ff-\u318e' 177 u'\u3038-\u303a\u303c\u3041-\u3096\u309f\u30a1-\u30fa\u30ff-\u318e'
178 '\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\ua014\ua016-\ua48c' 178 u'\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\ua014\ua016-\ua48c'
179 '\ua500-\ua60b\ua610-\ua61f\ua62a-\ua66e\ua680-\ua697\ua722-\ua76f' 179 u'\ua500-\ua60b\ua610-\ua61f\ua62a-\ua66e\ua680-\ua697\ua722-\ua76f'
180 '\ua771-\ua787\ua78b-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822' 180 u'\ua771-\ua787\ua78b-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822'
181 '\ua840-\ua873\ua882-\ua8b3\ua90a-\ua925\ua930-\ua946\uaa00-\uaa28' 181 u'\ua840-\ua873\ua882-\ua8b3\ua90a-\ua925\ua930-\ua946\uaa00-\uaa28'
182 '\uaa40-\uaa42\uaa44-\uaa4b\uac00-\ud7a3\uf900-\ufb1d\ufb1f-\ufb28' 182 u'\uaa40-\uaa42\uaa44-\uaa4b\uac00-\ud7a3\uf900-\ufb1d\ufb1f-\ufb28'
183 '\ufb2a-\ufd3d\ufd50-\ufdfb\ufe70-\ufefc\uff21-\uff3a\uff41-\uff5a' 183 u'\ufb2a-\ufd3d\ufd50-\ufdfb\ufe70-\ufefc\uff21-\uff3a\uff41-\uff5a'
184 '\uff66-\uff6f\uff71-\uff9d\uffa0-\uffdc]') 184 u'\uff66-\uff6f\uff71-\uff9d\uffa0-\uffdc]')
185 185
186 upper = ('[A-Z\\$_\u00c0-\u00d6\u00d8-\u00de\u0100\u0102\u0104\u0106\u0108' 186 upper = (u'[A-Z\\$_\u00c0-\u00d6\u00d8-\u00de\u0100\u0102\u0104\u0106\u0108'
187 '\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c' 187 u'\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c'
188 '\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130' 188 u'\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130'
189 '\u0132\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145' 189 u'\u0132\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145'
190 '\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a' 190 u'\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a'
191 '\u015c\u015e\u0160\u0162\u0164\u0166\u0168\u016a\u016c\u016e' 191 u'\u015c\u015e\u0160\u0162\u0164\u0166\u0168\u016a\u016c\u016e'
192 '\u0170\u0172\u0174\u0176\u0178-\u0179\u017b\u017d\u0181-\u0182' 192 u'\u0170\u0172\u0174\u0176\u0178-\u0179\u017b\u017d\u0181-\u0182'
193 '\u0184\u0186-\u0187\u0189-\u018b\u018e-\u0191\u0193-\u0194' 193 u'\u0184\u0186-\u0187\u0189-\u018b\u018e-\u0191\u0193-\u0194'
194 '\u0196-\u0198\u019c-\u019d\u019f-\u01a0\u01a2\u01a4\u01a6-\u01a7' 194 u'\u0196-\u0198\u019c-\u019d\u019f-\u01a0\u01a2\u01a4\u01a6-\u01a7'
195 '\u01a9\u01ac\u01ae-\u01af\u01b1-\u01b3\u01b5\u01b7-\u01b8\u01bc' 195 u'\u01a9\u01ac\u01ae-\u01af\u01b1-\u01b3\u01b5\u01b7-\u01b8\u01bc'
196 '\u01c4\u01c7\u01ca\u01cd\u01cf\u01d1\u01d3\u01d5\u01d7\u01d9' 196 u'\u01c4\u01c7\u01ca\u01cd\u01cf\u01d1\u01d3\u01d5\u01d7\u01d9'
197 '\u01db\u01de\u01e0\u01e2\u01e4\u01e6\u01e8\u01ea\u01ec\u01ee' 197 u'\u01db\u01de\u01e0\u01e2\u01e4\u01e6\u01e8\u01ea\u01ec\u01ee'
198 '\u01f1\u01f4\u01f6-\u01f8\u01fa\u01fc\u01fe\u0200\u0202\u0204' 198 u'\u01f1\u01f4\u01f6-\u01f8\u01fa\u01fc\u01fe\u0200\u0202\u0204'
199 '\u0206\u0208\u020a\u020c\u020e\u0210\u0212\u0214\u0216\u0218' 199 u'\u0206\u0208\u020a\u020c\u020e\u0210\u0212\u0214\u0216\u0218'
200 '\u021a\u021c\u021e\u0220\u0222\u0224\u0226\u0228\u022a\u022c' 200 u'\u021a\u021c\u021e\u0220\u0222\u0224\u0226\u0228\u022a\u022c'
201 '\u022e\u0230\u0232\u023a-\u023b\u023d-\u023e\u0241\u0243-\u0246' 201 u'\u022e\u0230\u0232\u023a-\u023b\u023d-\u023e\u0241\u0243-\u0246'
202 '\u0248\u024a\u024c\u024e\u0370\u0372\u0376\u0386\u0388-\u038f' 202 u'\u0248\u024a\u024c\u024e\u0370\u0372\u0376\u0386\u0388-\u038f'
203 '\u0391-\u03ab\u03cf\u03d2-\u03d4\u03d8\u03da\u03dc\u03de\u03e0' 203 u'\u0391-\u03ab\u03cf\u03d2-\u03d4\u03d8\u03da\u03dc\u03de\u03e0'
204 '\u03e2\u03e4\u03e6\u03e8\u03ea\u03ec\u03ee\u03f4\u03f7' 204 u'\u03e2\u03e4\u03e6\u03e8\u03ea\u03ec\u03ee\u03f4\u03f7'
205 '\u03f9-\u03fa\u03fd-\u042f\u0460\u0462\u0464\u0466\u0468\u046a' 205 u'\u03f9-\u03fa\u03fd-\u042f\u0460\u0462\u0464\u0466\u0468\u046a'
206 '\u046c\u046e\u0470\u0472\u0474\u0476\u0478\u047a\u047c\u047e' 206 u'\u046c\u046e\u0470\u0472\u0474\u0476\u0478\u047a\u047c\u047e'
207 '\u0480\u048a\u048c\u048e\u0490\u0492\u0494\u0496\u0498\u049a' 207 u'\u0480\u048a\u048c\u048e\u0490\u0492\u0494\u0496\u0498\u049a'
208 '\u049c\u049e\u04a0\u04a2\u04a4\u04a6\u04a8\u04aa\u04ac\u04ae' 208 u'\u049c\u049e\u04a0\u04a2\u04a4\u04a6\u04a8\u04aa\u04ac\u04ae'
209 '\u04b0\u04b2\u04b4\u04b6\u04b8\u04ba\u04bc\u04be\u04c0-\u04c1' 209 u'\u04b0\u04b2\u04b4\u04b6\u04b8\u04ba\u04bc\u04be\u04c0-\u04c1'
210 '\u04c3\u04c5\u04c7\u04c9\u04cb\u04cd\u04d0\u04d2\u04d4\u04d6' 210 u'\u04c3\u04c5\u04c7\u04c9\u04cb\u04cd\u04d0\u04d2\u04d4\u04d6'
211 '\u04d8\u04da\u04dc\u04de\u04e0\u04e2\u04e4\u04e6\u04e8\u04ea' 211 u'\u04d8\u04da\u04dc\u04de\u04e0\u04e2\u04e4\u04e6\u04e8\u04ea'
212 '\u04ec\u04ee\u04f0\u04f2\u04f4\u04f6\u04f8\u04fa\u04fc\u04fe' 212 u'\u04ec\u04ee\u04f0\u04f2\u04f4\u04f6\u04f8\u04fa\u04fc\u04fe'
213 '\u0500\u0502\u0504\u0506\u0508\u050a\u050c\u050e\u0510\u0512' 213 u'\u0500\u0502\u0504\u0506\u0508\u050a\u050c\u050e\u0510\u0512'
214 '\u0514\u0516\u0518\u051a\u051c\u051e\u0520\u0522\u0531-\u0556' 214 u'\u0514\u0516\u0518\u051a\u051c\u051e\u0520\u0522\u0531-\u0556'
215 '\u10a0-\u10c5\u1e00\u1e02\u1e04\u1e06\u1e08\u1e0a\u1e0c\u1e0e' 215 u'\u10a0-\u10c5\u1e00\u1e02\u1e04\u1e06\u1e08\u1e0a\u1e0c\u1e0e'
216 '\u1e10\u1e12\u1e14\u1e16\u1e18\u1e1a\u1e1c\u1e1e\u1e20\u1e22' 216 u'\u1e10\u1e12\u1e14\u1e16\u1e18\u1e1a\u1e1c\u1e1e\u1e20\u1e22'
217 '\u1e24\u1e26\u1e28\u1e2a\u1e2c\u1e2e\u1e30\u1e32\u1e34\u1e36' 217 u'\u1e24\u1e26\u1e28\u1e2a\u1e2c\u1e2e\u1e30\u1e32\u1e34\u1e36'
218 '\u1e38\u1e3a\u1e3c\u1e3e\u1e40\u1e42\u1e44\u1e46\u1e48\u1e4a' 218 u'\u1e38\u1e3a\u1e3c\u1e3e\u1e40\u1e42\u1e44\u1e46\u1e48\u1e4a'
219 '\u1e4c\u1e4e\u1e50\u1e52\u1e54\u1e56\u1e58\u1e5a\u1e5c\u1e5e' 219 u'\u1e4c\u1e4e\u1e50\u1e52\u1e54\u1e56\u1e58\u1e5a\u1e5c\u1e5e'
220 '\u1e60\u1e62\u1e64\u1e66\u1e68\u1e6a\u1e6c\u1e6e\u1e70\u1e72' 220 u'\u1e60\u1e62\u1e64\u1e66\u1e68\u1e6a\u1e6c\u1e6e\u1e70\u1e72'
221 '\u1e74\u1e76\u1e78\u1e7a\u1e7c\u1e7e\u1e80\u1e82\u1e84\u1e86' 221 u'\u1e74\u1e76\u1e78\u1e7a\u1e7c\u1e7e\u1e80\u1e82\u1e84\u1e86'
222 '\u1e88\u1e8a\u1e8c\u1e8e\u1e90\u1e92\u1e94\u1e9e\u1ea0\u1ea2' 222 u'\u1e88\u1e8a\u1e8c\u1e8e\u1e90\u1e92\u1e94\u1e9e\u1ea0\u1ea2'
223 '\u1ea4\u1ea6\u1ea8\u1eaa\u1eac\u1eae\u1eb0\u1eb2\u1eb4\u1eb6' 223 u'\u1ea4\u1ea6\u1ea8\u1eaa\u1eac\u1eae\u1eb0\u1eb2\u1eb4\u1eb6'
224 '\u1eb8\u1eba\u1ebc\u1ebe\u1ec0\u1ec2\u1ec4\u1ec6\u1ec8\u1eca' 224 u'\u1eb8\u1eba\u1ebc\u1ebe\u1ec0\u1ec2\u1ec4\u1ec6\u1ec8\u1eca'
225 '\u1ecc\u1ece\u1ed0\u1ed2\u1ed4\u1ed6\u1ed8\u1eda\u1edc\u1ede' 225 u'\u1ecc\u1ece\u1ed0\u1ed2\u1ed4\u1ed6\u1ed8\u1eda\u1edc\u1ede'
226 '\u1ee0\u1ee2\u1ee4\u1ee6\u1ee8\u1eea\u1eec\u1eee\u1ef0\u1ef2' 226 u'\u1ee0\u1ee2\u1ee4\u1ee6\u1ee8\u1eea\u1eec\u1eee\u1ef0\u1ef2'
227 '\u1ef4\u1ef6\u1ef8\u1efa\u1efc\u1efe\u1f08-\u1f0f\u1f18-\u1f1d' 227 u'\u1ef4\u1ef6\u1ef8\u1efa\u1efc\u1efe\u1f08-\u1f0f\u1f18-\u1f1d'
228 '\u1f28-\u1f2f\u1f38-\u1f3f\u1f48-\u1f4d\u1f59-\u1f5f' 228 u'\u1f28-\u1f2f\u1f38-\u1f3f\u1f48-\u1f4d\u1f59-\u1f5f'
229 '\u1f68-\u1f6f\u1fb8-\u1fbb\u1fc8-\u1fcb\u1fd8-\u1fdb' 229 u'\u1f68-\u1f6f\u1fb8-\u1fbb\u1fc8-\u1fcb\u1fd8-\u1fdb'
230 '\u1fe8-\u1fec\u1ff8-\u1ffb\u2102\u2107\u210b-\u210d\u2110-\u2112' 230 u'\u1fe8-\u1fec\u1ff8-\u1ffb\u2102\u2107\u210b-\u210d\u2110-\u2112'
231 '\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u2130-\u2133' 231 u'\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u2130-\u2133'
232 '\u213e-\u213f\u2145\u2183\u2c00-\u2c2e\u2c60\u2c62-\u2c64\u2c67' 232 u'\u213e-\u213f\u2145\u2183\u2c00-\u2c2e\u2c60\u2c62-\u2c64\u2c67'
233 '\u2c69\u2c6b\u2c6d-\u2c6f\u2c72\u2c75\u2c80\u2c82\u2c84\u2c86' 233 u'\u2c69\u2c6b\u2c6d-\u2c6f\u2c72\u2c75\u2c80\u2c82\u2c84\u2c86'
234 '\u2c88\u2c8a\u2c8c\u2c8e\u2c90\u2c92\u2c94\u2c96\u2c98\u2c9a' 234 u'\u2c88\u2c8a\u2c8c\u2c8e\u2c90\u2c92\u2c94\u2c96\u2c98\u2c9a'
235 '\u2c9c\u2c9e\u2ca0\u2ca2\u2ca4\u2ca6\u2ca8\u2caa\u2cac\u2cae' 235 u'\u2c9c\u2c9e\u2ca0\u2ca2\u2ca4\u2ca6\u2ca8\u2caa\u2cac\u2cae'
236 '\u2cb0\u2cb2\u2cb4\u2cb6\u2cb8\u2cba\u2cbc\u2cbe\u2cc0\u2cc2' 236 u'\u2cb0\u2cb2\u2cb4\u2cb6\u2cb8\u2cba\u2cbc\u2cbe\u2cc0\u2cc2'
237 '\u2cc4\u2cc6\u2cc8\u2cca\u2ccc\u2cce\u2cd0\u2cd2\u2cd4\u2cd6' 237 u'\u2cc4\u2cc6\u2cc8\u2cca\u2ccc\u2cce\u2cd0\u2cd2\u2cd4\u2cd6'
238 '\u2cd8\u2cda\u2cdc\u2cde\u2ce0\u2ce2\ua640\ua642\ua644\ua646' 238 u'\u2cd8\u2cda\u2cdc\u2cde\u2ce0\u2ce2\ua640\ua642\ua644\ua646'
239 '\ua648\ua64a\ua64c\ua64e\ua650\ua652\ua654\ua656\ua658\ua65a' 239 u'\ua648\ua64a\ua64c\ua64e\ua650\ua652\ua654\ua656\ua658\ua65a'
240 '\ua65c\ua65e\ua662\ua664\ua666\ua668\ua66a\ua66c\ua680\ua682' 240 u'\ua65c\ua65e\ua662\ua664\ua666\ua668\ua66a\ua66c\ua680\ua682'
241 '\ua684\ua686\ua688\ua68a\ua68c\ua68e\ua690\ua692\ua694\ua696' 241 u'\ua684\ua686\ua688\ua68a\ua68c\ua68e\ua690\ua692\ua694\ua696'
242 '\ua722\ua724\ua726\ua728\ua72a\ua72c\ua72e\ua732\ua734\ua736' 242 u'\ua722\ua724\ua726\ua728\ua72a\ua72c\ua72e\ua732\ua734\ua736'
243 '\ua738\ua73a\ua73c\ua73e\ua740\ua742\ua744\ua746\ua748\ua74a' 243 u'\ua738\ua73a\ua73c\ua73e\ua740\ua742\ua744\ua746\ua748\ua74a'
244 '\ua74c\ua74e\ua750\ua752\ua754\ua756\ua758\ua75a\ua75c\ua75e' 244 u'\ua74c\ua74e\ua750\ua752\ua754\ua756\ua758\ua75a\ua75c\ua75e'
245 '\ua760\ua762\ua764\ua766\ua768\ua76a\ua76c\ua76e\ua779\ua77b' 245 u'\ua760\ua762\ua764\ua766\ua768\ua76a\ua76c\ua76e\ua779\ua77b'
246 '\ua77d-\ua77e\ua780\ua782\ua784\ua786\ua78b\uff21-\uff3a]') 246 u'\ua77d-\ua77e\ua780\ua782\ua784\ua786\ua78b\uff21-\uff3a]')
247 247
248 idrest = r'%s(?:%s|[0-9])*(?:(?<=_)%s)?' % (letter, letter, op) 248 idrest = u'%s(?:%s|[0-9])*(?:(?<=_)%s)?' % (letter, letter, op)
249 letter_letter_digit = u'%s(?:%s|\d)*' % (letter, letter)
249 250
250 tokens = { 251 tokens = {
251 'root': [ 252 'root': [
252 # method names 253 # method names
253 (r'(class|trait|object)(\s+)', bygroups(Keyword, Text), 'class'), 254 (r'(class|trait|object)(\s+)', bygroups(Keyword, Text), 'class'),
254 (r"'%s" % idrest, Text.Symbol), 255 (u"'%s" % idrest, Text.Symbol),
255 (r'[^\S\n]+', Text), 256 (r'[^\S\n]+', Text),
256 (r'//.*?\n', Comment.Single), 257 (r'//.*?\n', Comment.Single),
257 (r'/\*', Comment.Multiline, 'comment'), 258 (r'/\*', Comment.Multiline, 'comment'),
258 (r'@%s' % idrest, Name.Decorator), 259 (u'@%s' % idrest, Name.Decorator),
259 (r'(abstract|ca(?:se|tch)|d(?:ef|o)|e(?:lse|xtends)|' 260 (u'(abstract|ca(?:se|tch)|d(?:ef|o)|e(?:lse|xtends)|'
260 r'f(?:inal(?:ly)?|or(?:Some)?)|i(?:f|mplicit)|' 261 u'f(?:inal(?:ly)?|or(?:Some)?)|i(?:f|mplicit)|'
261 r'lazy|match|new|override|pr(?:ivate|otected)' 262 u'lazy|match|new|override|pr(?:ivate|otected)'
262 r'|re(?:quires|turn)|s(?:ealed|uper)|' 263 u'|re(?:quires|turn)|s(?:ealed|uper)|'
263 r't(?:h(?:is|row)|ry)|va[lr]|w(?:hile|ith)|yield)\b|' 264 u't(?:h(?:is|row)|ry)|va[lr]|w(?:hile|ith)|yield)\\b|'
264 '(<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\\b|(?=\\s)|$)', Keyword), 265 u'(<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\\b|(?=\\s)|$)', Keyword),
265 (r':(?!%s)' % op, Keyword, 'type'), 266 (u':(?!%s)' % op, Keyword, 'type'),
266 (r'%s%s\b' % (upper, idrest), Name.Class), 267 (u'%s%s\\b' % (upper, idrest), Name.Class),
267 (r'(true|false|null)\b', Keyword.Constant), 268 (r'(true|false|null)\b', Keyword.Constant),
268 (r'(import|package)(\s+)', bygroups(Keyword, Text), 'import'), 269 (r'(import|package)(\s+)', bygroups(Keyword, Text), 'import'),
269 (r'(type)(\s+)', bygroups(Keyword, Text), 'type'), 270 (r'(type)(\s+)', bygroups(Keyword, Text), 'type'),
270 (r'""".*?"""(?!")', String), 271 (r'""".*?"""(?!")', String),
271 (r'"(\\\\|\\"|[^"])*"', String), 272 (r'"(\\\\|\\"|[^"])*"', String),
272 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), 273 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
273 # (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator, 274 (r'[fs]"""', String, 'interptriplestring'), # interpolated strings
274 # Name.Attribute)), 275 (r'[fs]"', String, 'interpstring'), # interpolated strings
276 (r'raw"(\\\\|\\"|[^"])*"', String), # raw strings
277 # (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator,
278 # Name.Attribute)),
275 (idrest, Name), 279 (idrest, Name),
276 (r'`[^`]+`', Name), 280 (r'`[^`]+`', Name),
277 (r'\[', Operator, 'typeparam'), 281 (r'\[', Operator, 'typeparam'),
278 (r'[\(\)\{\};,.#]', Operator), 282 (r'[(){};,.#]', Operator),
279 (op, Operator), 283 (op, Operator),
280 (r'([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?', 284 (r'([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?',
281 Number.Float), 285 Number.Float),
282 (r'0x[0-9a-fA-F]+', Number.Hex), 286 (r'0x[0-9a-fA-F]+', Number.Hex),
283 (r'[0-9]+L?', Number.Integer), 287 (r'[0-9]+L?', Number.Integer),
284 (r'\n', Text) 288 (r'\n', Text)
285 ], 289 ],
286 'class': [ 290 'class': [
287 (r'(%s|%s|`[^`]+`)(\s*)(\[)' % (idrest, op), 291 (u'(%s|%s|`[^`]+`)(\\s*)(\\[)' % (idrest, op),
288 bygroups(Name.Class, Text, Operator), 'typeparam'), 292 bygroups(Name.Class, Text, Operator), 'typeparam'),
289 (r'\s+', Text), 293 (r'\s+', Text),
290 (r'{', Operator, '#pop'), 294 (r'\{', Operator, '#pop'),
291 (r'\(', Operator, '#pop'), 295 (r'\(', Operator, '#pop'),
292 (r'//.*?\n', Comment.Single, '#pop'), 296 (r'//.*?\n', Comment.Single, '#pop'),
293 (r'%s|%s|`[^`]+`' % (idrest, op), Name.Class, '#pop'), 297 (u'%s|%s|`[^`]+`' % (idrest, op), Name.Class, '#pop'),
294 ], 298 ],
295 'type': [ 299 'type': [
296 (r'\s+', Text), 300 (r'\s+', Text),
297 ('<[%:]|>:|[#_\u21D2]|forSome|type', Keyword), 301 (r'<[%:]|>:|[#_]|forSome|type', Keyword),
298 (r'([,\);}]|=>|=)(\s*)', bygroups(Operator, Text), '#pop'), 302 (u'([,);}]|=>|=|\u21d2)(\\s*)', bygroups(Operator, Text), '#pop'),
299 (r'[\(\{]', Operator, '#push'), 303 (r'[({]', Operator, '#push'),
300 (r'((?:%s|%s|`[^`]+`)(?:\.(?:%s|%s|`[^`]+`))*)(\s*)(\[)' % 304 (u'((?:%s|%s|`[^`]+`)(?:\\.(?:%s|%s|`[^`]+`))*)(\\s*)(\\[)' %
301 (idrest, op, idrest, op), 305 (idrest, op, idrest, op),
302 bygroups(Keyword.Type, Text, Operator), ('#pop', 'typeparam')), 306 bygroups(Keyword.Type, Text, Operator), ('#pop', 'typeparam')),
303 (r'((?:%s|%s|`[^`]+`)(?:\.(?:%s|%s|`[^`]+`))*)(\s*)$' % 307 (u'((?:%s|%s|`[^`]+`)(?:\\.(?:%s|%s|`[^`]+`))*)(\\s*)$' %
304 (idrest, op, idrest, op), 308 (idrest, op, idrest, op),
305 bygroups(Keyword.Type, Text), '#pop'), 309 bygroups(Keyword.Type, Text), '#pop'),
306 (r'//.*?\n', Comment.Single, '#pop'), 310 (r'//.*?\n', Comment.Single, '#pop'),
307 (r'\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type) 311 (u'\\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
308 ], 312 ],
309 'typeparam': [ 313 'typeparam': [
310 (r'[\s,]+', Text), 314 (r'[\s,]+', Text),
311 ('<[%:]|=>|>:|[#_\u21D2]|forSome|type', Keyword), 315 (u'<[%:]|=>|>:|[#_\u21D2]|forSome|type', Keyword),
312 (r'([\]\)\}])', Operator, '#pop'), 316 (r'([\])}])', Operator, '#pop'),
313 (r'[\(\[\{]', Operator, '#push'), 317 (r'[(\[{]', Operator, '#push'),
314 (r'\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type) 318 (u'\\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
315 ], 319 ],
316 'comment': [ 320 'comment': [
317 (r'[^/\*]+', Comment.Multiline), 321 (r'[^/*]+', Comment.Multiline),
318 (r'/\*', Comment.Multiline, '#push'), 322 (r'/\*', Comment.Multiline, '#push'),
319 (r'\*/', Comment.Multiline, '#pop'), 323 (r'\*/', Comment.Multiline, '#pop'),
320 (r'[*/]', Comment.Multiline) 324 (r'[*/]', Comment.Multiline)
321 ], 325 ],
322 'import': [ 326 'import': [
323 (r'(%s|\.)+' % idrest, Name.Namespace, '#pop') 327 (u'(%s|\\.)+' % idrest, Name.Namespace, '#pop')
328 ],
329 'interpstringcommon': [
330 (r'[^"$\\]+', String),
331 (r'\$\$', String),
332 (r'\$' + letter_letter_digit, String.Interpol),
333 (r'\$\{', String.Interpol, 'interpbrace'),
334 (r'\\.', String),
335 ],
336 'interptriplestring': [
337 (r'"""(?!")', String, '#pop'),
338 (r'"', String),
339 include('interpstringcommon'),
340 ],
341 'interpstring': [
342 (r'"', String, '#pop'),
343 include('interpstringcommon'),
344 ],
345 'interpbrace': [
346 (r'\}', String.Interpol, '#pop'),
347 (r'\{', String.Interpol, '#push'),
348 include('root'),
324 ], 349 ],
325 } 350 }
326 351
327 352
328 class GosuLexer(RegexLexer): 353 class GosuLexer(RegexLexer):
329 """ 354 """
330 For Gosu source code. 355 For Gosu source code.
331 356
332 *New in Pygments 1.5.* 357 .. versionadded:: 1.5
333 """ 358 """
334 359
335 name = 'Gosu' 360 name = 'Gosu'
336 aliases = ['gosu'] 361 aliases = ['gosu']
337 filenames = ['*.gs', '*.gsx', '*.gsp', '*.vark'] 362 filenames = ['*.gs', '*.gsx', '*.gsp', '*.vark']
340 flags = re.MULTILINE | re.DOTALL 365 flags = re.MULTILINE | re.DOTALL
341 366
342 tokens = { 367 tokens = {
343 'root': [ 368 'root': [
344 # method names 369 # method names
345 (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # modifiers etc. 370 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # modifiers etc.
346 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name 371 r'([a-zA-Z_]\w*)' # method name
347 r'(\s*)(\()', # signature start 372 r'(\s*)(\()', # signature start
348 bygroups(using(this), Name.Function, Text, Operator)), 373 bygroups(using(this), Name.Function, Text, Operator)),
349 (r'[^\S\n]+', Text), 374 (r'[^\S\n]+', Text),
350 (r'//.*?\n', Comment.Single), 375 (r'//.*?\n', Comment.Single),
351 (r'/\*.*?\*/', Comment.Multiline), 376 (r'/\*.*?\*/', Comment.Multiline),
352 (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator), 377 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
353 (r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|for|' 378 (r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|for|'
354 r'index|while|do|continue|break|return|try|catch|finally|this|' 379 r'index|while|do|continue|break|return|try|catch|finally|this|'
355 r'throw|new|switch|case|default|eval|super|outer|classpath|' 380 r'throw|new|switch|case|default|eval|super|outer|classpath|'
356 r'using)\b', Keyword), 381 r'using)\b', Keyword),
357 (r'(var|delegate|construct|function|private|internal|protected|' 382 (r'(var|delegate|construct|function|private|internal|protected|'
360 (r'(property\s+)(get|set)?', Keyword.Declaration), 385 (r'(property\s+)(get|set)?', Keyword.Declaration),
361 (r'(boolean|byte|char|double|float|int|long|short|void|block)\b', 386 (r'(boolean|byte|char|double|float|int|long|short|void|block)\b',
362 Keyword.Type), 387 Keyword.Type),
363 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)), 388 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
364 (r'(true|false|null|NaN|Infinity)\b', Keyword.Constant), 389 (r'(true|false|null|NaN|Infinity)\b', Keyword.Constant),
365 (r'(class|interface|enhancement|enum)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', 390 (r'(class|interface|enhancement|enum)(\s+)([a-zA-Z_]\w*)',
366 bygroups(Keyword.Declaration, Text, Name.Class)), 391 bygroups(Keyword.Declaration, Text, Name.Class)),
367 (r'(uses)(\s+)([a-zA-Z0-9_.]+\*?)', 392 (r'(uses)(\s+)([\w.]+\*?)',
368 bygroups(Keyword.Namespace, Text, Name.Namespace)), 393 bygroups(Keyword.Namespace, Text, Name.Namespace)),
369 (r'"', String, 'string'), 394 (r'"', String, 'string'),
370 (r'(\??[\.#])([a-zA-Z_][a-zA-Z0-9_]*)', 395 (r'(\??[.#])([a-zA-Z_]\w*)',
371 bygroups(Operator, Name.Attribute)), 396 bygroups(Operator, Name.Attribute)),
372 (r'(:)([a-zA-Z_][a-zA-Z0-9_]*)', 397 (r'(:)([a-zA-Z_]\w*)',
373 bygroups(Operator, Name.Attribute)), 398 bygroups(Operator, Name.Attribute)),
374 (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), 399 (r'[a-zA-Z_$]\w*', Name),
375 (r'and|or|not|[\\~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), 400 (r'and|or|not|[\\~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
376 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 401 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
377 (r'[0-9]+', Number.Integer), 402 (r'[0-9]+', Number.Integer),
378 (r'\n', Text) 403 (r'\n', Text)
379 ], 404 ],
380 'templateText': [ 405 'templateText': [
381 (r'(\\<)|(\\\$)', String), 406 (r'(\\<)|(\\\$)', String),
382 (r'(<%@\s+)(extends|params)', 407 (r'(<%@\s+)(extends|params)',
383 bygroups(Operator, Name.Decorator), 'stringTemplate'), 408 bygroups(Operator, Name.Decorator), 'stringTemplate'),
384 (r'<%!--.*?--%>', Comment.Multiline), 409 (r'<%!--.*?--%>', Comment.Multiline),
385 (r'(<%)|(<%=)', Operator, 'stringTemplate'), 410 (r'(<%)|(<%=)', Operator, 'stringTemplate'),
386 (r'\$\{', Operator, 'stringTemplateShorthand'), 411 (r'\$\{', Operator, 'stringTemplateShorthand'),
387 (r'.', String) 412 (r'.', String)
388 ], 413 ],
389 'string': [ 414 'string': [
390 (r'"', String, '#pop'), 415 (r'"', String, '#pop'),
391 include('templateText') 416 include('templateText')
392 ], 417 ],
393 'stringTemplate': [ 418 'stringTemplate': [
394 (r'"', String, 'string'), 419 (r'"', String, 'string'),
395 (r'%>', Operator, '#pop'), 420 (r'%>', Operator, '#pop'),
396 include('root') 421 include('root')
397 ], 422 ],
398 'stringTemplateShorthand': [ 423 'stringTemplateShorthand': [
399 (r'"', String, 'string'), 424 (r'"', String, 'string'),
400 (r'\{', Operator, 'stringTemplateShorthand'), 425 (r'\{', Operator, 'stringTemplateShorthand'),
401 (r'\}', Operator, '#pop'), 426 (r'\}', Operator, '#pop'),
402 include('root') 427 include('root')
403 ], 428 ],
404 } 429 }
405 430
406 431
407 class GosuTemplateLexer(Lexer): 432 class GosuTemplateLexer(Lexer):
408 """ 433 """
409 For Gosu templates. 434 For Gosu templates.
410 435
411 *New in Pygments 1.5.* 436 .. versionadded:: 1.5
412 """ 437 """
413 438
414 name = 'Gosu Template' 439 name = 'Gosu Template'
415 aliases = ['gst'] 440 aliases = ['gst']
416 filenames = ['*.gst'] 441 filenames = ['*.gst']
417 mimetypes = ['text/x-gosu-template'] 442 mimetypes = ['text/x-gosu-template']
418 lexer = GosuLexer()
419 443
420 def get_tokens_unprocessed(self, text): 444 def get_tokens_unprocessed(self, text):
445 lexer = GosuLexer()
421 stack = ['templateText'] 446 stack = ['templateText']
422 for item in self.lexer.get_tokens_unprocessed(text, stack): 447 for item in lexer.get_tokens_unprocessed(text, stack):
423 yield item 448 yield item
424 449
425 450
426 class GroovyLexer(RegexLexer): 451 class GroovyLexer(RegexLexer):
427 """ 452 """
428 For `Groovy <http://groovy.codehaus.org/>`_ source code. 453 For `Groovy <http://groovy.codehaus.org/>`_ source code.
429 454
430 *New in Pygments 1.5.* 455 .. versionadded:: 1.5
431 """ 456 """
432 457
433 name = 'Groovy' 458 name = 'Groovy'
434 aliases = ['groovy'] 459 aliases = ['groovy']
435 filenames = ['*.groovy'] 460 filenames = ['*.groovy']
437 462
438 flags = re.MULTILINE | re.DOTALL 463 flags = re.MULTILINE | re.DOTALL
439 464
440 tokens = { 465 tokens = {
441 'root': [ 466 'root': [
467 # Groovy allows a file to start with a shebang
468 (r'#!(.*?)$', Comment.Preproc, 'base'),
469 default('base'),
470 ],
471 'base': [
442 # method names 472 # method names
443 (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments 473 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
444 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name 474 r'([a-zA-Z_]\w*)' # method name
445 r'(\s*)(\()', # signature start 475 r'(\s*)(\()', # signature start
446 bygroups(using(this), Name.Function, Text, Operator)), 476 bygroups(using(this), Name.Function, Text, Operator)),
447 (r'[^\S\n]+', Text), 477 (r'[^\S\n]+', Text),
448 (r'//.*?\n', Comment.Single), 478 (r'//.*?\n', Comment.Single),
449 (r'/\*.*?\*/', Comment.Multiline), 479 (r'/\*.*?\*/', Comment.Multiline),
450 (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator), 480 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
451 (r'(assert|break|case|catch|continue|default|do|else|finally|for|' 481 (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
452 r'if|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b', 482 r'if|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b',
453 Keyword), 483 Keyword),
454 (r'(abstract|const|enum|extends|final|implements|native|private|' 484 (r'(abstract|const|enum|extends|final|implements|native|private|'
455 r'protected|public|static|strictfp|super|synchronized|throws|' 485 r'protected|public|static|strictfp|super|synchronized|throws|'
459 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)), 489 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
460 (r'(true|false|null)\b', Keyword.Constant), 490 (r'(true|false|null)\b', Keyword.Constant),
461 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text), 491 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text),
462 'class'), 492 'class'),
463 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 493 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
494 (r'""".*?"""', String.Double),
495 (r"'''.*?'''", String.Single),
464 (r'"(\\\\|\\"|[^"])*"', String.Double), 496 (r'"(\\\\|\\"|[^"])*"', String.Double),
465 (r"'(\\\\|\\'|[^'])*'", String.Single), 497 (r"'(\\\\|\\'|[^'])*'", String.Single),
466 (r'\$/((?!/\$).)*/\$', String), 498 (r'\$/((?!/\$).)*/\$', String),
467 (r'/(\\\\|\\"|[^/])*/', String), 499 (r'/(\\\\|\\"|[^/])*/', String),
468 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), 500 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
469 (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)), 501 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)),
470 (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label), 502 (r'[a-zA-Z_]\w*:', Name.Label),
471 (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), 503 (r'[a-zA-Z_$]\w*', Name),
472 (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), 504 (r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
473 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 505 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
474 (r'0x[0-9a-fA-F]+', Number.Hex), 506 (r'0x[0-9a-fA-F]+', Number.Hex),
475 (r'[0-9]+L?', Number.Integer), 507 (r'[0-9]+L?', Number.Integer),
476 (r'\n', Text) 508 (r'\n', Text)
477 ], 509 ],
478 'class': [ 510 'class': [
479 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 511 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
480 ], 512 ],
481 'import': [ 513 'import': [
482 (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop') 514 (r'[\w.]+\*?', Name.Namespace, '#pop')
483 ], 515 ],
484 } 516 }
517
518 def analyse_text(text):
519 return shebang_matches(text, r'groovy')
485 520
486 521
487 class IokeLexer(RegexLexer): 522 class IokeLexer(RegexLexer):
488 """ 523 """
489 For `Ioke <http://ioke.org/>`_ (a strongly typed, dynamic, 524 For `Ioke <http://ioke.org/>`_ (a strongly typed, dynamic,
490 prototype based programming language) source. 525 prototype based programming language) source.
491 526
492 *New in Pygments 1.4.* 527 .. versionadded:: 1.4
493 """ 528 """
494 name = 'Ioke' 529 name = 'Ioke'
495 filenames = ['*.ik'] 530 filenames = ['*.ik']
496 aliases = ['ioke', 'ik'] 531 aliases = ['ioke', 'ik']
497 mimetypes = ['text/x-iokesrc'] 532 mimetypes = ['text/x-iokesrc']
498 tokens = { 533 tokens = {
499 'interpolatableText': [ 534 'interpolatableText': [
500 (r'(\\b|\\e|\\t|\\n|\\f|\\r|\\"|\\\\|\\#|\\\Z|\\u[0-9a-fA-F]{1,4}' 535 (r'(\\b|\\e|\\t|\\n|\\f|\\r|\\"|\\\\|\\#|\\\Z|\\u[0-9a-fA-F]{1,4}'
501 r'|\\[0-3]?[0-7]?[0-7])', String.Escape), 536 r'|\\[0-3]?[0-7]?[0-7])', String.Escape),
502 (r'#{', Punctuation, 'textInterpolationRoot') 537 (r'#\{', Punctuation, 'textInterpolationRoot')
503 ], 538 ],
504 539
505 'text': [ 540 'text': [
506 (r'(?<!\\)"', String, '#pop'), 541 (r'(?<!\\)"', String, '#pop'),
507 include('interpolatableText'), 542 include('interpolatableText'),
508 (r'[^"]', String) 543 (r'[^"]', String)
509 ], 544 ],
510 545
511 'documentation': [ 546 'documentation': [
512 (r'(?<!\\)"', String.Doc, '#pop'), 547 (r'(?<!\\)"', String.Doc, '#pop'),
513 include('interpolatableText'), 548 include('interpolatableText'),
514 (r'[^"]', String.Doc) 549 (r'[^"]', String.Doc)
515 ], 550 ],
516 551
517 'textInterpolationRoot': [ 552 'textInterpolationRoot': [
518 (r'}', Punctuation, '#pop'), 553 (r'\}', Punctuation, '#pop'),
519 include('root') 554 include('root')
520 ], 555 ],
521 556
522 'slashRegexp': [ 557 'slashRegexp': [
523 (r'(?<!\\)/[oxpniums]*', String.Regex, '#pop'), 558 (r'(?<!\\)/[oxpniums]*', String.Regex, '#pop'),
524 include('interpolatableText'), 559 include('interpolatableText'),
525 (r'\\/', String.Regex), 560 (r'\\/', String.Regex),
526 (r'[^/]', String.Regex) 561 (r'[^/]', String.Regex)
527 ], 562 ],
528 563
529 'squareRegexp': [ 564 'squareRegexp': [
530 (r'(?<!\\)][oxpniums]*', String.Regex, '#pop'), 565 (r'(?<!\\)][oxpniums]*', String.Regex, '#pop'),
531 include('interpolatableText'), 566 include('interpolatableText'),
532 (r'\\]', String.Regex), 567 (r'\\]', String.Regex),
533 (r'[^\]]', String.Regex) 568 (r'[^\]]', String.Regex)
534 ], 569 ],
535 570
536 'squareText': [ 571 'squareText': [
537 (r'(?<!\\)]', String, '#pop'), 572 (r'(?<!\\)]', String, '#pop'),
538 include('interpolatableText'), 573 include('interpolatableText'),
539 (r'[^\]]', String) 574 (r'[^\]]', String)
540 ], 575 ],
541 576
542 'root': [ 577 'root': [
543 (r'\n', Text), 578 (r'\n', Text),
544 (r'\s+', Text), 579 (r'\s+', Text),
545 580
546 # Comments 581 # Comments
547 (r';(.*?)\n', Comment), 582 (r';(.*?)\n', Comment),
548 (r'\A#!(.*?)\n', Comment), 583 (r'\A#!(.*?)\n', Comment),
549 584
550 #Regexps 585 # Regexps
551 (r'#/', String.Regex, 'slashRegexp'), 586 (r'#/', String.Regex, 'slashRegexp'),
552 (r'#r\[', String.Regex, 'squareRegexp'), 587 (r'#r\[', String.Regex, 'squareRegexp'),
553 588
554 #Symbols 589 # Symbols
555 (r':[a-zA-Z0-9_!:?]+', String.Symbol), 590 (r':[\w!:?]+', String.Symbol),
556 (r'[a-zA-Z0-9_!:?]+:(?![a-zA-Z0-9_!?])', String.Other), 591 (r'[\w!:?]+:(?![\w!?])', String.Other),
557 (r':"(\\\\|\\"|[^"])*"', String.Symbol), 592 (r':"(\\\\|\\"|[^"])*"', String.Symbol),
558 593
559 #Documentation 594 # Documentation
560 (r'((?<=fn\()|(?<=fnx\()|(?<=method\()|(?<=macro\()|(?<=lecro\()' 595 (r'((?<=fn\()|(?<=fnx\()|(?<=method\()|(?<=macro\()|(?<=lecro\()'
561 r'|(?<=syntax\()|(?<=dmacro\()|(?<=dlecro\()|(?<=dlecrox\()' 596 r'|(?<=syntax\()|(?<=dmacro\()|(?<=dlecro\()|(?<=dlecrox\()'
562 r'|(?<=dsyntax\())\s*"', String.Doc, 'documentation'), 597 r'|(?<=dsyntax\())\s*"', String.Doc, 'documentation'),
563 598
564 #Text 599 # Text
565 (r'"', String, 'text'), 600 (r'"', String, 'text'),
566 (r'#\[', String, 'squareText'), 601 (r'#\[', String, 'squareText'),
567 602
568 #Mimic 603 # Mimic
569 (r'[a-zA-Z0-9_][a-zA-Z0-9!?_:]+(?=\s*=.*mimic\s)', Name.Entity), 604 (r'\w[\w!:?]+(?=\s*=.*mimic\s)', Name.Entity),
570 605
571 #Assignment 606 # Assignment
572 (r'[a-zA-Z_][a-zA-Z0-9_!:?]*(?=[\s]*[+*/-]?=[^=].*($|\.))', 607 (r'[a-zA-Z_][\w!:?]*(?=[\s]*[+*/-]?=[^=].*($|\.))',
573 Name.Variable), 608 Name.Variable),
574 609
575 # keywords 610 # keywords
576 (r'(break|cond|continue|do|ensure|for|for:dict|for:set|if|let|' 611 (r'(break|cond|continue|do|ensure|for|for:dict|for:set|if|let|'
577 r'loop|p:for|p:for:dict|p:for:set|return|unless|until|while|' 612 r'loop|p:for|p:for:dict|p:for:set|return|unless|until|while|'
578 r'with)(?![a-zA-Z0-9!:_?])', Keyword.Reserved), 613 r'with)(?![\w!:?])', Keyword.Reserved),
579 614
580 # Origin 615 # Origin
581 (r'(eval|mimic|print|println)(?![a-zA-Z0-9!:_?])', Keyword), 616 (r'(eval|mimic|print|println)(?![\w!:?])', Keyword),
582 617
583 # Base 618 # Base
584 (r'(cell\?|cellNames|cellOwner\?|cellOwner|cells|cell|' 619 (r'(cell\?|cellNames|cellOwner\?|cellOwner|cells|cell|'
585 r'documentation|hash|identity|mimic|removeCell\!|undefineCell\!)' 620 r'documentation|hash|identity|mimic|removeCell\!|undefineCell\!)'
586 r'(?![a-zA-Z0-9!:_?])', Keyword), 621 r'(?![\w!:?])', Keyword),
587 622
588 # Ground 623 # Ground
589 (r'(stackTraceAsText)(?![a-zA-Z0-9!:_?])', Keyword), 624 (r'(stackTraceAsText)(?![\w!:?])', Keyword),
590 625
591 #DefaultBehaviour Literals 626 # DefaultBehaviour Literals
592 (r'(dict|list|message|set)(?![a-zA-Z0-9!:_?])', Keyword.Reserved), 627 (r'(dict|list|message|set)(?![\w!:?])', Keyword.Reserved),
593 628
594 #DefaultBehaviour Case 629 # DefaultBehaviour Case
595 (r'(case|case:and|case:else|case:nand|case:nor|case:not|case:or|' 630 (r'(case|case:and|case:else|case:nand|case:nor|case:not|case:or|'
596 r'case:otherwise|case:xor)(?![a-zA-Z0-9!:_?])', Keyword.Reserved), 631 r'case:otherwise|case:xor)(?![\w!:?])', Keyword.Reserved),
597 632
598 #DefaultBehaviour Reflection 633 # DefaultBehaviour Reflection
599 (r'(asText|become\!|derive|freeze\!|frozen\?|in\?|is\?|kind\?|' 634 (r'(asText|become\!|derive|freeze\!|frozen\?|in\?|is\?|kind\?|'
600 r'mimic\!|mimics|mimics\?|prependMimic\!|removeAllMimics\!|' 635 r'mimic\!|mimics|mimics\?|prependMimic\!|removeAllMimics\!|'
601 r'removeMimic\!|same\?|send|thaw\!|uniqueHexId)' 636 r'removeMimic\!|same\?|send|thaw\!|uniqueHexId)'
602 r'(?![a-zA-Z0-9!:_?])', Keyword), 637 r'(?![\w!:?])', Keyword),
603 638
604 #DefaultBehaviour Aspects 639 # DefaultBehaviour Aspects
605 (r'(after|around|before)(?![a-zA-Z0-9!:_?])', Keyword.Reserved), 640 (r'(after|around|before)(?![\w!:?])', Keyword.Reserved),
606 641
607 # DefaultBehaviour 642 # DefaultBehaviour
608 (r'(kind|cellDescriptionDict|cellSummary|genSym|inspect|notice)' 643 (r'(kind|cellDescriptionDict|cellSummary|genSym|inspect|notice)'
609 r'(?![a-zA-Z0-9!:_?])', Keyword), 644 r'(?![\w!:?])', Keyword),
610 (r'(use|destructuring)', Keyword.Reserved), 645 (r'(use|destructuring)', Keyword.Reserved),
611 646
612 #DefaultBehavior BaseBehavior 647 # DefaultBehavior BaseBehavior
613 (r'(cell\?|cellOwner\?|cellOwner|cellNames|cells|cell|' 648 (r'(cell\?|cellOwner\?|cellOwner|cellNames|cells|cell|'
614 r'documentation|identity|removeCell!|undefineCell)' 649 r'documentation|identity|removeCell!|undefineCell)'
615 r'(?![a-zA-Z0-9!:_?])', Keyword), 650 r'(?![\w!:?])', Keyword),
616 651
617 #DefaultBehavior Internal 652 # DefaultBehavior Internal
618 (r'(internal:compositeRegexp|internal:concatenateText|' 653 (r'(internal:compositeRegexp|internal:concatenateText|'
619 r'internal:createDecimal|internal:createNumber|' 654 r'internal:createDecimal|internal:createNumber|'
620 r'internal:createRegexp|internal:createText)' 655 r'internal:createRegexp|internal:createText)'
621 r'(?![a-zA-Z0-9!:_?])', Keyword.Reserved), 656 r'(?![\w!:?])', Keyword.Reserved),
622 657
623 #DefaultBehaviour Conditions 658 # DefaultBehaviour Conditions
624 (r'(availableRestarts|bind|error\!|findRestart|handle|' 659 (r'(availableRestarts|bind|error\!|findRestart|handle|'
625 r'invokeRestart|rescue|restart|signal\!|warn\!)' 660 r'invokeRestart|rescue|restart|signal\!|warn\!)'
626 r'(?![a-zA-Z0-9!:_?])', Keyword.Reserved), 661 r'(?![\w!:?])', Keyword.Reserved),
627 662
628 # constants 663 # constants
629 (r'(nil|false|true)(?![a-zA-Z0-9!:_?])', Name.Constant), 664 (r'(nil|false|true)(?![\w!:?])', Name.Constant),
630 665
631 # names 666 # names
632 (r'(Arity|Base|Call|Condition|DateTime|Aspects|Pointcut|' 667 (r'(Arity|Base|Call|Condition|DateTime|Aspects|Pointcut|'
633 r'Assignment|BaseBehavior|Boolean|Case|AndCombiner|Else|' 668 r'Assignment|BaseBehavior|Boolean|Case|AndCombiner|Else|'
634 r'NAndCombiner|NOrCombiner|NotCombiner|OrCombiner|XOrCombiner|' 669 r'NAndCombiner|NOrCombiner|NotCombiner|OrCombiner|XOrCombiner|'
636 r'Reflection|DefaultMacro|DefaultMethod|DefaultSyntax|Dict|' 671 r'Reflection|DefaultMacro|DefaultMethod|DefaultSyntax|Dict|'
637 r'FileSystem|Ground|Handler|Hook|IO|IokeGround|Struct|' 672 r'FileSystem|Ground|Handler|Hook|IO|IokeGround|Struct|'
638 r'LexicalBlock|LexicalMacro|List|Message|Method|Mixins|' 673 r'LexicalBlock|LexicalMacro|List|Message|Method|Mixins|'
639 r'NativeMethod|Number|Origin|Pair|Range|Reflector|Regexp Match|' 674 r'NativeMethod|Number|Origin|Pair|Range|Reflector|Regexp Match|'
640 r'Regexp|Rescue|Restart|Runtime|Sequence|Set|Symbol|' 675 r'Regexp|Rescue|Restart|Runtime|Sequence|Set|Symbol|'
641 r'System|Text|Tuple)(?![a-zA-Z0-9!:_?])', Name.Builtin), 676 r'System|Text|Tuple)(?![\w!:?])', Name.Builtin),
642 677
643 # functions 678 # functions
644 (r'(generateMatchMethod|aliasMethod|\u03bb|\u028E|fnx|fn|method|' 679 (u'(generateMatchMethod|aliasMethod|\u03bb|\u028E|fnx|fn|method|'
645 r'dmacro|dlecro|syntax|macro|dlecrox|lecrox|lecro|syntax)' 680 u'dmacro|dlecro|syntax|macro|dlecrox|lecrox|lecro|syntax)'
646 r'(?![a-zA-Z0-9!:_?])', Name.Function), 681 u'(?![\w!:?])', Name.Function),
647 682
648 # Numbers 683 # Numbers
649 (r'-?0[xX][0-9a-fA-F]+', Number.Hex), 684 (r'-?0[xX][0-9a-fA-F]+', Number.Hex),
650 (r'-?(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), 685 (r'-?(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
651 (r'-?\d+', Number.Integer), 686 (r'-?\d+', Number.Integer),
652 687
653 (r'#\(', Punctuation), 688 (r'#\(', Punctuation),
654 689
655 # Operators 690 # Operators
656 (r'(&&>>|\|\|>>|\*\*>>|:::|::|\.\.\.|===|\*\*>|\*\*=|&&>|&&=|' 691 (r'(&&>>|\|\|>>|\*\*>>|:::|::|\.\.\.|===|\*\*>|\*\*=|&&>|&&=|'
657 r'\|\|>|\|\|=|\->>|\+>>|!>>|<>>>|<>>|&>>|%>>|#>>|@>>|/>>|\*>>|' 692 r'\|\|>|\|\|=|\->>|\+>>|!>>|<>>>|<>>|&>>|%>>|#>>|@>>|/>>|\*>>|'
658 r'\?>>|\|>>|\^>>|~>>|\$>>|=>>|<<=|>>=|<=>|<\->|=~|!~|=>|\+\+|' 693 r'\?>>|\|>>|\^>>|~>>|\$>>|=>>|<<=|>>=|<=>|<\->|=~|!~|=>|\+\+|'
659 r'\-\-|<=|>=|==|!=|&&|\.\.|\+=|\-=|\*=|\/=|%=|&=|\^=|\|=|<\-|' 694 r'\-\-|<=|>=|==|!=|&&|\.\.|\+=|\-=|\*=|\/=|%=|&=|\^=|\|=|<\-|'
660 r'\+>|!>|<>|&>|%>|#>|\@>|\/>|\*>|\?>|\|>|\^>|~>|\$>|<\->|\->|' 695 r'\+>|!>|<>|&>|%>|#>|\@>|\/>|\*>|\?>|\|>|\^>|~>|\$>|<\->|\->|'
661 r'<<|>>|\*\*|\?\||\?&|\|\||>|<|\*|\/|%|\+|\-|&|\^|\||=|\$|!|~|' 696 r'<<|>>|\*\*|\?\||\?&|\|\||>|<|\*|\/|%|\+|\-|&|\^|\||=|\$|!|~|'
662 r'\?|#|\u2260|\u2218|\u2208|\u2209)', Operator), 697 u'\\?|#|\u2260|\u2218|\u2208|\u2209)', Operator),
663 (r'(and|nand|or|xor|nor|return|import)(?![a-zA-Z0-9_!?])', 698 (r'(and|nand|or|xor|nor|return|import)(?![\w!?])',
664 Operator), 699 Operator),
665 700
666 # Punctuation 701 # Punctuation
667 (r'(\`\`|\`|\'\'|\'|\.|\,|@@|@|\[|\]|\(|\)|{|})', Punctuation), 702 (r'(\`\`|\`|\'\'|\'|\.|\,|@@|@|\[|\]|\(|\)|\{|\})', Punctuation),
668 703
669 #kinds 704 # kinds
670 (r'[A-Z][a-zA-Z0-9_!:?]*', Name.Class), 705 (r'[A-Z][\w!:?]*', Name.Class),
671 706
672 #default cellnames 707 # default cellnames
673 (r'[a-z_][a-zA-Z0-9_!:?]*', Name) 708 (r'[a-z_][\w!:?]*', Name)
674 ] 709 ]
675 } 710 }
676 711
677 712
678 class ClojureLexer(RegexLexer): 713 class ClojureLexer(RegexLexer):
679 """ 714 """
680 Lexer for `Clojure <http://clojure.org/>`_ source code. 715 Lexer for `Clojure <http://clojure.org/>`_ source code.
681 716
682 *New in Pygments 0.11.* 717 .. versionadded:: 0.11
683 """ 718 """
684 name = 'Clojure' 719 name = 'Clojure'
685 aliases = ['clojure', 'clj'] 720 aliases = ['clojure', 'clj']
686 filenames = ['*.clj'] 721 filenames = ['*.clj']
687 mimetypes = ['text/x-clojure', 'application/x-clojure'] 722 mimetypes = ['text/x-clojure', 'application/x-clojure']
688 723
689 special_forms = [ 724 special_forms = (
690 '.', 'def', 'do', 'fn', 'if', 'let', 'new', 'quote', 'var', 'loop' 725 '.', 'def', 'do', 'fn', 'if', 'let', 'new', 'quote', 'var', 'loop'
691 ] 726 )
692 727
693 # It's safe to consider 'ns' a declaration thing because it defines a new 728 # It's safe to consider 'ns' a declaration thing because it defines a new
694 # namespace. 729 # namespace.
695 declarations = [ 730 declarations = (
696 'def-', 'defn', 'defn-', 'defmacro', 'defmulti', 'defmethod', 731 'def-', 'defn', 'defn-', 'defmacro', 'defmulti', 'defmethod',
697 'defstruct', 'defonce', 'declare', 'definline', 'definterface', 732 'defstruct', 'defonce', 'declare', 'definline', 'definterface',
698 'defprotocol', 'defrecord', 'deftype', 'defproject', 'ns' 733 'defprotocol', 'defrecord', 'deftype', 'defproject', 'ns'
699 ] 734 )
700 735
701 builtins = [ 736 builtins = (
702 '*', '+', '-', '->', '/', '<', '<=', '=', '==', '>', '>=', '..', 737 '*', '+', '-', '->', '/', '<', '<=', '=', '==', '>', '>=', '..',
703 'accessor', 'agent', 'agent-errors', 'aget', 'alength', 'all-ns', 738 'accessor', 'agent', 'agent-errors', 'aget', 'alength', 'all-ns',
704 'alter', 'and', 'append-child', 'apply', 'array-map', 'aset', 739 'alter', 'and', 'append-child', 'apply', 'array-map', 'aset',
705 'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float', 740 'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float',
706 'aset-int', 'aset-long', 'aset-short', 'assert', 'assoc', 'await', 741 'aset-int', 'aset-long', 'aset-short', 'assert', 'assoc', 'await',
745 'sync', 'take', 'take-nth', 'take-while', 'test', 'time', 'to-array', 780 'sync', 'take', 'take-nth', 'take-while', 'test', 'time', 'to-array',
746 'to-array-2d', 'tree-seq', 'true?', 'union', 'up', 'update-proxy', 781 'to-array-2d', 'tree-seq', 'true?', 'union', 'up', 'update-proxy',
747 'val', 'vals', 'var-get', 'var-set', 'var?', 'vector', 'vector-zip', 782 'val', 'vals', 'var-get', 'var-set', 'var?', 'vector', 'vector-zip',
748 'vector?', 'when', 'when-first', 'when-let', 'when-not', 783 'vector?', 'when', 'when-first', 'when-let', 'when-not',
749 'with-local-vars', 'with-meta', 'with-open', 'with-out-str', 784 'with-local-vars', 'with-meta', 'with-open', 'with-out-str',
750 'xml-seq', 'xml-zip', 'zero?', 'zipmap', 'zipper'] 785 'xml-seq', 'xml-zip', 'zero?', 'zipmap', 'zipper')
751 786
752 # valid names for identifiers 787 # valid names for identifiers
753 # well, names can only not consist fully of numbers 788 # well, names can only not consist fully of numbers
754 # but this should be good enough for now 789 # but this should be good enough for now
755 790
756 # TODO / should divide keywords/symbols into namespace/rest 791 # TODO / should divide keywords/symbols into namespace/rest
757 # but that's hard, so just pretend / is part of the name 792 # but that's hard, so just pretend / is part of the name
758 valid_name = r'(?!#)[\w!$%*+<=>?/.#-]+' 793 valid_name = r'(?!#)[\w!$%*+<=>?/.#-]+'
759
760 def _multi_escape(entries):
761 return '(%s)' % ('|'.join(re.escape(entry) + ' ' for entry in entries))
762 794
763 tokens = { 795 tokens = {
764 'root': [ 796 'root': [
765 # the comments - always starting with semicolon 797 # the comments - always starting with semicolon
766 # and going to the end of the line 798 # and going to the end of the line
778 (r'"(\\\\|\\"|[^"])*"', String), 810 (r'"(\\\\|\\"|[^"])*"', String),
779 (r"'" + valid_name, String.Symbol), 811 (r"'" + valid_name, String.Symbol),
780 (r"\\(.|[a-z]+)", String.Char), 812 (r"\\(.|[a-z]+)", String.Char),
781 813
782 # keywords 814 # keywords
783 (r'::?' + valid_name, String.Symbol), 815 (r'::?#?' + valid_name, String.Symbol),
784 816
785 # special operators 817 # special operators
786 (r'~@|[`\'#^~&@]', Operator), 818 (r'~@|[`\'#^~&@]', Operator),
787 819
788 # highlight the special forms 820 # highlight the special forms
789 (_multi_escape(special_forms), Keyword), 821 (words(special_forms, suffix=' '), Keyword),
790 822
791 # Technically, only the special forms are 'keywords'. The problem 823 # Technically, only the special forms are 'keywords'. The problem
792 # is that only treating them as keywords means that things like 824 # is that only treating them as keywords means that things like
793 # 'defn' and 'ns' need to be highlighted as builtins. This is ugly 825 # 'defn' and 'ns' need to be highlighted as builtins. This is ugly
794 # and weird for most styles. So, as a compromise we're going to 826 # and weird for most styles. So, as a compromise we're going to
795 # highlight them as Keyword.Declarations. 827 # highlight them as Keyword.Declarations.
796 (_multi_escape(declarations), Keyword.Declaration), 828 (words(declarations, suffix=' '), Keyword.Declaration),
797 829
798 # highlight the builtins 830 # highlight the builtins
799 (_multi_escape(builtins), Name.Builtin), 831 (words(builtins, suffix=' '), Name.Builtin),
800 832
801 # the remaining functions 833 # the remaining functions
802 (r'(?<=\()' + valid_name, Name.Function), 834 (r'(?<=\()' + valid_name, Name.Function),
803 835
804 # find the remaining variables 836 # find the remaining variables
814 (r'(\(|\))', Punctuation), 846 (r'(\(|\))', Punctuation),
815 ], 847 ],
816 } 848 }
817 849
818 850
851 class ClojureScriptLexer(ClojureLexer):
852 """
853 Lexer for `ClojureScript <http://clojure.org/clojurescript>`_
854 source code.
855
856 .. versionadded:: 2.0
857 """
858 name = 'ClojureScript'
859 aliases = ['clojurescript', 'cljs']
860 filenames = ['*.cljs']
861 mimetypes = ['text/x-clojurescript', 'application/x-clojurescript']
862
863
819 class TeaLangLexer(RegexLexer): 864 class TeaLangLexer(RegexLexer):
820 """ 865 """
821 For `Tea <http://teatrove.org/>`_ source code. Only used within a 866 For `Tea <http://teatrove.org/>`_ source code. Only used within a
822 TeaTemplateLexer. 867 TeaTemplateLexer.
823 868
824 *New in Pygments 1.5.* 869 .. versionadded:: 1.5
825 """ 870 """
826 871
827 flags = re.MULTILINE | re.DOTALL 872 flags = re.MULTILINE | re.DOTALL
828 873
829 tokens = { 874 tokens = {
830 'root': [ 875 'root': [
831 # method names 876 # method names
832 (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments 877 (r'^(\s*(?:[a-zA-Z_][\w\.\[\]]*\s+)+?)' # return arguments
833 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name 878 r'([a-zA-Z_]\w*)' # method name
834 r'(\s*)(\()', # signature start 879 r'(\s*)(\()', # signature start
835 bygroups(using(this), Name.Function, Text, Operator)), 880 bygroups(using(this), Name.Function, Text, Operator)),
836 (r'[^\S\n]+', Text), 881 (r'[^\S\n]+', Text),
837 (r'//.*?\n', Comment.Single), 882 (r'//.*?\n', Comment.Single),
838 (r'/\*.*?\*/', Comment.Multiline), 883 (r'/\*.*?\*/', Comment.Multiline),
839 (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator), 884 (r'@[a-zA-Z_][\w\.]*', Name.Decorator),
840 (r'(and|break|else|foreach|if|in|not|or|reverse)\b', 885 (r'(and|break|else|foreach|if|in|not|or|reverse)\b',
841 Keyword), 886 Keyword),
842 (r'(as|call|define)\b', Keyword.Declaration), 887 (r'(as|call|define)\b', Keyword.Declaration),
843 (r'(true|false|null)\b', Keyword.Constant), 888 (r'(true|false|null)\b', Keyword.Constant),
844 (r'(template)(\s+)', bygroups(Keyword.Declaration, Text), 'template'), 889 (r'(template)(\s+)', bygroups(Keyword.Declaration, Text), 'template'),
845 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 890 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
846 (r'"(\\\\|\\"|[^"])*"', String), 891 (r'"(\\\\|\\"|[^"])*"', String),
847 (r'\'(\\\\|\\\'|[^\'])*\'', String), 892 (r'\'(\\\\|\\\'|[^\'])*\'', String),
848 (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)), 893 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)),
849 (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label), 894 (r'[a-zA-Z_]\w*:', Name.Label),
850 (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), 895 (r'[a-zA-Z_\$]\w*', Name),
851 (r'(isa|[.]{3}|[.]{2}|[=#!<>+-/%&;,.\*\\\(\)\[\]\{\}])', Operator), 896 (r'(isa|[.]{3}|[.]{2}|[=#!<>+-/%&;,.\*\\\(\)\[\]\{\}])', Operator),
852 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 897 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
853 (r'0x[0-9a-fA-F]+', Number.Hex), 898 (r'0x[0-9a-fA-F]+', Number.Hex),
854 (r'[0-9]+L?', Number.Integer), 899 (r'[0-9]+L?', Number.Integer),
855 (r'\n', Text) 900 (r'\n', Text)
856 ], 901 ],
857 'template': [ 902 'template': [
858 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 903 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
859 ], 904 ],
860 'import': [ 905 'import': [
861 (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop') 906 (r'[\w.]+\*?', Name.Namespace, '#pop')
862 ], 907 ],
863 } 908 }
864 909
865 910
866 class CeylonLexer(RegexLexer): 911 class CeylonLexer(RegexLexer):
867 """ 912 """
868 For `Ceylon <http://ceylon-lang.org/>`_ source code. 913 For `Ceylon <http://ceylon-lang.org/>`_ source code.
869 914
870 *New in Pygments 1.6.* 915 .. versionadded:: 1.6
871 """ 916 """
872 917
873 name = 'Ceylon' 918 name = 'Ceylon'
874 aliases = ['ceylon'] 919 aliases = ['ceylon']
875 filenames = ['*.ceylon'] 920 filenames = ['*.ceylon']
881 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' 926 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
882 927
883 tokens = { 928 tokens = {
884 'root': [ 929 'root': [
885 # method names 930 # method names
886 (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments 931 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
887 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name 932 r'([a-zA-Z_]\w*)' # method name
888 r'(\s*)(\()', # signature start 933 r'(\s*)(\()', # signature start
889 bygroups(using(this), Name.Function, Text, Operator)), 934 bygroups(using(this), Name.Function, Text, Operator)),
890 (r'[^\S\n]+', Text), 935 (r'[^\S\n]+', Text),
891 (r'//.*?\n', Comment.Single), 936 (r'//.*?\n', Comment.Single),
892 (r'/\*.*?\*/', Comment.Multiline), 937 (r'/\*', Comment.Multiline, 'comment'),
893 (r'(variable|shared|abstract|doc|by|formal|actual)', 938 (r'(variable|shared|abstract|doc|by|formal|actual|late|native)',
894 Name.Decorator), 939 Name.Decorator),
895 (r'(break|case|catch|continue|default|else|finally|for|in|' 940 (r'(break|case|catch|continue|default|else|finally|for|in|'
896 r'variable|if|return|switch|this|throw|try|while|is|exists|' 941 r'variable|if|return|switch|this|throw|try|while|is|exists|dynamic|'
897 r'nonempty|then|outer)\b', Keyword), 942 r'nonempty|then|outer|assert)\b', Keyword),
898 (r'(abstracts|extends|satisfies|adapts|' 943 (r'(abstracts|extends|satisfies|adapts|'
899 r'super|given|of|out|assign|' 944 r'super|given|of|out|assign|'
900 r'transient|volatile)\b', Keyword.Declaration), 945 r'transient|volatile)\b', Keyword.Declaration),
901 (r'(function|value|void)\b', 946 (r'(function|value|void)\b',
902 Keyword.Type), 947 Keyword.Type),
903 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)), 948 (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
904 (r'(true|false|null)\b', Keyword.Constant), 949 (r'(true|false|null)\b', Keyword.Constant),
905 (r'(class|interface|object)(\s+)', 950 (r'(class|interface|object|alias)(\s+)',
906 bygroups(Keyword.Declaration, Text), 'class'), 951 bygroups(Keyword.Declaration, Text), 'class'),
907 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 952 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
908 (r'"(\\\\|\\"|[^"])*"', String), 953 (r'"(\\\\|\\"|[^"])*"', String),
909 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Quoted), 954 (r"'\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'", String.Char),
910 (r"`\\.`|`[^\\]`|`\\u[0-9a-fA-F]{4}`", String.Char), 955 (r'".*``.*``.*"', String.Interpol),
911 (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', 956 (r'(\.)([a-z_]\w*)',
912 bygroups(Operator, Name.Attribute)), 957 bygroups(Operator, Name.Attribute)),
913 (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label), 958 (r'[a-zA-Z_]\w*:', Name.Label),
914 (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), 959 (r'[a-zA-Z_]\w*', Name),
915 (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), 960 (r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
916 (r'\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float), 961 (r'\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float),
917 (r'\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?', 962 (r'\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?',
918 Number.Float), 963 Number.Float),
919 (r'[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float), 964 (r'[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float),
920 (r'[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?', 965 (r'[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?',
921 Number.Float), 966 Number.Float),
922 (r'0x[0-9a-fA-F]+', Number.Hex), 967 (r'#([0-9a-fA-F]{4})(_[0-9a-fA-F]{4})+', Number.Hex),
968 (r'#[0-9a-fA-F]+', Number.Hex),
969 (r'\$([01]{4})(_[01]{4})+', Number.Bin),
970 (r'\$[01]+', Number.Bin),
923 (r'\d{1,3}(_\d{3})+[kMGTP]?', Number.Integer), 971 (r'\d{1,3}(_\d{3})+[kMGTP]?', Number.Integer),
924 (r'[0-9]+[kMGTP]?', Number.Integer), 972 (r'[0-9]+[kMGTP]?', Number.Integer),
925 (r'\n', Text) 973 (r'\n', Text)
926 ], 974 ],
927 'class': [ 975 'class': [
928 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 976 (r'[A-Za-z_]\w*', Name.Class, '#pop')
929 ], 977 ],
930 'import': [ 978 'import': [
931 (r'[a-zA-Z0-9_.]+\w+ \{([a-zA-Z,]+|\.\.\.)\}', 979 (r'[a-z][\w.]*',
932 Name.Namespace, '#pop') 980 Name.Namespace, '#pop')
933 ], 981 ],
982 'comment': [
983 (r'[^*/]', Comment.Multiline),
984 (r'/\*', Comment.Multiline, '#push'),
985 (r'\*/', Comment.Multiline, '#pop'),
986 (r'[*/]', Comment.Multiline)
987 ],
934 } 988 }
935 989
936 990
937 class KotlinLexer(RegexLexer): 991 class KotlinLexer(RegexLexer):
938 """ 992 """
939 For `Kotlin <http://confluence.jetbrains.net/display/Kotlin/>`_ 993 For `Kotlin <http://kotlin.jetbrains.org/>`_
940 source code. 994 source code.
941 995
942 Additional options accepted: 996 .. versionadded:: 1.5
943
944 `unicodelevel`
945 Determines which Unicode characters this lexer allows for identifiers.
946 The possible values are:
947
948 * ``none`` -- only the ASCII letters and numbers are allowed. This
949 is the fastest selection.
950 * ``basic`` -- all Unicode characters from the specification except
951 category ``Lo`` are allowed.
952 * ``full`` -- all Unicode characters as specified in the C# specs
953 are allowed. Note that this means a considerable slowdown since the
954 ``Lo`` category has more than 40,000 characters in it!
955
956 The default value is ``basic``.
957
958 *New in Pygments 1.5.*
959 """ 997 """
960 998
961 name = 'Kotlin' 999 name = 'Kotlin'
962 aliases = ['kotlin'] 1000 aliases = ['kotlin']
963 filenames = ['*.kt'] 1001 filenames = ['*.kt']
964 mimetypes = ['text/x-kotlin'] # inferred 1002 mimetypes = ['text/x-kotlin']
965 1003
966 flags = re.MULTILINE | re.DOTALL | re.UNICODE 1004 flags = re.MULTILINE | re.DOTALL | re.UNICODE
967 1005
968 # for the range of allowed unicode characters in identifiers, 1006 kt_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
969 # see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf 1007 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf',
970 1008 'Mn', 'Mc') + ']*')
971 levels = { 1009 kt_id = '(' + kt_name + '|`' + kt_name + '`)'
972 'none': '@?[_a-zA-Z][a-zA-Z0-9_]*', 1010
973 'basic': ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + 1011 tokens = {
974 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + 1012 'root': [
975 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), 1013 (r'^\s*\[.*?\]', Name.Attribute),
976 'full': ('@?(?:_|[^' + 1014 (r'[^\S\n]+', Text),
977 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' 1015 (r'\\\n', Text), # line continuation
978 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 1016 (r'//.*?\n', Comment.Single),
979 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), 1017 (r'/[*].*?[*]/', Comment.Multiline),
1018 (r'\n', Text),
1019 (r'::|!!|\?[:.]', Operator),
1020 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),
1021 (r'[{}]', Punctuation),
1022 (r'@"(""|[^"])*"', String),
1023 (r'"(\\\\|\\"|[^"\n])*["\n]', String),
1024 (r"'\\.'|'[^\\]'", String.Char),
1025 (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFL]?|"
1026 r"0[xX][0-9a-fA-F]+[Ll]?", Number),
1027 (r'(class)(\s+)(object)', bygroups(Keyword, Text, Keyword)),
1028 (r'(class|trait|object)(\s+)', bygroups(Keyword, Text), 'class'),
1029 (r'(package|import)(\s+)', bygroups(Keyword, Text), 'package'),
1030 (r'(val|var)(\s+)', bygroups(Keyword, Text), 'property'),
1031 (r'(fun)(\s+)', bygroups(Keyword, Text), 'function'),
1032 (r'(abstract|annotation|as|break|by|catch|class|continue|do|else|'
1033 r'enum|false|final|finally|for|fun|get|if|import|in|inner|'
1034 r'internal|is|null|object|open|out|override|package|private|'
1035 r'protected|public|reified|return|set|super|this|throw|trait|'
1036 r'true|try|type|val|var|vararg|when|where|while|This)\b', Keyword),
1037 (kt_id, Name),
1038 ],
1039 'package': [
1040 (r'\S+', Name.Namespace, '#pop')
1041 ],
1042 'class': [
1043 (kt_id, Name.Class, '#pop')
1044 ],
1045 'property': [
1046 (kt_id, Name.Property, '#pop')
1047 ],
1048 'function': [
1049 (kt_id, Name.Function, '#pop')
1050 ],
980 } 1051 }
981 1052
982 tokens = {}
983 token_variants = True
984
985 for levelname, cs_ident in list(levels.items()):
986 tokens[levelname] = {
987 'root': [
988 # method names
989 (r'^([ \t]*(?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type
990 r'(' + cs_ident + ')' # method name
991 r'(\s*)(\()', # signature start
992 bygroups(using(this), Name.Function, Text, Punctuation)),
993 (r'^\s*\[.*?\]', Name.Attribute),
994 (r'[^\S\n]+', Text),
995 (r'\\\n', Text), # line continuation
996 (r'//.*?\n', Comment.Single),
997 (r'/[*](.|\n)*?[*]/', Comment.Multiline),
998 (r'\n', Text),
999 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),
1000 (r'[{}]', Punctuation),
1001 (r'@"(""|[^"])*"', String),
1002 (r'"(\\\\|\\"|[^"\n])*["\n]', String),
1003 (r"'\\.'|'[^\\]'", String.Char),
1004 (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?"
1005 r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number),
1006 (r'#[ \t]*(if|endif|else|elif|define|undef|'
1007 r'line|error|warning|region|endregion|pragma)\b.*?\n',
1008 Comment.Preproc),
1009 (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Text,
1010 Keyword)),
1011 (r'(abstract|as|break|catch|'
1012 r'fun|continue|default|delegate|'
1013 r'do|else|enum|extern|false|finally|'
1014 r'fixed|for|goto|if|implicit|in|interface|'
1015 r'internal|is|lock|null|'
1016 r'out|override|private|protected|public|readonly|'
1017 r'ref|return|sealed|sizeof|'
1018 r'when|this|throw|true|try|typeof|'
1019 r'unchecked|unsafe|virtual|void|while|'
1020 r'get|set|new|partial|yield|val|var)\b', Keyword),
1021 (r'(global)(::)', bygroups(Keyword, Punctuation)),
1022 (r'(bool|byte|char|decimal|double|dynamic|float|int|long|'
1023 r'short)\b\??', Keyword.Type),
1024 (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'class'),
1025 (r'(package|using)(\s+)', bygroups(Keyword, Text), 'package'),
1026 (cs_ident, Name),
1027 ],
1028 'class': [
1029 (cs_ident, Name.Class, '#pop')
1030 ],
1031 'package': [
1032 (r'(?=\()', Text, '#pop'), # using (resource)
1033 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop')
1034 ]
1035 }
1036
1037 def __init__(self, **options):
1038 level = get_choice_opt(options, 'unicodelevel', list(self.tokens.keys()),
1039 'basic')
1040 if level not in self._all_tokens:
1041 # compile the regexes now
1042 self._tokens = self.__class__.process_tokendef(level)
1043 else:
1044 self._tokens = self._all_tokens[level]
1045
1046 RegexLexer.__init__(self, **options)
1047
1048 1053
1049 class XtendLexer(RegexLexer): 1054 class XtendLexer(RegexLexer):
1050 """ 1055 """
1051 For `Xtend <http://xtend-lang.org/>`_ source code. 1056 For `Xtend <http://xtend-lang.org/>`_ source code.
1052 1057
1053 *New in Pygments 1.6.* 1058 .. versionadded:: 1.6
1054 """ 1059 """
1055 1060
1056 name = 'Xtend' 1061 name = 'Xtend'
1057 aliases = ['xtend'] 1062 aliases = ['xtend']
1058 filenames = ['*.xtend'] 1063 filenames = ['*.xtend']
1061 flags = re.MULTILINE | re.DOTALL 1066 flags = re.MULTILINE | re.DOTALL
1062 1067
1063 tokens = { 1068 tokens = {
1064 'root': [ 1069 'root': [
1065 # method names 1070 # method names
1066 (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments 1071 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
1067 r'([a-zA-Z_$][a-zA-Z0-9_$]*)' # method name 1072 r'([a-zA-Z_$][\w$]*)' # method name
1068 r'(\s*)(\()', # signature start 1073 r'(\s*)(\()', # signature start
1069 bygroups(using(this), Name.Function, Text, Operator)), 1074 bygroups(using(this), Name.Function, Text, Operator)),
1070 (r'[^\S\n]+', Text), 1075 (r'[^\S\n]+', Text),
1071 (r'//.*?\n', Comment.Single), 1076 (r'//.*?\n', Comment.Single),
1072 (r'/\*.*?\*/', Comment.Multiline), 1077 (r'/\*.*?\*/', Comment.Multiline),
1073 (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator), 1078 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
1074 (r'(assert|break|case|catch|continue|default|do|else|finally|for|' 1079 (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
1075 r'if|goto|instanceof|new|return|switch|this|throw|try|while|IF|' 1080 r'if|goto|instanceof|new|return|switch|this|throw|try|while|IF|'
1076 r'ELSE|ELSEIF|ENDIF|FOR|ENDFOR|SEPARATOR|BEFORE|AFTER)\b', 1081 r'ELSE|ELSEIF|ENDIF|FOR|ENDFOR|SEPARATOR|BEFORE|AFTER)\b',
1077 Keyword), 1082 Keyword),
1078 (r'(def|abstract|const|enum|extends|final|implements|native|private|' 1083 (r'(def|abstract|const|enum|extends|final|implements|native|private|'
1084 (r'(true|false|null)\b', Keyword.Constant), 1089 (r'(true|false|null)\b', Keyword.Constant),
1085 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text), 1090 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text),
1086 'class'), 1091 'class'),
1087 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), 1092 (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
1088 (r"(''')", String, 'template'), 1093 (r"(''')", String, 'template'),
1089 (r"(\u00BB)", String, 'template'), 1094 (u'(\u00BB)', String, 'template'),
1090 (r'"(\\\\|\\"|[^"])*"', String), 1095 (r'"(\\\\|\\"|[^"])*"', String),
1091 (r"'(\\\\|\\'|[^'])*'", String), 1096 (r"'(\\\\|\\'|[^'])*'", String),
1092 (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label), 1097 (r'[a-zA-Z_]\w*:', Name.Label),
1093 (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), 1098 (r'[a-zA-Z_$]\w*', Name),
1094 (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), 1099 (r'[~^*!%&\[\](){}<>\|+=:;,./?-]', Operator),
1095 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 1100 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1096 (r'0x[0-9a-fA-F]+', Number.Hex), 1101 (r'0x[0-9a-fA-F]+', Number.Hex),
1097 (r'[0-9]+L?', Number.Integer), 1102 (r'[0-9]+L?', Number.Integer),
1098 (r'\n', Text) 1103 (r'\n', Text)
1099 ], 1104 ],
1100 'class': [ 1105 'class': [
1101 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 1106 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
1102 ], 1107 ],
1103 'import': [ 1108 'import': [
1104 (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop') 1109 (r'[\w.]+\*?', Name.Namespace, '#pop')
1105 ], 1110 ],
1106 'template': [ 1111 'template': [
1107 (r"'''", String, '#pop'), 1112 (r"'''", String, '#pop'),
1108 (r"\u00AB", String, '#pop'), 1113 (u'\u00AB', String, '#pop'),
1109 (r'.', String) 1114 (r'.', String)
1110 ], 1115 ],
1111 } 1116 }
1117
1118
1119 class PigLexer(RegexLexer):
1120 """
1121 For `Pig Latin <https://pig.apache.org/>`_ source code.
1122
1123 .. versionadded:: 2.0
1124 """
1125
1126 name = 'Pig'
1127 aliases = ['pig']
1128 filenames = ['*.pig']
1129 mimetypes = ['text/x-pig']
1130
1131 flags = re.MULTILINE | re.IGNORECASE
1132
1133 tokens = {
1134 'root': [
1135 (r'\s+', Text),
1136 (r'--.*', Comment),
1137 (r'/\*[\w\W]*?\*/', Comment.Multiline),
1138 (r'\\\n', Text),
1139 (r'\\', Text),
1140 (r'\'(?:\\[ntbrf\\\']|\\u[0-9a-f]{4}|[^\'\\\n\r])*\'', String),
1141 include('keywords'),
1142 include('types'),
1143 include('builtins'),
1144 include('punct'),
1145 include('operators'),
1146 (r'[0-9]*\.[0-9]+(e[0-9]+)?[fd]?', Number.Float),
1147 (r'0x[0-9a-f]+', Number.Hex),
1148 (r'[0-9]+L?', Number.Integer),
1149 (r'\n', Text),
1150 (r'([a-z_]\w*)(\s*)(\()',
1151 bygroups(Name.Function, Text, Punctuation)),
1152 (r'[()#:]', Text),
1153 (r'[^(:#\'")\s]+', Text),
1154 (r'\S+\s+', Text) # TODO: make tests pass without \s+
1155 ],
1156 'keywords': [
1157 (r'(assert|and|any|all|arrange|as|asc|bag|by|cache|CASE|cat|cd|cp|'
1158 r'%declare|%default|define|dense|desc|describe|distinct|du|dump|'
1159 r'eval|exex|explain|filter|flatten|foreach|full|generate|group|'
1160 r'help|if|illustrate|import|inner|input|into|is|join|kill|left|'
1161 r'limit|load|ls|map|matches|mkdir|mv|not|null|onschema|or|order|'
1162 r'outer|output|parallel|pig|pwd|quit|register|returns|right|rm|'
1163 r'rmf|rollup|run|sample|set|ship|split|stderr|stdin|stdout|store|'
1164 r'stream|through|union|using|void)\b', Keyword)
1165 ],
1166 'builtins': [
1167 (r'(AVG|BinStorage|cogroup|CONCAT|copyFromLocal|copyToLocal|COUNT|'
1168 r'cross|DIFF|MAX|MIN|PigDump|PigStorage|SIZE|SUM|TextLoader|'
1169 r'TOKENIZE)\b', Name.Builtin)
1170 ],
1171 'types': [
1172 (r'(bytearray|BIGINTEGER|BIGDECIMAL|chararray|datetime|double|float|'
1173 r'int|long|tuple)\b', Keyword.Type)
1174 ],
1175 'punct': [
1176 (r'[;(){}\[\]]', Punctuation),
1177 ],
1178 'operators': [
1179 (r'[#=,./%+\-?]', Operator),
1180 (r'(eq|gt|lt|gte|lte|neq|matches)\b', Operator),
1181 (r'(==|<=|<|>=|>|!=)', Operator),
1182 ],
1183 }
1184
1185
1186 class GoloLexer(RegexLexer):
1187 """
1188 For `Golo <http://golo-lang.org/>`_ source code.
1189
1190 .. versionadded:: 2.0
1191 """
1192
1193 name = 'Golo'
1194 filenames = ['*.golo']
1195 aliases = ['golo']
1196
1197 tokens = {
1198 'root': [
1199 (r'[^\S\n]+', Text),
1200
1201 (r'#.*$', Comment),
1202
1203 (r'(\^|\.\.\.|:|\?:|->|==|!=|=|\+|\*|%|/|<=|<|>=|>|=|\.)',
1204 Operator),
1205 (r'(?<=[^-])(-)(?=[^-])', Operator),
1206
1207 (r'(?<=[^`])(is|isnt|and|or|not|oftype|in|orIfNull)\b', Operator.Word),
1208 (r'[]{}|(),[]', Punctuation),
1209
1210 (r'(module|import)(\s+)',
1211 bygroups(Keyword.Namespace, Text),
1212 'modname'),
1213 (r'\b([a-zA-Z_][\w$.]*)(::)', bygroups(Name.Namespace, Punctuation)),
1214 (r'\b([a-zA-Z_][\w$]*(?:\.[a-zA-Z_][\w$]*)+)\b', Name.Namespace),
1215
1216 (r'(let|var)(\s+)',
1217 bygroups(Keyword.Declaration, Text),
1218 'varname'),
1219 (r'(struct)(\s+)',
1220 bygroups(Keyword.Declaration, Text),
1221 'structname'),
1222 (r'(function)(\s+)',
1223 bygroups(Keyword.Declaration, Text),
1224 'funcname'),
1225
1226 (r'(null|true|false)\b', Keyword.Constant),
1227 (r'(augment|pimp'
1228 r'|if|else|case|match|return'
1229 r'|case|when|then|otherwise'
1230 r'|while|for|foreach'
1231 r'|try|catch|finally|throw'
1232 r'|local'
1233 r'|continue|break)\b', Keyword),
1234
1235 (r'(map|array|list|set|vector|tuple)(\[)',
1236 bygroups(Name.Builtin, Punctuation)),
1237 (r'(print|println|readln|raise|fun'
1238 r'|asInterfaceInstance)\b', Name.Builtin),
1239 (r'(`?[a-zA-Z_][\w$]*)(\()',
1240 bygroups(Name.Function, Punctuation)),
1241
1242 (r'-?[\d_]*\.[\d_]*([eE][+-]?\d[\d_]*)?F?', Number.Float),
1243 (r'0[0-7]+j?', Number.Oct),
1244 (r'0[xX][a-fA-F0-9]+', Number.Hex),
1245 (r'-?\d[\d_]*L', Number.Integer.Long),
1246 (r'-?\d[\d_]*', Number.Integer),
1247
1248 ('`?[a-zA-Z_][\w$]*', Name),
1249 (r'@[a-zA-Z_][\w$.]*', Name.Decorator),
1250
1251 (r'"""', String, combined('stringescape', 'triplestring')),
1252 (r'"', String, combined('stringescape', 'doublestring')),
1253 (r"'", String, combined('stringescape', 'singlestring')),
1254 (r'----((.|\n)*?)----', String.Doc)
1255
1256 ],
1257
1258 'funcname': [
1259 (r'`?[a-zA-Z_][\w$]*', Name.Function, '#pop'),
1260 ],
1261 'modname': [
1262 (r'[a-zA-Z_][\w$.]*\*?', Name.Namespace, '#pop')
1263 ],
1264 'structname': [
1265 (r'`?[\w.]+\*?', Name.Class, '#pop')
1266 ],
1267 'varname': [
1268 (r'`?[a-zA-Z_][\w$]*', Name.Variable, '#pop'),
1269 ],
1270 'string': [
1271 (r'[^\\\'"\n]+', String),
1272 (r'[\'"\\]', String)
1273 ],
1274 'stringescape': [
1275 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|'
1276 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
1277 ],
1278 'triplestring': [
1279 (r'"""', String, '#pop'),
1280 include('string'),
1281 (r'\n', String),
1282 ],
1283 'doublestring': [
1284 (r'"', String.Double, '#pop'),
1285 include('string'),
1286 ],
1287 'singlestring': [
1288 (r"'", String, '#pop'),
1289 include('string'),
1290 ],
1291 'operators': [
1292 (r'[#=,./%+\-?]', Operator),
1293 (r'(eq|gt|lt|gte|lte|neq|matches)\b', Operator),
1294 (r'(==|<=|<|>=|>|!=)', Operator),
1295 ],
1296 }
1297
1298
1299 class JasminLexer(RegexLexer):
1300 """
1301 For `Jasmin <http://jasmin.sourceforge.net/>`_ assembly code.
1302
1303 .. versionadded:: 2.0
1304 """
1305
1306 name = 'Jasmin'
1307 aliases = ['jasmin', 'jasminxt']
1308 filenames = ['*.j']
1309
1310 _whitespace = r' \n\t\r'
1311 _ws = r'(?:[%s]+)' % _whitespace
1312 _separator = r'%s:=' % _whitespace
1313 _break = r'(?=[%s]|$)' % _separator
1314 _name = r'[^%s]+' % _separator
1315 _unqualified_name = r'(?:[^%s.;\[/]+)' % _separator
1316
1317 tokens = {
1318 'default': [
1319 (r'\n', Text, '#pop'),
1320 (r"'", String.Single, ('#pop', 'quote')),
1321 (r'"', String.Double, 'string'),
1322 (r'=', Punctuation),
1323 (r':', Punctuation, 'label'),
1324 (_ws, Text),
1325 (r';.*', Comment.Single),
1326 (r'(\$[-+])?0x-?[\da-fA-F]+%s' % _break, Number.Hex),
1327 (r'(\$[-+]|\+)?-?\d+%s' % _break, Number.Integer),
1328 (r'-?(\d+\.\d*|\.\d+)([eE][-+]?\d+)?[fFdD]?'
1329 r'[\x00-\x08\x0b\x0c\x0e-\x1f]*%s' % _break, Number.Float),
1330 (r'\$%s' % _name, Name.Variable),
1331
1332 # Directives
1333 (r'\.annotation%s' % _break, Keyword.Reserved, 'annotation'),
1334 (r'(\.attribute|\.bytecode|\.debug|\.deprecated|\.enclosing|'
1335 r'\.interface|\.line|\.signature|\.source|\.stack|\.var|abstract|'
1336 r'annotation|bridge|class|default|enum|field|final|fpstrict|'
1337 r'interface|native|private|protected|public|signature|static|'
1338 r'synchronized|synthetic|transient|varargs|volatile)%s' % _break,
1339 Keyword.Reserved),
1340 (r'\.catch%s' % _break, Keyword.Reserved, 'caught-exception'),
1341 (r'(\.class|\.implements|\.inner|\.super|inner|invisible|'
1342 r'invisibleparam|outer|visible|visibleparam)%s' % _break,
1343 Keyword.Reserved, 'class/convert-dots'),
1344 (r'\.field%s' % _break, Keyword.Reserved,
1345 ('descriptor/convert-dots', 'field')),
1346 (r'(\.end|\.limit|use)%s' % _break, Keyword.Reserved,
1347 'no-verification'),
1348 (r'\.method%s' % _break, Keyword.Reserved, 'method'),
1349 (r'\.set%s' % _break, Keyword.Reserved, 'var'),
1350 (r'\.throws%s' % _break, Keyword.Reserved, 'exception'),
1351 (r'(from|offset|to|using)%s' % _break, Keyword.Reserved, 'label'),
1352 (r'is%s' % _break, Keyword.Reserved,
1353 ('descriptor/convert-dots', 'var')),
1354 (r'(locals|stack)%s' % _break, Keyword.Reserved, 'verification'),
1355 (r'method%s' % _break, Keyword.Reserved, 'enclosing-method'),
1356
1357 # Instructions
1358 (words((
1359 'aaload', 'aastore', 'aconst_null', 'aload', 'aload_0', 'aload_1', 'aload_2',
1360 'aload_3', 'aload_w', 'areturn', 'arraylength', 'astore', 'astore_0', 'astore_1',
1361 'astore_2', 'astore_3', 'astore_w', 'athrow', 'baload', 'bastore', 'bipush',
1362 'breakpoint', 'caload', 'castore', 'd2f', 'd2i', 'd2l', 'dadd', 'daload', 'dastore',
1363 'dcmpg', 'dcmpl', 'dconst_0', 'dconst_1', 'ddiv', 'dload', 'dload_0', 'dload_1',
1364 'dload_2', 'dload_3', 'dload_w', 'dmul', 'dneg', 'drem', 'dreturn', 'dstore', 'dstore_0',
1365 'dstore_1', 'dstore_2', 'dstore_3', 'dstore_w', 'dsub', 'dup', 'dup2', 'dup2_x1',
1366 'dup2_x2', 'dup_x1', 'dup_x2', 'f2d', 'f2i', 'f2l', 'fadd', 'faload', 'fastore', 'fcmpg',
1367 'fcmpl', 'fconst_0', 'fconst_1', 'fconst_2', 'fdiv', 'fload', 'fload_0', 'fload_1',
1368 'fload_2', 'fload_3', 'fload_w', 'fmul', 'fneg', 'frem', 'freturn', 'fstore', 'fstore_0',
1369 'fstore_1', 'fstore_2', 'fstore_3', 'fstore_w', 'fsub', 'i2b', 'i2c', 'i2d', 'i2f', 'i2l',
1370 'i2s', 'iadd', 'iaload', 'iand', 'iastore', 'iconst_0', 'iconst_1', 'iconst_2',
1371 'iconst_3', 'iconst_4', 'iconst_5', 'iconst_m1', 'idiv', 'iinc', 'iinc_w', 'iload',
1372 'iload_0', 'iload_1', 'iload_2', 'iload_3', 'iload_w', 'imul', 'ineg', 'int2byte',
1373 'int2char', 'int2short', 'ior', 'irem', 'ireturn', 'ishl', 'ishr', 'istore', 'istore_0',
1374 'istore_1', 'istore_2', 'istore_3', 'istore_w', 'isub', 'iushr', 'ixor', 'l2d', 'l2f',
1375 'l2i', 'ladd', 'laload', 'land', 'lastore', 'lcmp', 'lconst_0', 'lconst_1', 'ldc2_w',
1376 'ldiv', 'lload', 'lload_0', 'lload_1', 'lload_2', 'lload_3', 'lload_w', 'lmul', 'lneg',
1377 'lookupswitch', 'lor', 'lrem', 'lreturn', 'lshl', 'lshr', 'lstore', 'lstore_0',
1378 'lstore_1', 'lstore_2', 'lstore_3', 'lstore_w', 'lsub', 'lushr', 'lxor',
1379 'monitorenter', 'monitorexit', 'nop', 'pop', 'pop2', 'ret', 'ret_w', 'return', 'saload',
1380 'sastore', 'sipush', 'swap'), suffix=_break), Keyword.Reserved),
1381 (r'(anewarray|checkcast|instanceof|ldc|ldc_w|new)%s' % _break,
1382 Keyword.Reserved, 'class/no-dots'),
1383 (r'invoke(dynamic|interface|nonvirtual|special|'
1384 r'static|virtual)%s' % _break, Keyword.Reserved,
1385 'invocation'),
1386 (r'(getfield|putfield)%s' % _break, Keyword.Reserved,
1387 ('descriptor/no-dots', 'field')),
1388 (r'(getstatic|putstatic)%s' % _break, Keyword.Reserved,
1389 ('descriptor/no-dots', 'static')),
1390 (words((
1391 'goto', 'goto_w', 'if_acmpeq', 'if_acmpne', 'if_icmpeq',
1392 'if_icmpge', 'if_icmpgt', 'if_icmple', 'if_icmplt', 'if_icmpne',
1393 'ifeq', 'ifge', 'ifgt', 'ifle', 'iflt', 'ifne', 'ifnonnull',
1394 'ifnull', 'jsr', 'jsr_w'), suffix=_break),
1395 Keyword.Reserved, 'label'),
1396 (r'(multianewarray|newarray)%s' % _break, Keyword.Reserved,
1397 'descriptor/convert-dots'),
1398 (r'tableswitch%s' % _break, Keyword.Reserved, 'table')
1399 ],
1400 'quote': [
1401 (r"'", String.Single, '#pop'),
1402 (r'\\u[\da-fA-F]{4}', String.Escape),
1403 (r"[^'\\]+", String.Single)
1404 ],
1405 'string': [
1406 (r'"', String.Double, '#pop'),
1407 (r'\\([nrtfb"\'\\]|u[\da-fA-F]{4}|[0-3]?[0-7]{1,2})',
1408 String.Escape),
1409 (r'[^"\\]+', String.Double)
1410 ],
1411 'root': [
1412 (r'\n+', Text),
1413 (r"'", String.Single, 'quote'),
1414 include('default'),
1415 (r'(%s)([ \t\r]*)(:)' % _name,
1416 bygroups(Name.Label, Text, Punctuation)),
1417 (_name, String.Other)
1418 ],
1419 'annotation': [
1420 (r'\n', Text, ('#pop', 'annotation-body')),
1421 (r'default%s' % _break, Keyword.Reserved,
1422 ('#pop', 'annotation-default')),
1423 include('default')
1424 ],
1425 'annotation-body': [
1426 (r'\n+', Text),
1427 (r'\.end%s' % _break, Keyword.Reserved, '#pop'),
1428 include('default'),
1429 (_name, String.Other, ('annotation-items', 'descriptor/no-dots'))
1430 ],
1431 'annotation-default': [
1432 (r'\n+', Text),
1433 (r'\.end%s' % _break, Keyword.Reserved, '#pop'),
1434 include('default'),
1435 default(('annotation-items', 'descriptor/no-dots'))
1436 ],
1437 'annotation-items': [
1438 (r"'", String.Single, 'quote'),
1439 include('default'),
1440 (_name, String.Other)
1441 ],
1442 'caught-exception': [
1443 (r'all%s' % _break, Keyword, '#pop'),
1444 include('exception')
1445 ],
1446 'class/convert-dots': [
1447 include('default'),
1448 (r'(L)((?:%s[/.])*)(%s)(;)' % (_unqualified_name, _name),
1449 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1450 '#pop'),
1451 (r'((?:%s[/.])*)(%s)' % (_unqualified_name, _name),
1452 bygroups(Name.Namespace, Name.Class), '#pop')
1453 ],
1454 'class/no-dots': [
1455 include('default'),
1456 (r'\[+', Punctuation, ('#pop', 'descriptor/no-dots')),
1457 (r'(L)((?:%s/)*)(%s)(;)' % (_unqualified_name, _name),
1458 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1459 '#pop'),
1460 (r'((?:%s/)*)(%s)' % (_unqualified_name, _name),
1461 bygroups(Name.Namespace, Name.Class), '#pop')
1462 ],
1463 'descriptor/convert-dots': [
1464 include('default'),
1465 (r'\[+', Punctuation),
1466 (r'(L)((?:%s[/.])*)(%s?)(;)' % (_unqualified_name, _name),
1467 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1468 '#pop'),
1469 (r'[^%s\[)L]+' % _separator, Keyword.Type, '#pop'),
1470 default('#pop')
1471 ],
1472 'descriptor/no-dots': [
1473 include('default'),
1474 (r'\[+', Punctuation),
1475 (r'(L)((?:%s/)*)(%s)(;)' % (_unqualified_name, _name),
1476 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1477 '#pop'),
1478 (r'[^%s\[)L]+' % _separator, Keyword.Type, '#pop'),
1479 default('#pop')
1480 ],
1481 'descriptors/convert-dots': [
1482 (r'\)', Punctuation, '#pop'),
1483 default('descriptor/convert-dots')
1484 ],
1485 'enclosing-method': [
1486 (_ws, Text),
1487 (r'(?=[^%s]*\()' % _separator, Text, ('#pop', 'invocation')),
1488 default(('#pop', 'class/convert-dots'))
1489 ],
1490 'exception': [
1491 include('default'),
1492 (r'((?:%s[/.])*)(%s)' % (_unqualified_name, _name),
1493 bygroups(Name.Namespace, Name.Exception), '#pop')
1494 ],
1495 'field': [
1496 (r'static%s' % _break, Keyword.Reserved, ('#pop', 'static')),
1497 include('default'),
1498 (r'((?:%s[/.](?=[^%s]*[/.]))*)(%s[/.])?(%s)' %
1499 (_unqualified_name, _separator, _unqualified_name, _name),
1500 bygroups(Name.Namespace, Name.Class, Name.Variable.Instance),
1501 '#pop')
1502 ],
1503 'invocation': [
1504 include('default'),
1505 (r'((?:%s[/.](?=[^%s(]*[/.]))*)(%s[/.])?(%s)(\()' %
1506 (_unqualified_name, _separator, _unqualified_name, _name),
1507 bygroups(Name.Namespace, Name.Class, Name.Function, Punctuation),
1508 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots',
1509 'descriptor/convert-dots'))
1510 ],
1511 'label': [
1512 include('default'),
1513 (_name, Name.Label, '#pop')
1514 ],
1515 'method': [
1516 include('default'),
1517 (r'(%s)(\()' % _name, bygroups(Name.Function, Punctuation),
1518 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots',
1519 'descriptor/convert-dots'))
1520 ],
1521 'no-verification': [
1522 (r'(locals|method|stack)%s' % _break, Keyword.Reserved, '#pop'),
1523 include('default')
1524 ],
1525 'static': [
1526 include('default'),
1527 (r'((?:%s[/.](?=[^%s]*[/.]))*)(%s[/.])?(%s)' %
1528 (_unqualified_name, _separator, _unqualified_name, _name),
1529 bygroups(Name.Namespace, Name.Class, Name.Variable.Class), '#pop')
1530 ],
1531 'table': [
1532 (r'\n+', Text),
1533 (r'default%s' % _break, Keyword.Reserved, '#pop'),
1534 include('default'),
1535 (_name, Name.Label)
1536 ],
1537 'var': [
1538 include('default'),
1539 (_name, Name.Variable, '#pop')
1540 ],
1541 'verification': [
1542 include('default'),
1543 (r'(Double|Float|Integer|Long|Null|Top|UninitializedThis)%s' %
1544 _break, Keyword, '#pop'),
1545 (r'Object%s' % _break, Keyword, ('#pop', 'class/no-dots')),
1546 (r'Uninitialized%s' % _break, Keyword, ('#pop', 'label'))
1547 ]
1548 }
1549
1550 def analyse_text(text):
1551 score = 0
1552 if re.search(r'^\s*\.class\s', text, re.MULTILINE):
1553 score += 0.5
1554 if re.search(r'^\s*[a-z]+_[a-z]+\b', text, re.MULTILINE):
1555 score += 0.3
1556 if re.search(r'^\s*\.(attribute|bytecode|debug|deprecated|enclosing|'
1557 r'inner|interface|limit|set|signature|stack)\b', text,
1558 re.MULTILINE):
1559 score += 0.6
1560 return score

eric ide

mercurial