javascript.py 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.javascript
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for JavaScript and related 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 RegexLexer, include, bygroups, default, using, \
  11. this, words, combined
  12. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  13. Number, Punctuation, Other
  14. from pygments.util import get_bool_opt, iteritems
  15. import pygments.unistring as uni
  16. __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer',
  17. 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer',
  18. 'CoffeeScriptLexer', 'MaskLexer', 'EarlGreyLexer', 'JuttleLexer']
  19. JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') +
  20. ']|\\\\u[a-fA-F0-9]{4})')
  21. JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',
  22. 'Mn', 'Mc', 'Nd', 'Pc') +
  23. u'\u200c\u200d]|\\\\u[a-fA-F0-9]{4})')
  24. JS_IDENT = JS_IDENT_START + '(?:' + JS_IDENT_PART + ')*'
  25. class JavascriptLexer(RegexLexer):
  26. """
  27. For JavaScript source code.
  28. """
  29. name = 'JavaScript'
  30. aliases = ['js', 'javascript']
  31. filenames = ['*.js', '*.jsm']
  32. mimetypes = ['application/javascript', 'application/x-javascript',
  33. 'text/x-javascript', 'text/javascript']
  34. flags = re.DOTALL | re.UNICODE | re.MULTILINE
  35. tokens = {
  36. 'commentsandwhitespace': [
  37. (r'\s+', Text),
  38. (r'<!--', Comment),
  39. (r'//.*?\n', Comment.Single),
  40. (r'/\*.*?\*/', Comment.Multiline)
  41. ],
  42. 'slashstartsregex': [
  43. include('commentsandwhitespace'),
  44. (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  45. r'([gimuy]+\b|\B)', String.Regex, '#pop'),
  46. (r'(?=/)', Text, ('#pop', 'badregex')),
  47. default('#pop')
  48. ],
  49. 'badregex': [
  50. (r'\n', Text, '#pop')
  51. ],
  52. 'root': [
  53. (r'\A#! ?/.*?\n', Comment.Hashbang), # recognized by node.js
  54. (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
  55. include('commentsandwhitespace'),
  56. (r'(\.\d+|[0-9]+\.[0-9]*)([eE][-+]?[0-9]+)?', Number.Float),
  57. (r'0[bB][01]+', Number.Bin),
  58. (r'0[oO][0-7]+', Number.Oct),
  59. (r'0[xX][0-9a-fA-F]+', Number.Hex),
  60. (r'[0-9]+', Number.Integer),
  61. (r'\.\.\.|=>', Punctuation),
  62. (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
  63. r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
  64. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  65. (r'[})\].]', Punctuation),
  66. (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
  67. r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|'
  68. r'this|of)\b', Keyword, 'slashstartsregex'),
  69. (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
  70. (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
  71. r'extends|final|float|goto|implements|import|int|interface|long|native|'
  72. r'package|private|protected|public|short|static|super|synchronized|throws|'
  73. r'transient|volatile)\b', Keyword.Reserved),
  74. (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
  75. (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
  76. r'Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|'
  77. r'decodeURIComponent|encodeURI|encodeURIComponent|'
  78. r'Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|'
  79. r'document|this|window)\b', Name.Builtin),
  80. (JS_IDENT, Name.Other),
  81. (r'"(\\\\|\\"|[^"])*"', String.Double),
  82. (r"'(\\\\|\\'|[^'])*'", String.Single),
  83. (r'`', String.Backtick, 'interp'),
  84. ],
  85. 'interp': [
  86. (r'`', String.Backtick, '#pop'),
  87. (r'\\\\', String.Backtick),
  88. (r'\\`', String.Backtick),
  89. (r'\$\{', String.Interpol, 'interp-inside'),
  90. (r'\$', String.Backtick),
  91. (r'[^`\\$]+', String.Backtick),
  92. ],
  93. 'interp-inside': [
  94. # TODO: should this include single-line comments and allow nesting strings?
  95. (r'\}', String.Interpol, '#pop'),
  96. include('root'),
  97. ],
  98. # (\\\\|\\`|[^`])*`', String.Backtick),
  99. }
  100. class KalLexer(RegexLexer):
  101. """
  102. For `Kal`_ source code.
  103. .. _Kal: http://rzimmerman.github.io/kal
  104. .. versionadded:: 2.0
  105. """
  106. name = 'Kal'
  107. aliases = ['kal']
  108. filenames = ['*.kal']
  109. mimetypes = ['text/kal', 'application/kal']
  110. flags = re.DOTALL
  111. tokens = {
  112. 'commentsandwhitespace': [
  113. (r'\s+', Text),
  114. (r'###[^#].*?###', Comment.Multiline),
  115. (r'#(?!##[^#]).*?\n', Comment.Single),
  116. ],
  117. 'functiondef': [
  118. (r'[$a-zA-Z_][\w$]*\s*', Name.Function, '#pop'),
  119. include('commentsandwhitespace'),
  120. ],
  121. 'classdef': [
  122. (r'\binherits\s+from\b', Keyword),
  123. (r'[$a-zA-Z_][\w$]*\s*\n', Name.Class, '#pop'),
  124. (r'[$a-zA-Z_][\w$]*\s*', Name.Class),
  125. include('commentsandwhitespace'),
  126. ],
  127. 'listcomprehension': [
  128. (r'\]', Punctuation, '#pop'),
  129. (r'\b(property|value)\b', Keyword),
  130. include('root'),
  131. ],
  132. 'waitfor': [
  133. (r'\n', Punctuation, '#pop'),
  134. (r'\bfrom\b', Keyword),
  135. include('root'),
  136. ],
  137. 'root': [
  138. include('commentsandwhitespace'),
  139. (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  140. r'([gim]+\b|\B)', String.Regex),
  141. (r'\?|:|_(?=\n)|==?|!=|-(?!>)|[<>+*/-]=?',
  142. Operator),
  143. (r'\b(and|or|isnt|is|not|but|bitwise|mod|\^|xor|exists|'
  144. r'doesnt\s+exist)\b', Operator.Word),
  145. (r'(?:\([^()]+\))?\s*>', Name.Function),
  146. (r'[{(]', Punctuation),
  147. (r'\[', Punctuation, 'listcomprehension'),
  148. (r'[})\].,]', Punctuation),
  149. (r'\b(function|method|task)\b', Keyword.Declaration, 'functiondef'),
  150. (r'\bclass\b', Keyword.Declaration, 'classdef'),
  151. (r'\b(safe\s+)?wait\s+for\b', Keyword, 'waitfor'),
  152. (r'\b(me|this)(\.[$a-zA-Z_][\w.$]*)?\b', Name.Variable.Instance),
  153. (r'(?<![.$])(for(\s+(parallel|series))?|in|of|while|until|'
  154. r'break|return|continue|'
  155. r'when|if|unless|else|otherwise|except\s+when|'
  156. r'throw|raise|fail\s+with|try|catch|finally|new|delete|'
  157. r'typeof|instanceof|super|run\s+in\s+parallel|'
  158. r'inherits\s+from)\b', Keyword),
  159. (r'(?<![.$])(true|false|yes|no|on|off|null|nothing|none|'
  160. r'NaN|Infinity|undefined)\b',
  161. Keyword.Constant),
  162. (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
  163. r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
  164. r'decodeURIComponent|encodeURI|encodeURIComponent|'
  165. r'eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|document|'
  166. r'window|'
  167. r'print)\b',
  168. Name.Builtin),
  169. (r'[$a-zA-Z_][\w.$]*\s*(:|[+\-*/]?\=)?\b', Name.Variable),
  170. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  171. (r'0x[0-9a-fA-F]+', Number.Hex),
  172. (r'[0-9]+', Number.Integer),
  173. ('"""', String, 'tdqs'),
  174. ("'''", String, 'tsqs'),
  175. ('"', String, 'dqs'),
  176. ("'", String, 'sqs'),
  177. ],
  178. 'strings': [
  179. (r'[^#\\\'"]+', String),
  180. # note that all kal strings are multi-line.
  181. # hashmarks, quotes and backslashes must be parsed one at a time
  182. ],
  183. 'interpoling_string': [
  184. (r'\}', String.Interpol, "#pop"),
  185. include('root')
  186. ],
  187. 'dqs': [
  188. (r'"', String, '#pop'),
  189. (r'\\.|\'', String), # double-quoted string don't need ' escapes
  190. (r'#\{', String.Interpol, "interpoling_string"),
  191. include('strings')
  192. ],
  193. 'sqs': [
  194. (r"'", String, '#pop'),
  195. (r'#|\\.|"', String), # single quoted strings don't need " escapses
  196. include('strings')
  197. ],
  198. 'tdqs': [
  199. (r'"""', String, '#pop'),
  200. (r'\\.|\'|"', String), # no need to escape quotes in triple-string
  201. (r'#\{', String.Interpol, "interpoling_string"),
  202. include('strings'),
  203. ],
  204. 'tsqs': [
  205. (r"'''", String, '#pop'),
  206. (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings
  207. include('strings')
  208. ],
  209. }
  210. class LiveScriptLexer(RegexLexer):
  211. """
  212. For `LiveScript`_ source code.
  213. .. _LiveScript: http://gkz.github.com/LiveScript/
  214. .. versionadded:: 1.6
  215. """
  216. name = 'LiveScript'
  217. aliases = ['live-script', 'livescript']
  218. filenames = ['*.ls']
  219. mimetypes = ['text/livescript']
  220. flags = re.DOTALL
  221. tokens = {
  222. 'commentsandwhitespace': [
  223. (r'\s+', Text),
  224. (r'/\*.*?\*/', Comment.Multiline),
  225. (r'#.*?\n', Comment.Single),
  226. ],
  227. 'multilineregex': [
  228. include('commentsandwhitespace'),
  229. (r'//([gim]+\b|\B)', String.Regex, '#pop'),
  230. (r'/', String.Regex),
  231. (r'[^/#]+', String.Regex)
  232. ],
  233. 'slashstartsregex': [
  234. include('commentsandwhitespace'),
  235. (r'//', String.Regex, ('#pop', 'multilineregex')),
  236. (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  237. r'([gim]+\b|\B)', String.Regex, '#pop'),
  238. default('#pop'),
  239. ],
  240. 'root': [
  241. # this next expr leads to infinite loops root -> slashstartsregex
  242. # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
  243. include('commentsandwhitespace'),
  244. (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|'
  245. r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function),
  246. (r'\+\+|&&|(?<![.$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|'
  247. r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|'
  248. r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|'
  249. r'[+*`%&|^/])=?',
  250. Operator, 'slashstartsregex'),
  251. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  252. (r'[})\].]', Punctuation),
  253. (r'(?<![.$])(for|own|in|of|while|until|loop|break|'
  254. r'return|continue|switch|when|then|if|unless|else|'
  255. r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
  256. r'extends|this|class|by|const|var|to|til)\b', Keyword,
  257. 'slashstartsregex'),
  258. (r'(?<![.$])(true|false|yes|no|on|off|'
  259. r'null|NaN|Infinity|undefined|void)\b',
  260. Keyword.Constant),
  261. (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
  262. r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
  263. r'decodeURIComponent|encodeURI|encodeURIComponent|'
  264. r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b',
  265. Name.Builtin),
  266. (r'[$a-zA-Z_][\w.\-:$]*\s*[:=]\s', Name.Variable,
  267. 'slashstartsregex'),
  268. (r'@[$a-zA-Z_][\w.\-:$]*\s*[:=]\s', Name.Variable.Instance,
  269. 'slashstartsregex'),
  270. (r'@', Name.Other, 'slashstartsregex'),
  271. (r'@?[$a-zA-Z_][\w-]*', Name.Other, 'slashstartsregex'),
  272. (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float),
  273. (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer),
  274. ('"""', String, 'tdqs'),
  275. ("'''", String, 'tsqs'),
  276. ('"', String, 'dqs'),
  277. ("'", String, 'sqs'),
  278. (r'\\\S+', String),
  279. (r'<\[.*?\]>', String),
  280. ],
  281. 'strings': [
  282. (r'[^#\\\'"]+', String),
  283. # note that all coffee script strings are multi-line.
  284. # hashmarks, quotes and backslashes must be parsed one at a time
  285. ],
  286. 'interpoling_string': [
  287. (r'\}', String.Interpol, "#pop"),
  288. include('root')
  289. ],
  290. 'dqs': [
  291. (r'"', String, '#pop'),
  292. (r'\\.|\'', String), # double-quoted string don't need ' escapes
  293. (r'#\{', String.Interpol, "interpoling_string"),
  294. (r'#', String),
  295. include('strings')
  296. ],
  297. 'sqs': [
  298. (r"'", String, '#pop'),
  299. (r'#|\\.|"', String), # single quoted strings don't need " escapses
  300. include('strings')
  301. ],
  302. 'tdqs': [
  303. (r'"""', String, '#pop'),
  304. (r'\\.|\'|"', String), # no need to escape quotes in triple-string
  305. (r'#\{', String.Interpol, "interpoling_string"),
  306. (r'#', String),
  307. include('strings'),
  308. ],
  309. 'tsqs': [
  310. (r"'''", String, '#pop'),
  311. (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings
  312. include('strings')
  313. ],
  314. }
  315. class DartLexer(RegexLexer):
  316. """
  317. For `Dart <http://dartlang.org/>`_ source code.
  318. .. versionadded:: 1.5
  319. """
  320. name = 'Dart'
  321. aliases = ['dart']
  322. filenames = ['*.dart']
  323. mimetypes = ['text/x-dart']
  324. flags = re.MULTILINE | re.DOTALL
  325. tokens = {
  326. 'root': [
  327. include('string_literal'),
  328. (r'#!(.*?)$', Comment.Preproc),
  329. (r'\b(import|export)\b', Keyword, 'import_decl'),
  330. (r'\b(library|source|part of|part)\b', Keyword),
  331. (r'[^\S\n]+', Text),
  332. (r'//.*?\n', Comment.Single),
  333. (r'/\*.*?\*/', Comment.Multiline),
  334. (r'\b(class)\b(\s+)',
  335. bygroups(Keyword.Declaration, Text), 'class'),
  336. (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|'
  337. r'if|in|is|new|return|super|switch|this|throw|try|while)\b',
  338. Keyword),
  339. (r'\b(abstract|async|await|const|extends|factory|final|get|'
  340. r'implements|native|operator|set|static|sync|typedef|var|with|'
  341. r'yield)\b', Keyword.Declaration),
  342. (r'\b(bool|double|dynamic|int|num|Object|String|void)\b', Keyword.Type),
  343. (r'\b(false|null|true)\b', Keyword.Constant),
  344. (r'[~!%^&*+=|?:<>/-]|as\b', Operator),
  345. (r'@[a-zA-Z_$]\w*', Name.Decorator),
  346. (r'[a-zA-Z_$]\w*:', Name.Label),
  347. (r'[a-zA-Z_$]\w*', Name),
  348. (r'[(){}\[\],.;]', Punctuation),
  349. (r'0[xX][0-9a-fA-F]+', Number.Hex),
  350. # DIGIT+ (‘.’ DIGIT*)? EXPONENT?
  351. (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number),
  352. (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT?
  353. (r'\n', Text)
  354. # pseudo-keyword negate intentionally left out
  355. ],
  356. 'class': [
  357. (r'[a-zA-Z_$]\w*', Name.Class, '#pop')
  358. ],
  359. 'import_decl': [
  360. include('string_literal'),
  361. (r'\s+', Text),
  362. (r'\b(as|show|hide)\b', Keyword),
  363. (r'[a-zA-Z_$]\w*', Name),
  364. (r'\,', Punctuation),
  365. (r'\;', Punctuation, '#pop')
  366. ],
  367. 'string_literal': [
  368. # Raw strings.
  369. (r'r"""([\w\W]*?)"""', String.Double),
  370. (r"r'''([\w\W]*?)'''", String.Single),
  371. (r'r"(.*?)"', String.Double),
  372. (r"r'(.*?)'", String.Single),
  373. # Normal Strings.
  374. (r'"""', String.Double, 'string_double_multiline'),
  375. (r"'''", String.Single, 'string_single_multiline'),
  376. (r'"', String.Double, 'string_double'),
  377. (r"'", String.Single, 'string_single')
  378. ],
  379. 'string_common': [
  380. (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z'\"$\\])",
  381. String.Escape),
  382. (r'(\$)([a-zA-Z_]\w*)', bygroups(String.Interpol, Name)),
  383. (r'(\$\{)(.*?)(\})',
  384. bygroups(String.Interpol, using(this), String.Interpol))
  385. ],
  386. 'string_double': [
  387. (r'"', String.Double, '#pop'),
  388. (r'[^"$\\\n]+', String.Double),
  389. include('string_common'),
  390. (r'\$+', String.Double)
  391. ],
  392. 'string_double_multiline': [
  393. (r'"""', String.Double, '#pop'),
  394. (r'[^"$\\]+', String.Double),
  395. include('string_common'),
  396. (r'(\$|\")+', String.Double)
  397. ],
  398. 'string_single': [
  399. (r"'", String.Single, '#pop'),
  400. (r"[^'$\\\n]+", String.Single),
  401. include('string_common'),
  402. (r'\$+', String.Single)
  403. ],
  404. 'string_single_multiline': [
  405. (r"'''", String.Single, '#pop'),
  406. (r'[^\'$\\]+', String.Single),
  407. include('string_common'),
  408. (r'(\$|\')+', String.Single)
  409. ]
  410. }
  411. class TypeScriptLexer(RegexLexer):
  412. """
  413. For `TypeScript <http://typescriptlang.org/>`_ source code.
  414. .. versionadded:: 1.6
  415. """
  416. name = 'TypeScript'
  417. aliases = ['ts', 'typescript']
  418. filenames = ['*.ts', '*.tsx']
  419. mimetypes = ['text/x-typescript']
  420. flags = re.DOTALL | re.MULTILINE
  421. # Higher priority than the TypoScriptLexer, as TypeScript is far more
  422. # common these days
  423. priority = 0.5
  424. tokens = {
  425. 'commentsandwhitespace': [
  426. (r'\s+', Text),
  427. (r'<!--', Comment),
  428. (r'//.*?\n', Comment.Single),
  429. (r'/\*.*?\*/', Comment.Multiline)
  430. ],
  431. 'slashstartsregex': [
  432. include('commentsandwhitespace'),
  433. (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  434. r'([gim]+\b|\B)', String.Regex, '#pop'),
  435. (r'(?=/)', Text, ('#pop', 'badregex')),
  436. default('#pop')
  437. ],
  438. 'badregex': [
  439. (r'\n', Text, '#pop')
  440. ],
  441. 'root': [
  442. (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
  443. include('commentsandwhitespace'),
  444. (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
  445. r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
  446. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  447. (r'[})\].]', Punctuation),
  448. (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
  449. r'throw|try|catch|finally|new|delete|typeof|instanceof|void|of|'
  450. r'this)\b', Keyword, 'slashstartsregex'),
  451. (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
  452. (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
  453. r'extends|final|float|goto|implements|import|int|interface|long|native|'
  454. r'package|private|protected|public|short|static|super|synchronized|throws|'
  455. r'transient|volatile)\b', Keyword.Reserved),
  456. (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
  457. (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
  458. r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
  459. r'decodeURIComponent|encodeURI|encodeURIComponent|'
  460. r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
  461. r'window)\b', Name.Builtin),
  462. # Match stuff like: module name {...}
  463. (r'\b(module)(\s*)(\s*[\w?.$][\w?.$]*)(\s*)',
  464. bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'),
  465. # Match variable type keywords
  466. (r'\b(string|bool|number)\b', Keyword.Type),
  467. # Match stuff like: constructor
  468. (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved),
  469. # Match stuff like: super(argument, list)
  470. (r'(super)(\s*)(\([\w,?.$\s]+\s*\))',
  471. bygroups(Keyword.Reserved, Text), 'slashstartsregex'),
  472. # Match stuff like: function() {...}
  473. (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'),
  474. # Match stuff like: (function: return type)
  475. (r'([\w?.$][\w?.$]*)(\s*:\s*)([\w?.$][\w?.$]*)',
  476. bygroups(Name.Other, Text, Keyword.Type)),
  477. (r'[$a-zA-Z_]\w*', Name.Other),
  478. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  479. (r'0x[0-9a-fA-F]+', Number.Hex),
  480. (r'[0-9]+', Number.Integer),
  481. (r'"(\\\\|\\"|[^"])*"', String.Double),
  482. (r"'(\\\\|\\'|[^'])*'", String.Single),
  483. (r'`', String.Backtick, 'interp'),
  484. # Match stuff like: Decorators
  485. (r'@\w+', Keyword.Declaration),
  486. ],
  487. # The 'interp*' rules match those in JavascriptLexer. Changes made
  488. # there should be reflected here as well.
  489. 'interp': [
  490. (r'`', String.Backtick, '#pop'),
  491. (r'\\\\', String.Backtick),
  492. (r'\\`', String.Backtick),
  493. (r'\$\{', String.Interpol, 'interp-inside'),
  494. (r'\$', String.Backtick),
  495. (r'[^`\\$]+', String.Backtick),
  496. ],
  497. 'interp-inside': [
  498. # TODO: should this include single-line comments and allow nesting strings?
  499. (r'\}', String.Interpol, '#pop'),
  500. include('root'),
  501. ],
  502. }
  503. class LassoLexer(RegexLexer):
  504. """
  505. For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9
  506. syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in
  507. HTML, use the `LassoHtmlLexer`.
  508. Additional options accepted:
  509. `builtinshighlighting`
  510. If given and ``True``, highlight builtin types, traits, methods, and
  511. members (default: ``True``).
  512. `requiredelimiters`
  513. If given and ``True``, only highlight code between delimiters as Lasso
  514. (default: ``False``).
  515. .. versionadded:: 1.6
  516. """
  517. name = 'Lasso'
  518. aliases = ['lasso', 'lassoscript']
  519. filenames = ['*.lasso', '*.lasso[89]']
  520. alias_filenames = ['*.incl', '*.inc', '*.las']
  521. mimetypes = ['text/x-lasso']
  522. flags = re.IGNORECASE | re.DOTALL | re.MULTILINE
  523. tokens = {
  524. 'root': [
  525. (r'^#![ \S]+lasso9\b', Comment.Preproc, 'lasso'),
  526. (r'(?=\[|<)', Other, 'delimiters'),
  527. (r'\s+', Other),
  528. default(('delimiters', 'lassofile')),
  529. ],
  530. 'delimiters': [
  531. (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'),
  532. (r'\[noprocess\]', Comment.Preproc, 'noprocess'),
  533. (r'\[', Comment.Preproc, 'squarebrackets'),
  534. (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'),
  535. (r'<(!--.*?-->)?', Other),
  536. (r'[^[<]+', Other),
  537. ],
  538. 'nosquarebrackets': [
  539. (r'\[noprocess\]', Comment.Preproc, 'noprocess'),
  540. (r'\[', Other),
  541. (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'),
  542. (r'<(!--.*?-->)?', Other),
  543. (r'[^[<]+', Other),
  544. ],
  545. 'noprocess': [
  546. (r'\[/noprocess\]', Comment.Preproc, '#pop'),
  547. (r'\[', Other),
  548. (r'[^[]', Other),
  549. ],
  550. 'squarebrackets': [
  551. (r'\]', Comment.Preproc, '#pop'),
  552. include('lasso'),
  553. ],
  554. 'anglebrackets': [
  555. (r'\?>', Comment.Preproc, '#pop'),
  556. include('lasso'),
  557. ],
  558. 'lassofile': [
  559. (r'\]|\?>', Comment.Preproc, '#pop'),
  560. include('lasso'),
  561. ],
  562. 'whitespacecomments': [
  563. (r'\s+', Text),
  564. (r'//.*?\n', Comment.Single),
  565. (r'/\*\*!.*?\*/', String.Doc),
  566. (r'/\*.*?\*/', Comment.Multiline),
  567. ],
  568. 'lasso': [
  569. # whitespace/comments
  570. include('whitespacecomments'),
  571. # literals
  572. (r'\d*\.\d+(e[+-]?\d+)?', Number.Float),
  573. (r'0x[\da-f]+', Number.Hex),
  574. (r'\d+', Number.Integer),
  575. (r'(infinity|NaN)\b', Number),
  576. (r"'", String.Single, 'singlestring'),
  577. (r'"', String.Double, 'doublestring'),
  578. (r'`[^`]*`', String.Backtick),
  579. # names
  580. (r'\$[a-z_][\w.]*', Name.Variable),
  581. (r'#([a-z_][\w.]*|\d+\b)', Name.Variable.Instance),
  582. (r"(\.\s*)('[a-z_][\w.]*')",
  583. bygroups(Name.Builtin.Pseudo, Name.Variable.Class)),
  584. (r"(self)(\s*->\s*)('[a-z_][\w.]*')",
  585. bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)),
  586. (r'(\.\.?\s*)([a-z_][\w.]*(=(?!=))?)',
  587. bygroups(Name.Builtin.Pseudo, Name.Other.Member)),
  588. (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)',
  589. bygroups(Operator, Name.Other.Member)),
  590. (r'(?<!->)(self|inherited|currentcapture|givenblock)\b',
  591. Name.Builtin.Pseudo),
  592. (r'-(?!infinity)[a-z_][\w.]*', Name.Attribute),
  593. (r'::\s*[a-z_][\w.]*', Name.Label),
  594. (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|'
  595. r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|'
  596. r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|'
  597. r'Error_InvalidDatabase|Error_InvalidPassword|'
  598. r'Error_InvalidUsername|Error_ModuleNotFound|'
  599. r'Error_NoError|Error_NoPermission|Error_OutOfMemory|'
  600. r'Error_ReqColumnMissing|Error_ReqFieldMissing|'
  601. r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|'
  602. r'Error_UpdateError)\b', Name.Exception),
  603. # definitions
  604. (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b',
  605. bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)),
  606. (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%])',
  607. bygroups(Keyword.Declaration, Text, Name.Class, Operator,
  608. Name.Function), 'signature'),
  609. (r'(define)(\s+)([a-z_][\w.]*)',
  610. bygroups(Keyword.Declaration, Text, Name.Function), 'signature'),
  611. (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])'
  612. r'(?=\s*\())', bygroups(Keyword, Text, Name.Function),
  613. 'signature'),
  614. (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)',
  615. bygroups(Keyword, Text, Name.Function)),
  616. # keywords
  617. (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant),
  618. (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration),
  619. (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|'
  620. r'null|boolean|bytes|keyword|list|locale|queue|set|stack|'
  621. r'staticarray)\b', Keyword.Type),
  622. (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)),
  623. (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)),
  624. (r'require\b', Keyword, 'requiresection'),
  625. (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)),
  626. (r'(/?)(Cache|Database_Names|Database_SchemaNames|'
  627. r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|'
  628. r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|'
  629. r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|'
  630. r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|Link_FirstRecord|'
  631. r'Link_LastGroup|Link_LastRecord|Link_NextGroup|Link_NextRecord|'
  632. r'Link_PrevGroup|Link_PrevRecord|Log|Loop|Output_None|Portal|'
  633. r'Private|Protect|Records|Referer|Referrer|Repeating|ResultSet|'
  634. r'Rows|Search_Args|Search_Arguments|Select|Sort_Args|'
  635. r'Sort_Arguments|Thread_Atomic|Value_List|While|Abort|Case|Else|'
  636. r'Fail_If|Fail_IfNot|Fail|If_Empty|If_False|If_Null|If_True|'
  637. r'Loop_Abort|Loop_Continue|Loop_Count|Params|Params_Up|Return|'
  638. r'Return_Value|Run_Children|SOAP_DefineTag|SOAP_LastRequest|'
  639. r'SOAP_LastResponse|Tag_Name|ascending|average|by|define|'
  640. r'descending|do|equals|frozen|group|handle_failure|import|in|into|'
  641. r'join|let|match|max|min|on|order|parent|protected|provide|public|'
  642. r'require|returnhome|skip|split_thread|sum|take|thread|to|trait|'
  643. r'type|where|with|yield|yieldhome)\b',
  644. bygroups(Punctuation, Keyword)),
  645. # other
  646. (r',', Punctuation, 'commamember'),
  647. (r'(and|or|not)\b', Operator.Word),
  648. (r'([a-z_][\w.]*)(\s*::\s*[a-z_][\w.]*)?(\s*=(?!=))',
  649. bygroups(Name, Name.Label, Operator)),
  650. (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)),
  651. (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b',
  652. bygroups(Operator, Operator.Word)),
  653. (r':=|[-+*/%=<>&|!?\\]+', Operator),
  654. (r'[{}():;,@^]', Punctuation),
  655. ],
  656. 'singlestring': [
  657. (r"'", String.Single, '#pop'),
  658. (r"[^'\\]+", String.Single),
  659. include('escape'),
  660. (r"\\", String.Single),
  661. ],
  662. 'doublestring': [
  663. (r'"', String.Double, '#pop'),
  664. (r'[^"\\]+', String.Double),
  665. include('escape'),
  666. (r'\\', String.Double),
  667. ],
  668. 'escape': [
  669. (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:\n\r]+:|'
  670. r'[abefnrtv?"\'\\]|$)', String.Escape),
  671. ],
  672. 'signature': [
  673. (r'=>', Operator, '#pop'),
  674. (r'\)', Punctuation, '#pop'),
  675. (r'[(,]', Punctuation, 'parameter'),
  676. include('lasso'),
  677. ],
  678. 'parameter': [
  679. (r'\)', Punctuation, '#pop'),
  680. (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'),
  681. (r'\.\.\.', Name.Builtin.Pseudo),
  682. include('lasso'),
  683. ],
  684. 'requiresection': [
  685. (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'),
  686. (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name),
  687. (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'),
  688. (r'::\s*[a-z_][\w.]*', Name.Label),
  689. (r',', Punctuation),
  690. include('whitespacecomments'),
  691. ],
  692. 'requiresignature': [
  693. (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'),
  694. (r'\)', Punctuation, '#pop:2'),
  695. (r'-?[a-z_][\w.]*', Name.Attribute),
  696. (r'::\s*[a-z_][\w.]*', Name.Label),
  697. (r'\.\.\.', Name.Builtin.Pseudo),
  698. (r'[(,]', Punctuation),
  699. include('whitespacecomments'),
  700. ],
  701. 'commamember': [
  702. (r'(([a-z_][\w.]*=?|[-+*/%])'
  703. r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))',
  704. Name.Function, 'signature'),
  705. include('whitespacecomments'),
  706. default('#pop'),
  707. ],
  708. }
  709. def __init__(self, **options):
  710. self.builtinshighlighting = get_bool_opt(
  711. options, 'builtinshighlighting', True)
  712. self.requiredelimiters = get_bool_opt(
  713. options, 'requiredelimiters', False)
  714. self._builtins = set()
  715. self._members = set()
  716. if self.builtinshighlighting:
  717. from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS
  718. for key, value in iteritems(BUILTINS):
  719. self._builtins.update(value)
  720. for key, value in iteritems(MEMBERS):
  721. self._members.update(value)
  722. RegexLexer.__init__(self, **options)
  723. def get_tokens_unprocessed(self, text):
  724. stack = ['root']
  725. if self.requiredelimiters:
  726. stack.append('delimiters')
  727. for index, token, value in \
  728. RegexLexer.get_tokens_unprocessed(self, text, stack):
  729. if (token is Name.Other and value.lower() in self._builtins or
  730. token is Name.Other.Member and
  731. value.lower().rstrip('=') in self._members):
  732. yield index, Name.Builtin, value
  733. continue
  734. yield index, token, value
  735. def analyse_text(text):
  736. rv = 0.0
  737. if 'bin/lasso9' in text:
  738. rv += 0.8
  739. if re.search(r'<\?lasso', text, re.I):
  740. rv += 0.4
  741. if re.search(r'local\(', text, re.I):
  742. rv += 0.4
  743. return rv
  744. class ObjectiveJLexer(RegexLexer):
  745. """
  746. For Objective-J source code with preprocessor directives.
  747. .. versionadded:: 1.3
  748. """
  749. name = 'Objective-J'
  750. aliases = ['objective-j', 'objectivej', 'obj-j', 'objj']
  751. filenames = ['*.j']
  752. mimetypes = ['text/x-objective-j']
  753. #: optional Comment or Whitespace
  754. _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*'
  755. flags = re.DOTALL | re.MULTILINE
  756. tokens = {
  757. 'root': [
  758. include('whitespace'),
  759. # function definition
  760. (r'^(' + _ws + r'[+-]' + _ws + r')([(a-zA-Z_].*?[^(])(' + _ws + r'\{)',
  761. bygroups(using(this), using(this, state='function_signature'),
  762. using(this))),
  763. # class definition
  764. (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
  765. 'classname'),
  766. (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text),
  767. 'forward_classname'),
  768. (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
  769. include('statements'),
  770. ('[{()}]', Punctuation),
  771. (';', Punctuation),
  772. ],
  773. 'whitespace': [
  774. (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")',
  775. bygroups(Comment.Preproc, Text, String.Double)),
  776. (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)',
  777. bygroups(Comment.Preproc, Text, String.Double)),
  778. (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")',
  779. bygroups(Comment.Preproc, Text, String.Double)),
  780. (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)',
  781. bygroups(Comment.Preproc, Text, String.Double)),
  782. (r'#if\s+0', Comment.Preproc, 'if0'),
  783. (r'#', Comment.Preproc, 'macro'),
  784. (r'\n', Text),
  785. (r'\s+', Text),
  786. (r'\\\n', Text), # line continuation
  787. (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
  788. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  789. (r'<!--', Comment),
  790. ],
  791. 'slashstartsregex': [
  792. include('whitespace'),
  793. (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  794. r'([gim]+\b|\B)', String.Regex, '#pop'),
  795. (r'(?=/)', Text, ('#pop', 'badregex')),
  796. default('#pop'),
  797. ],
  798. 'badregex': [
  799. (r'\n', Text, '#pop'),
  800. ],
  801. 'statements': [
  802. (r'(L|@)?"', String, 'string'),
  803. (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
  804. String.Char),
  805. (r'"(\\\\|\\"|[^"])*"', String.Double),
  806. (r"'(\\\\|\\'|[^'])*'", String.Single),
  807. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
  808. (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
  809. (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
  810. (r'0[0-7]+[Ll]?', Number.Oct),
  811. (r'\d+[Ll]?', Number.Integer),
  812. (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
  813. (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
  814. r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?',
  815. Operator, 'slashstartsregex'),
  816. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  817. (r'[})\].]', Punctuation),
  818. (r'(for|in|while|do|break|return|continue|switch|case|default|if|'
  819. r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|'
  820. r'prototype|__proto__)\b', Keyword, 'slashstartsregex'),
  821. (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
  822. (r'(@selector|@private|@protected|@public|@encode|'
  823. r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
  824. r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword),
  825. (r'(int|long|float|short|double|char|unsigned|signed|void|'
  826. r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b',
  827. Keyword.Type),
  828. (r'(self|super)\b', Name.Builtin),
  829. (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant),
  830. (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant),
  831. (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|'
  832. r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|'
  833. r'SQRT2)\b', Keyword.Constant),
  834. (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
  835. r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
  836. r'decodeURIComponent|encodeURI|encodeURIComponent|'
  837. r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|'
  838. r'window)\b', Name.Builtin),
  839. (r'([$a-zA-Z_]\w*)(' + _ws + r')(?=\()',
  840. bygroups(Name.Function, using(this))),
  841. (r'[$a-zA-Z_]\w*', Name),
  842. ],
  843. 'classname': [
  844. # interface definition that inherits
  845. (r'([a-zA-Z_]\w*)(' + _ws + r':' + _ws +
  846. r')([a-zA-Z_]\w*)?',
  847. bygroups(Name.Class, using(this), Name.Class), '#pop'),
  848. # interface definition for a category
  849. (r'([a-zA-Z_]\w*)(' + _ws + r'\()([a-zA-Z_]\w*)(\))',
  850. bygroups(Name.Class, using(this), Name.Label, Text), '#pop'),
  851. # simple interface / implementation
  852. (r'([a-zA-Z_]\w*)', Name.Class, '#pop'),
  853. ],
  854. 'forward_classname': [
  855. (r'([a-zA-Z_]\w*)(\s*,\s*)',
  856. bygroups(Name.Class, Text), '#push'),
  857. (r'([a-zA-Z_]\w*)(\s*;?)',
  858. bygroups(Name.Class, Text), '#pop'),
  859. ],
  860. 'function_signature': [
  861. include('whitespace'),
  862. # start of a selector w/ parameters
  863. (r'(\(' + _ws + r')' # open paren
  864. r'([a-zA-Z_]\w+)' # return type
  865. r'(' + _ws + r'\)' + _ws + r')' # close paren
  866. r'([$a-zA-Z_]\w+' + _ws + r':)', # function name
  867. bygroups(using(this), Keyword.Type, using(this),
  868. Name.Function), 'function_parameters'),
  869. # no-param function
  870. (r'(\(' + _ws + r')' # open paren
  871. r'([a-zA-Z_]\w+)' # return type
  872. r'(' + _ws + r'\)' + _ws + r')' # close paren
  873. r'([$a-zA-Z_]\w+)', # function name
  874. bygroups(using(this), Keyword.Type, using(this),
  875. Name.Function), "#pop"),
  876. # no return type given, start of a selector w/ parameters
  877. (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name
  878. bygroups(Name.Function), 'function_parameters'),
  879. # no return type given, no-param function
  880. (r'([$a-zA-Z_]\w+)', # function name
  881. bygroups(Name.Function), "#pop"),
  882. default('#pop'),
  883. ],
  884. 'function_parameters': [
  885. include('whitespace'),
  886. # parameters
  887. (r'(\(' + _ws + ')' # open paren
  888. r'([^)]+)' # type
  889. r'(' + _ws + r'\)' + _ws + r')' # close paren
  890. r'([$a-zA-Z_]\w+)', # param name
  891. bygroups(using(this), Keyword.Type, using(this), Text)),
  892. # one piece of a selector name
  893. (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name
  894. Name.Function),
  895. # smallest possible selector piece
  896. (r'(:)', Name.Function),
  897. # var args
  898. (r'(,' + _ws + r'\.\.\.)', using(this)),
  899. # param name
  900. (r'([$a-zA-Z_]\w+)', Text),
  901. ],
  902. 'expression': [
  903. (r'([$a-zA-Z_]\w*)(\()', bygroups(Name.Function,
  904. Punctuation)),
  905. (r'(\))', Punctuation, "#pop"),
  906. ],
  907. 'string': [
  908. (r'"', String, '#pop'),
  909. (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  910. (r'[^\\"\n]+', String), # all other characters
  911. (r'\\\n', String), # line continuation
  912. (r'\\', String), # stray backslash
  913. ],
  914. 'macro': [
  915. (r'[^/\n]+', Comment.Preproc),
  916. (r'/[*](.|\n)*?[*]/', Comment.Multiline),
  917. (r'//.*?\n', Comment.Single, '#pop'),
  918. (r'/', Comment.Preproc),
  919. (r'(?<=\\)\n', Comment.Preproc),
  920. (r'\n', Comment.Preproc, '#pop'),
  921. ],
  922. 'if0': [
  923. (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
  924. (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
  925. (r'.*?\n', Comment),
  926. ]
  927. }
  928. def analyse_text(text):
  929. if re.search(r'^\s*@import\s+[<"]', text, re.MULTILINE):
  930. # special directive found in most Objective-J files
  931. return True
  932. return False
  933. class CoffeeScriptLexer(RegexLexer):
  934. """
  935. For `CoffeeScript`_ source code.
  936. .. _CoffeeScript: http://coffeescript.org
  937. .. versionadded:: 1.3
  938. """
  939. name = 'CoffeeScript'
  940. aliases = ['coffee-script', 'coffeescript', 'coffee']
  941. filenames = ['*.coffee']
  942. mimetypes = ['text/coffeescript']
  943. _operator_re = (
  944. r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|'
  945. r'\|\||\\(?=\n)|'
  946. r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?')
  947. flags = re.DOTALL
  948. tokens = {
  949. 'commentsandwhitespace': [
  950. (r'\s+', Text),
  951. (r'###[^#].*?###', Comment.Multiline),
  952. (r'#(?!##[^#]).*?\n', Comment.Single),
  953. ],
  954. 'multilineregex': [
  955. (r'[^/#]+', String.Regex),
  956. (r'///([gim]+\b|\B)', String.Regex, '#pop'),
  957. (r'#\{', String.Interpol, 'interpoling_string'),
  958. (r'[/#]', String.Regex),
  959. ],
  960. 'slashstartsregex': [
  961. include('commentsandwhitespace'),
  962. (r'///', String.Regex, ('#pop', 'multilineregex')),
  963. (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  964. r'([gim]+\b|\B)', String.Regex, '#pop'),
  965. # This isn't really guarding against mishighlighting well-formed
  966. # code, just the ability to infinite-loop between root and
  967. # slashstartsregex.
  968. (r'/', Operator),
  969. default('#pop'),
  970. ],
  971. 'root': [
  972. include('commentsandwhitespace'),
  973. (r'^(?=\s|/)', Text, 'slashstartsregex'),
  974. (_operator_re, Operator, 'slashstartsregex'),
  975. (r'(?:\([^()]*\))?\s*[=-]>', Name.Function, 'slashstartsregex'),
  976. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  977. (r'[})\].]', Punctuation),
  978. (r'(?<![.$])(for|own|in|of|while|until|'
  979. r'loop|break|return|continue|'
  980. r'switch|when|then|if|unless|else|'
  981. r'throw|try|catch|finally|new|delete|typeof|instanceof|super|'
  982. r'extends|this|class|by)\b', Keyword, 'slashstartsregex'),
  983. (r'(?<![.$])(true|false|yes|no|on|off|null|'
  984. r'NaN|Infinity|undefined)\b',
  985. Keyword.Constant),
  986. (r'(Array|Boolean|Date|Error|Function|Math|netscape|'
  987. r'Number|Object|Packages|RegExp|String|sun|decodeURI|'
  988. r'decodeURIComponent|encodeURI|encodeURIComponent|'
  989. r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b',
  990. Name.Builtin),
  991. (r'[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable,
  992. 'slashstartsregex'),
  993. (r'@[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable.Instance,
  994. 'slashstartsregex'),
  995. (r'@', Name.Other, 'slashstartsregex'),
  996. (r'@?[$a-zA-Z_][\w$]*', Name.Other),
  997. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  998. (r'0x[0-9a-fA-F]+', Number.Hex),
  999. (r'[0-9]+', Number.Integer),
  1000. ('"""', String, 'tdqs'),
  1001. ("'''", String, 'tsqs'),
  1002. ('"', String, 'dqs'),
  1003. ("'", String, 'sqs'),
  1004. ],
  1005. 'strings': [
  1006. (r'[^#\\\'"]+', String),
  1007. # note that all coffee script strings are multi-line.
  1008. # hashmarks, quotes and backslashes must be parsed one at a time
  1009. ],
  1010. 'interpoling_string': [
  1011. (r'\}', String.Interpol, "#pop"),
  1012. include('root')
  1013. ],
  1014. 'dqs': [
  1015. (r'"', String, '#pop'),
  1016. (r'\\.|\'', String), # double-quoted string don't need ' escapes
  1017. (r'#\{', String.Interpol, "interpoling_string"),
  1018. (r'#', String),
  1019. include('strings')
  1020. ],
  1021. 'sqs': [
  1022. (r"'", String, '#pop'),
  1023. (r'#|\\.|"', String), # single quoted strings don't need " escapses
  1024. include('strings')
  1025. ],
  1026. 'tdqs': [
  1027. (r'"""', String, '#pop'),
  1028. (r'\\.|\'|"', String), # no need to escape quotes in triple-string
  1029. (r'#\{', String.Interpol, "interpoling_string"),
  1030. (r'#', String),
  1031. include('strings'),
  1032. ],
  1033. 'tsqs': [
  1034. (r"'''", String, '#pop'),
  1035. (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings
  1036. include('strings')
  1037. ],
  1038. }
  1039. class MaskLexer(RegexLexer):
  1040. """
  1041. For `Mask <http://github.com/atmajs/MaskJS>`__ markup.
  1042. .. versionadded:: 2.0
  1043. """
  1044. name = 'Mask'
  1045. aliases = ['mask']
  1046. filenames = ['*.mask']
  1047. mimetypes = ['text/x-mask']
  1048. flags = re.MULTILINE | re.IGNORECASE | re.DOTALL
  1049. tokens = {
  1050. 'root': [
  1051. (r'\s+', Text),
  1052. (r'//.*?\n', Comment.Single),
  1053. (r'/\*.*?\*/', Comment.Multiline),
  1054. (r'[{};>]', Punctuation),
  1055. (r"'''", String, 'string-trpl-single'),
  1056. (r'"""', String, 'string-trpl-double'),
  1057. (r"'", String, 'string-single'),
  1058. (r'"', String, 'string-double'),
  1059. (r'([\w-]+)', Name.Tag, 'node'),
  1060. (r'([^.#;{>\s]+)', Name.Class, 'node'),
  1061. (r'(#[\w-]+)', Name.Function, 'node'),
  1062. (r'(\.[\w-]+)', Name.Variable.Class, 'node')
  1063. ],
  1064. 'string-base': [
  1065. (r'\\.', String.Escape),
  1066. (r'~\[', String.Interpol, 'interpolation'),
  1067. (r'.', String.Single),
  1068. ],
  1069. 'string-single': [
  1070. (r"'", String.Single, '#pop'),
  1071. include('string-base')
  1072. ],
  1073. 'string-double': [
  1074. (r'"', String.Single, '#pop'),
  1075. include('string-base')
  1076. ],
  1077. 'string-trpl-single': [
  1078. (r"'''", String.Single, '#pop'),
  1079. include('string-base')
  1080. ],
  1081. 'string-trpl-double': [
  1082. (r'"""', String.Single, '#pop'),
  1083. include('string-base')
  1084. ],
  1085. 'interpolation': [
  1086. (r'\]', String.Interpol, '#pop'),
  1087. (r'\s*:', String.Interpol, 'expression'),
  1088. (r'\s*\w+:', Name.Other),
  1089. (r'[^\]]+', String.Interpol)
  1090. ],
  1091. 'expression': [
  1092. (r'[^\]]+', using(JavascriptLexer), '#pop')
  1093. ],
  1094. 'node': [
  1095. (r'\s+', Text),
  1096. (r'\.', Name.Variable.Class, 'node-class'),
  1097. (r'\#', Name.Function, 'node-id'),
  1098. (r'style[ \t]*=', Name.Attribute, 'node-attr-style-value'),
  1099. (r'[\w:-]+[ \t]*=', Name.Attribute, 'node-attr-value'),
  1100. (r'[\w:-]+', Name.Attribute),
  1101. (r'[>{;]', Punctuation, '#pop')
  1102. ],
  1103. 'node-class': [
  1104. (r'[\w-]+', Name.Variable.Class),
  1105. (r'~\[', String.Interpol, 'interpolation'),
  1106. default('#pop')
  1107. ],
  1108. 'node-id': [
  1109. (r'[\w-]+', Name.Function),
  1110. (r'~\[', String.Interpol, 'interpolation'),
  1111. default('#pop')
  1112. ],
  1113. 'node-attr-value': [
  1114. (r'\s+', Text),
  1115. (r'\w+', Name.Variable, '#pop'),
  1116. (r"'", String, 'string-single-pop2'),
  1117. (r'"', String, 'string-double-pop2'),
  1118. default('#pop')
  1119. ],
  1120. 'node-attr-style-value': [
  1121. (r'\s+', Text),
  1122. (r"'", String.Single, 'css-single-end'),
  1123. (r'"', String.Single, 'css-double-end'),
  1124. include('node-attr-value')
  1125. ],
  1126. 'css-base': [
  1127. (r'\s+', Text),
  1128. (r";", Punctuation),
  1129. (r"[\w\-]+\s*:", Name.Builtin)
  1130. ],
  1131. 'css-single-end': [
  1132. include('css-base'),
  1133. (r"'", String.Single, '#pop:2'),
  1134. (r"[^;']+", Name.Entity)
  1135. ],
  1136. 'css-double-end': [
  1137. include('css-base'),
  1138. (r'"', String.Single, '#pop:2'),
  1139. (r'[^;"]+', Name.Entity)
  1140. ],
  1141. 'string-single-pop2': [
  1142. (r"'", String.Single, '#pop:2'),
  1143. include('string-base')
  1144. ],
  1145. 'string-double-pop2': [
  1146. (r'"', String.Single, '#pop:2'),
  1147. include('string-base')
  1148. ],
  1149. }
  1150. class EarlGreyLexer(RegexLexer):
  1151. """
  1152. For `Earl-Grey`_ source code.
  1153. .. _Earl-Grey: https://breuleux.github.io/earl-grey/
  1154. .. versionadded: 2.1
  1155. """
  1156. name = 'Earl Grey'
  1157. aliases = ['earl-grey', 'earlgrey', 'eg']
  1158. filenames = ['*.eg']
  1159. mimetypes = ['text/x-earl-grey']
  1160. tokens = {
  1161. 'root': [
  1162. (r'\n', Text),
  1163. include('control'),
  1164. (r'[^\S\n]+', Text),
  1165. (r';;.*\n', Comment),
  1166. (r'[\[\]{}:(),;]', Punctuation),
  1167. (r'\\\n', Text),
  1168. (r'\\', Text),
  1169. include('errors'),
  1170. (words((
  1171. 'with', 'where', 'when', 'and', 'not', 'or', 'in',
  1172. 'as', 'of', 'is'),
  1173. prefix=r'(?<=\s|\[)', suffix=r'(?![\w$\-])'),
  1174. Operator.Word),
  1175. (r'[*@]?->', Name.Function),
  1176. (r'[+\-*/~^<>%&|?!@#.]*=', Operator.Word),
  1177. (r'\.{2,3}', Operator.Word), # Range Operator
  1178. (r'([+*/~^<>&|?!]+)|([#\-](?=\s))|@@+(?=\s)|=+', Operator),
  1179. (r'(?<![\w$\-])(var|let)(?:[^\w$])', Keyword.Declaration),
  1180. include('keywords'),
  1181. include('builtins'),
  1182. include('assignment'),
  1183. (r'''(?x)
  1184. (?:()([a-zA-Z$_](?:[\w$\-]*[\w$])?)|
  1185. (?<=[\s{\[(])(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?))
  1186. (?=.*%)''',
  1187. bygroups(Punctuation, Name.Tag, Punctuation, Name.Class.Start), 'dbs'),
  1188. (r'[rR]?`', String.Backtick, 'bt'),
  1189. (r'[rR]?```', String.Backtick, 'tbt'),
  1190. (r'(?<=[\s\[{(,;])\.([a-zA-Z$_](?:[\w$\-]*[\w$])?)'
  1191. r'(?=[\s\]}),;])', String.Symbol),
  1192. include('nested'),
  1193. (r'(?:[rR]|[rR]\.[gmi]{1,3})?"', String, combined('stringescape', 'dqs')),
  1194. (r'(?:[rR]|[rR]\.[gmi]{1,3})?\'', String, combined('stringescape', 'sqs')),
  1195. (r'"""', String, combined('stringescape', 'tdqs')),
  1196. include('tuple'),
  1197. include('import_paths'),
  1198. include('name'),
  1199. include('numbers'),
  1200. ],
  1201. 'dbs': [
  1202. (r'(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?)(?=[.\[\s])',
  1203. bygroups(Punctuation, Name.Class.DBS)),
  1204. (r'(\[)([\^#][a-zA-Z$_](?:[\w$\-]*[\w$])?)(\])',
  1205. bygroups(Punctuation, Name.Entity.DBS, Punctuation)),
  1206. (r'\s+', Text),
  1207. (r'%', Operator.DBS, '#pop'),
  1208. ],
  1209. 'import_paths': [
  1210. (r'(?<=[\s:;,])(\.{1,3}(?:[\w\-]*/)*)(\w(?:[\w\-]*\w)*)(?=[\s;,])',
  1211. bygroups(Text.Whitespace, Text)),
  1212. ],
  1213. 'assignment': [
  1214. (r'(\.)?([a-zA-Z$_](?:[\w$\-]*[\w$])?)'
  1215. r'(?=\s+[+\-*/~^<>%&|?!@#.]*\=\s)',
  1216. bygroups(Punctuation, Name.Variable))
  1217. ],
  1218. 'errors': [
  1219. (words(('Error', 'TypeError', 'ReferenceError'),
  1220. prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'),
  1221. Name.Exception),
  1222. (r'''(?x)
  1223. (?<![\w$])
  1224. E\.[\w$](?:[\w$\-]*[\w$])?
  1225. (?:\.[\w$](?:[\w$\-]*[\w$])?)*
  1226. (?=[({\[?!\s])''',
  1227. Name.Exception),
  1228. ],
  1229. 'control': [
  1230. (r'''(?x)
  1231. ([a-zA-Z$_](?:[\w$-]*[\w$])?)
  1232. (?!\n)\s+
  1233. (?!and|as|each\*|each|in|is|mod|of|or|when|where|with)
  1234. (?=(?:[+\-*/~^<>%&|?!@#.])?[a-zA-Z$_](?:[\w$-]*[\w$])?)''',
  1235. Keyword.Control),
  1236. (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(?!\n)\s+(?=[\'"\d{\[(])',
  1237. Keyword.Control),
  1238. (r'''(?x)
  1239. (?:
  1240. (?<=[%=])|
  1241. (?<=[=\-]>)|
  1242. (?<=with|each|with)|
  1243. (?<=each\*|where)
  1244. )(\s+)
  1245. ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''',
  1246. bygroups(Text, Keyword.Control, Punctuation)),
  1247. (r'''(?x)
  1248. (?<![+\-*/~^<>%&|?!@#.])(\s+)
  1249. ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''',
  1250. bygroups(Text, Keyword.Control, Punctuation)),
  1251. ],
  1252. 'nested': [
  1253. (r'''(?x)
  1254. (?<=[\w$\]})])(\.)
  1255. ([a-zA-Z$_](?:[\w$-]*[\w$])?)
  1256. (?=\s+with(?:\s|\n))''',
  1257. bygroups(Punctuation, Name.Function)),
  1258. (r'''(?x)
  1259. (?<!\s)(\.)
  1260. ([a-zA-Z$_](?:[\w$-]*[\w$])?)
  1261. (?=[}\]).,;:\s])''',
  1262. bygroups(Punctuation, Name.Field)),
  1263. (r'''(?x)
  1264. (?<=[\w$\]})])(\.)
  1265. ([a-zA-Z$_](?:[\w$-]*[\w$])?)
  1266. (?=[\[{(:])''',
  1267. bygroups(Punctuation, Name.Function)),
  1268. ],
  1269. 'keywords': [
  1270. (words((
  1271. 'each', 'each*', 'mod', 'await', 'break', 'chain',
  1272. 'continue', 'elif', 'expr-value', 'if', 'match',
  1273. 'return', 'yield', 'pass', 'else', 'require', 'var',
  1274. 'let', 'async', 'method', 'gen'),
  1275. prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'),
  1276. Keyword.Pseudo),
  1277. (words(('this', 'self', '@'),
  1278. prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'),
  1279. Keyword.Constant),
  1280. (words((
  1281. 'Function', 'Object', 'Array', 'String', 'Number',
  1282. 'Boolean', 'ErrorFactory', 'ENode', 'Promise'),
  1283. prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'),
  1284. Keyword.Type),
  1285. ],
  1286. 'builtins': [
  1287. (words((
  1288. 'send', 'object', 'keys', 'items', 'enumerate', 'zip',
  1289. 'product', 'neighbours', 'predicate', 'equal',
  1290. 'nequal', 'contains', 'repr', 'clone', 'range',
  1291. 'getChecker', 'get-checker', 'getProperty', 'get-property',
  1292. 'getProjector', 'get-projector', 'consume', 'take',
  1293. 'promisify', 'spawn', 'constructor'),
  1294. prefix=r'(?<![\w\-#.])', suffix=r'(?![\w\-.])'),
  1295. Name.Builtin),
  1296. (words((
  1297. 'true', 'false', 'null', 'undefined'),
  1298. prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'),
  1299. Name.Constant),
  1300. ],
  1301. 'name': [
  1302. (r'@([a-zA-Z$_](?:[\w$-]*[\w$])?)', Name.Variable.Instance),
  1303. (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(\+\+|\-\-)?',
  1304. bygroups(Name.Symbol, Operator.Word))
  1305. ],
  1306. 'tuple': [
  1307. (r'#[a-zA-Z_][\w\-]*(?=[\s{(,;])', Name.Namespace)
  1308. ],
  1309. 'interpoling_string': [
  1310. (r'\}', String.Interpol, '#pop'),
  1311. include('root')
  1312. ],
  1313. 'stringescape': [
  1314. (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|'
  1315. r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
  1316. ],
  1317. 'strings': [
  1318. (r'[^\\\'"]', String),
  1319. (r'[\'"\\]', String),
  1320. (r'\n', String) # All strings are multiline in EG
  1321. ],
  1322. 'dqs': [
  1323. (r'"', String, '#pop'),
  1324. (r'\\\\|\\"|\\\n', String.Escape),
  1325. include('strings')
  1326. ],
  1327. 'sqs': [
  1328. (r"'", String, '#pop'),
  1329. (r"\\\\|\\'|\\\n", String.Escape),
  1330. (r'\{', String.Interpol, 'interpoling_string'),
  1331. include('strings')
  1332. ],
  1333. 'tdqs': [
  1334. (r'"""', String, '#pop'),
  1335. include('strings'),
  1336. ],
  1337. 'bt': [
  1338. (r'`', String.Backtick, '#pop'),
  1339. (r'(?<!`)\n', String.Backtick),
  1340. (r'\^=?', String.Escape),
  1341. (r'.+', String.Backtick),
  1342. ],
  1343. 'tbt': [
  1344. (r'```', String.Backtick, '#pop'),
  1345. (r'\n', String.Backtick),
  1346. (r'\^=?', String.Escape),
  1347. (r'[^`]+', String.Backtick),
  1348. ],
  1349. 'numbers': [
  1350. (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float),
  1351. (r'\d+[eE][+-]?[0-9]+', Number.Float),
  1352. (r'8r[0-7]+', Number.Oct),
  1353. (r'2r[01]+', Number.Bin),
  1354. (r'16r[a-fA-F0-9]+', Number.Hex),
  1355. (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?',
  1356. Number.Radix),
  1357. (r'\d+', Number.Integer)
  1358. ],
  1359. }
  1360. class JuttleLexer(RegexLexer):
  1361. """
  1362. For `Juttle`_ source code.
  1363. .. _Juttle: https://github.com/juttle/juttle
  1364. .. versionadded:: 2.2
  1365. """
  1366. name = 'Juttle'
  1367. aliases = ['juttle', 'juttle']
  1368. filenames = ['*.juttle']
  1369. mimetypes = ['application/juttle', 'application/x-juttle',
  1370. 'text/x-juttle', 'text/juttle']
  1371. flags = re.DOTALL | re.UNICODE | re.MULTILINE
  1372. tokens = {
  1373. 'commentsandwhitespace': [
  1374. (r'\s+', Text),
  1375. (r'//.*?\n', Comment.Single),
  1376. (r'/\*.*?\*/', Comment.Multiline)
  1377. ],
  1378. 'slashstartsregex': [
  1379. include('commentsandwhitespace'),
  1380. (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  1381. r'([gim]+\b|\B)', String.Regex, '#pop'),
  1382. (r'(?=/)', Text, ('#pop', 'badregex')),
  1383. default('#pop')
  1384. ],
  1385. 'badregex': [
  1386. (r'\n', Text, '#pop')
  1387. ],
  1388. 'root': [
  1389. (r'^(?=\s|/)', Text, 'slashstartsregex'),
  1390. include('commentsandwhitespace'),
  1391. (r':\d{2}:\d{2}:\d{2}(\.\d*)?:', String.Moment),
  1392. (r':(now|beginning|end|forever|yesterday|today|tomorrow|'
  1393. r'(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment),
  1394. (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?'
  1395. r'(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment),
  1396. (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|'
  1397. r'day|week|month|year)[s]?'
  1398. r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|'
  1399. r'day|week|month|year)[s]?)'
  1400. r'|[ ]+(ago|from[ ]+now))*:', String.Moment),
  1401. (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
  1402. r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
  1403. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  1404. (r'[})\].]', Punctuation),
  1405. (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'),
  1406. (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration,
  1407. 'slashstartsregex'),
  1408. (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|'
  1409. r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b',
  1410. Keyword.Reserved),
  1411. (r'(true|false|null|Infinity)\b', Keyword.Constant),
  1412. (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b',
  1413. Name.Builtin),
  1414. (JS_IDENT, Name.Other),
  1415. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  1416. (r'[0-9]+', Number.Integer),
  1417. (r'"(\\\\|\\"|[^"])*"', String.Double),
  1418. (r"'(\\\\|\\'|[^'])*'", String.Single)
  1419. ]
  1420. }