eric6/ThirdParty/Pygments/pygments/lexers/jvm.py

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

eric ide

mercurial