jvm.py 69 KB

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