Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pygments/lexers/jvm.py : 87%

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