jvm.py 65 KB

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