code.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. Rainbow.extend('html', [
  2. {
  3. 'name': 'source.php.embedded',
  4. 'matches': {
  5. 2: {
  6. 'language': 'php'
  7. }
  8. },
  9. 'pattern': /<\?=?(?!xml)(php)?([\s\S]*?)(\?>)/gm
  10. },
  11. {
  12. 'name': 'source.css.embedded',
  13. 'matches': {
  14. 1: {
  15. 'matches': {
  16. 1: 'support.tag.style',
  17. 2: [
  18. {
  19. 'name': 'entity.tag.style',
  20. 'pattern': /^style/g
  21. },
  22. {
  23. 'name': 'string',
  24. 'pattern': /('|")(.*?)(\1)/g
  25. },
  26. {
  27. 'name': 'entity.tag.style.attribute',
  28. 'pattern': /(\w+)/g
  29. }
  30. ],
  31. 3: 'support.tag.style'
  32. },
  33. 'pattern': /(<\/?)(style.*?)(>)/g
  34. },
  35. 2: {
  36. 'language': 'css'
  37. },
  38. 3: 'support.tag.style',
  39. 4: 'entity.tag.style',
  40. 5: 'support.tag.style'
  41. },
  42. 'pattern': /(<style.*?>)([\s\S]*?)(<\/)(style)(>)/gm
  43. },
  44. {
  45. 'name': 'source.js.embedded',
  46. 'matches': {
  47. 1: {
  48. 'matches': {
  49. 1: 'support.tag.script',
  50. 2: [
  51. {
  52. 'name': 'entity.tag.script',
  53. 'pattern': /^script/g
  54. },
  55. {
  56. 'name': 'string',
  57. 'pattern': /('|")(.*?)(\1)/g
  58. },
  59. {
  60. 'name': 'entity.tag.script.attribute',
  61. 'pattern': /(\w+)/g
  62. }
  63. ],
  64. 3: 'support.tag.script'
  65. },
  66. 'pattern': /(<\/?)(script.*?)(>)/g
  67. },
  68. 2: {
  69. 'language': 'javascript'
  70. },
  71. 3: 'support.tag.script',
  72. 4: 'entity.tag.script',
  73. 5: 'support.tag.script'
  74. },
  75. 'pattern': /(<script(?! src).*?>)([\s\S]*?)(<\/)(script)(>)/gm
  76. },
  77. {
  78. 'name': 'comment.html',
  79. 'pattern': /<\!--[\S\s]*?-->/g
  80. },
  81. {
  82. 'matches': {
  83. 1: 'support.tag.open',
  84. 2: 'support.tag.close'
  85. },
  86. 'pattern': /(<)|(\/?\??>)/g
  87. },
  88. {
  89. 'name': 'support.tag',
  90. 'matches': {
  91. 1: 'support.tag',
  92. 2: 'support.tag.special',
  93. 3: 'support.tag-name'
  94. },
  95. 'pattern': /(<\??)(\/|\!?)(\w+)/g
  96. },
  97. {
  98. 'matches': {
  99. 1: 'support.attribute'
  100. },
  101. 'pattern': /([a-z-]+)(?=\=)/gi
  102. },
  103. {
  104. 'matches': {
  105. 1: 'support.operator',
  106. 2: 'string.quote',
  107. 3: 'string.value',
  108. 4: 'string.quote'
  109. },
  110. 'pattern': /(=)('|")(.*?)(\2)/g
  111. },
  112. {
  113. 'matches': {
  114. 1: 'support.operator',
  115. 2: 'support.value'
  116. },
  117. 'pattern': /(=)([a-zA-Z\-0-9]*)\b/g
  118. },
  119. {
  120. 'matches': {
  121. 1: 'support.attribute'
  122. },
  123. 'pattern': /\s(\w+)(?=\s|>)(?![\s\S]*<)/g
  124. }
  125. ], true);
  126. Rainbow.extend('css', [
  127. {
  128. 'name': 'comment',
  129. 'pattern': /\/\*[\s\S]*?\*\//gm
  130. },
  131. {
  132. 'name': 'constant.hex-color',
  133. 'pattern': /#([a-f0-9]{3}|[a-f0-9]{6})(?=;|\s|,|\))/gi
  134. },
  135. {
  136. 'matches': {
  137. 1: 'constant.numeric',
  138. 2: 'keyword.unit'
  139. },
  140. 'pattern': /(\d+)(px|em|cm|s|%)?/g
  141. },
  142. {
  143. 'name': 'string',
  144. 'pattern': /('|")(.*?)\1/g
  145. },
  146. {
  147. 'name': 'support.css-property',
  148. 'matches': {
  149. 1: 'support.vendor-prefix'
  150. },
  151. 'pattern': /(-o-|-moz-|-webkit-|-ms-)?[\w-]+(?=\s?:)(?!.*\{)/g
  152. },
  153. {
  154. 'matches': {
  155. 1: [
  156. {
  157. 'name': 'entity.name.sass',
  158. 'pattern': /&/g
  159. },
  160. {
  161. 'name': 'direct-descendant',
  162. 'pattern': />/g
  163. },
  164. {
  165. 'name': 'entity.name.class',
  166. 'pattern': /\.[\w\-_]+/g
  167. },
  168. {
  169. 'name': 'entity.name.id',
  170. 'pattern': /\#[\w\-_]+/g
  171. },
  172. {
  173. 'name': 'entity.name.pseudo',
  174. 'pattern': /:[\w\-_]+/g
  175. },
  176. {
  177. 'name': 'entity.name.tag',
  178. 'pattern': /\w+/g
  179. }
  180. ]
  181. },
  182. 'pattern': /([\w\ ,\n:\.\#\&\;\-_]+)(?=.*\{)/g
  183. },
  184. {
  185. 'matches': {
  186. 2: 'support.vendor-prefix',
  187. 3: 'support.css-value'
  188. },
  189. 'pattern': /(:|,)\s*(-o-|-moz-|-webkit-|-ms-)?([a-zA-Z-]*)(?=\b)(?!.*\{)/g
  190. }
  191. ], true);
  192. Rainbow.extend('javascript', [
  193. /**
  194. * matches $. or $(
  195. */
  196. {
  197. 'name': 'selector',
  198. 'pattern': /(\s|^)\$(?=\.|\()/g
  199. },
  200. {
  201. 'name': 'support',
  202. 'pattern': /\b(window|document)\b/g
  203. },
  204. {
  205. 'matches': {
  206. 1: 'support.property'
  207. },
  208. 'pattern': /\.(length|node(Name|Value))\b/g
  209. },
  210. {
  211. 'matches': {
  212. 1: 'support.function'
  213. },
  214. 'pattern': /(setTimeout|setInterval)(?=\()/g
  215. },
  216. {
  217. 'matches': {
  218. 1: 'support.method'
  219. },
  220. 'pattern': /\.(getAttribute|push|getElementById|getElementsByClassName|log|setTimeout|setInterval)(?=\()/g
  221. },
  222. /**
  223. * matches any escaped characters inside of a js regex pattern
  224. *
  225. * @see https://github.com/ccampbell/rainbow/issues/22
  226. *
  227. * this was causing single line comments to fail so it now makes sure
  228. * the opening / is not directly followed by a *
  229. *
  230. * @todo check that there is valid regex in match group 1
  231. */
  232. {
  233. 'name': 'string.regexp',
  234. 'matches': {
  235. 1: 'string.regexp.open',
  236. 2: {
  237. 'name': 'constant.regexp.escape',
  238. 'pattern': /\\(.){1}/g
  239. },
  240. 3: 'string.regexp.close',
  241. 4: 'string.regexp.modifier'
  242. },
  243. 'pattern': /(\/)(?!\*)(.+)(\/)([igm]{0,3})/g
  244. },
  245. /**
  246. * matches runtime function declarations
  247. */
  248. {
  249. 'matches': {
  250. 1: 'storage',
  251. 3: 'entity.function'
  252. },
  253. 'pattern': /(var)?(\s|^)(\S*)(?=\s?=\s?function\()/g
  254. },
  255. /**
  256. * matches constructor call
  257. */
  258. {
  259. 'matches': {
  260. 1: 'keyword',
  261. 2: 'entity.function'
  262. },
  263. 'pattern': /(new)\s+(.*)(?=\()/g
  264. },
  265. /**
  266. * matches any function call in the style functionName: function()
  267. */
  268. {
  269. 'name': 'entity.function',
  270. 'pattern': /(\w+)(?=:\s{0,}function)/g
  271. }
  272. ]);
  273. Rainbow.extend('coffeescript', [
  274. {
  275. 'name': 'comment.block',
  276. 'pattern': /(\#{3})[\s\S]*\1/gm
  277. },
  278. {
  279. 'name': 'string.block',
  280. 'pattern': /('{3}|"{3})[\s\S]*\1/gm
  281. },
  282. /**
  283. * multiline regex with comments
  284. */
  285. {
  286. 'name': 'string.regex',
  287. 'matches': {
  288. 2: {
  289. 'name': 'comment',
  290. 'pattern': /\#(.*?)\n/g
  291. }
  292. },
  293. 'pattern': /(\/{3})([\s\S]*)\1/gm
  294. },
  295. {
  296. 'matches': {
  297. 1: 'keyword'
  298. },
  299. 'pattern': /\b(in|when|is|isnt|of|not|unless|until|super)(?=\b)/gi
  300. },
  301. {
  302. 'name': 'keyword.operator',
  303. 'pattern': /\?/g
  304. },
  305. {
  306. 'name': 'constant.language',
  307. 'pattern': /\b(undefined|yes|on|no|off)\b/g
  308. },
  309. {
  310. 'name': 'keyword.variable.coffee',
  311. 'pattern': /@(\w+)/gi
  312. },
  313. /**
  314. * reset global keywards from generic
  315. */
  316. {
  317. 'name': 'reset',
  318. 'pattern': /object|class|print/gi
  319. },
  320. /**
  321. * named function
  322. */
  323. {
  324. 'matches' : {
  325. 1: 'entity.name.function',
  326. 2: 'keyword.operator',
  327. 3: {
  328. 'name': 'function.argument.coffee',
  329. 'pattern': /([\@\w]+)/g
  330. },
  331. 4: 'keyword.function'
  332. },
  333. 'pattern': /(\w+)\s{0,}(=|:)\s{0,}\((.*?)((-|=)>)/gi
  334. },
  335. /**
  336. * anonymous function
  337. */
  338. {
  339. 'matches': {
  340. 1: {
  341. 'name': 'function.argument.coffee',
  342. 'pattern': /([\@\w]+)/g
  343. },
  344. 2: 'keyword.function'
  345. },
  346. 'pattern': /\s\((.*?)\)\s{0,}((-|=)>)/gi
  347. },
  348. /**
  349. * direct function no arguments
  350. */
  351. {
  352. 'matches' : {
  353. 1: 'entity.name.function',
  354. 2: 'keyword.operator',
  355. 3: 'keyword.function'
  356. },
  357. 'pattern': /(\w+)\s{0,}(=|:)\s{0,}((-|=)>)/gi
  358. },
  359. /**
  360. * class definitions
  361. */
  362. {
  363. 'matches': {
  364. 1: 'storage.class',
  365. 2: 'entity.name.class',
  366. 3: 'storage.modifier.extends',
  367. 4: 'entity.other.inherited-class'
  368. },
  369. 'pattern': /\b(class)\s(\w+)(\sextends\s)?([\w\\]*)?\b/g
  370. },
  371. /**
  372. * object instantiation
  373. */
  374. {
  375. 'matches': {
  376. 1: 'keyword.new',
  377. 2: {
  378. 'name': 'support.class',
  379. 'pattern': /\w+/g
  380. }
  381. },
  382. 'pattern': /\b(new)\s(.*?)(?=\s)/g
  383. }
  384. ]);
  385. Rainbow.extend('php', [
  386. {
  387. 'name': 'support',
  388. 'pattern': /\becho\b/g
  389. },
  390. {
  391. 'matches': {
  392. 1: 'variable.dollar-sign',
  393. 2: 'variable'
  394. },
  395. 'pattern': /(\$)(\w+)\b/g
  396. },
  397. {
  398. 'name': 'constant.language',
  399. 'pattern': /true|false|null/ig
  400. },
  401. {
  402. 'name': 'constant',
  403. 'pattern': /\b[A-Z0-9_]{2,}\b/g
  404. },
  405. {
  406. 'name': 'keyword.dot',
  407. 'pattern': /\./g
  408. },
  409. {
  410. 'name': 'keyword',
  411. 'pattern': /\b(die|end(for(each)?|switch|if)|case|require(_once)?|include(_once)?)(?=\(|\b)/g
  412. },
  413. {
  414. 'matches': {
  415. 1: 'keyword',
  416. 2: {
  417. 'name': 'support.class',
  418. 'pattern': /\w+/g
  419. }
  420. },
  421. 'pattern': /(instanceof)\s([^\$].*?)(\)|;)/g
  422. },
  423. /**
  424. * these are the top 50 most used PHP functions
  425. * found from running a script and checking the frequency of each function
  426. * over a bunch of popular PHP frameworks then combining the results
  427. */
  428. {
  429. 'matches': {
  430. 1: 'support.function'
  431. },
  432. 'pattern': /\b(array(_key_exists|_merge|_keys|_shift)?|isset|count|empty|unset|printf|is_(array|string|numeric|object)|sprintf|each|date|time|substr|pos|str(len|pos|tolower|_replace|totime)?|ord|trim|in_array|implode|end|preg_match|explode|fmod|define|link|list|get_class|serialize|file|sort|mail|dir|idate|log|intval|header|chr|function_exists|dirname|preg_replace|file_exists)(?=\()/g
  433. },
  434. {
  435. 'name': 'variable.language.php-tag',
  436. 'pattern': /(<\?(php)?|\?>)/g
  437. },
  438. {
  439. 'matches': {
  440. 1: 'keyword.namespace',
  441. 2: {
  442. 'name': 'support.namespace',
  443. 'pattern': /\w+/g
  444. }
  445. },
  446. 'pattern': /\b(namespace|use)\s(.*?);/g
  447. },
  448. {
  449. 'matches': {
  450. 1: 'storage.modifier',
  451. 2: 'storage.class',
  452. 3: 'entity.name.class',
  453. 4: 'storage.modifier.extends',
  454. 5: 'entity.other.inherited-class',
  455. 6: 'storage.modifier.extends',
  456. 7: 'entity.other.inherited-class'
  457. },
  458. 'pattern': /\b(abstract|final)?\s?(class|interface|trait)\s(\w+)(\sextends\s)?([\w\\]*)?(\simplements\s)?([\w\\]*)?\s?\{?(\n|\})/g
  459. },
  460. {
  461. 'name': 'keyword.static',
  462. 'pattern': /self::|static::/g
  463. },
  464. {
  465. 'matches': {
  466. 1: 'storage.function',
  467. 2: 'support.magic'
  468. },
  469. 'pattern': /(function)\s(__.*?)(?=\()/g
  470. },
  471. {
  472. 'matches': {
  473. 1: 'keyword.new',
  474. 2: {
  475. 'name': 'support.class',
  476. 'pattern': /\w+/g
  477. }
  478. },
  479. 'pattern': /\b(new)\s([^\$].*?)(?=\)|\(|;)/g
  480. },
  481. {
  482. 'matches': {
  483. 1: {
  484. 'name': 'support.class',
  485. 'pattern': /\w+/g
  486. },
  487. 2: 'keyword.static'
  488. },
  489. 'pattern': /([\w\\]*?)(::)(?=\b|\$)/g
  490. },
  491. {
  492. 'matches': {
  493. 2: {
  494. 'name': 'support.class',
  495. 'pattern': /\w+/g
  496. }
  497. },
  498. 'pattern': /(\(|,\s?)([\w\\]*?)(?=\s\$)/g
  499. }
  500. ]);
  501. Rainbow.extend('ruby', [
  502. /**
  503. * __END__ DATA
  504. */
  505. {
  506. 'matches': {
  507. 1: 'variable.language',
  508. 2: {
  509. 'language': null
  510. }
  511. },
  512. //find __END__ and consume remaining text
  513. 'pattern': /^(__END__)\n((?:.*\n)*)/gm
  514. },
  515. /**
  516. * Strings
  517. * 1. No support for multi-line strings
  518. */
  519. {
  520. 'name': 'string',
  521. 'matches': {
  522. 1: 'string.open',
  523. 2: [{
  524. 'name': 'string.interpolation',
  525. 'matches': {
  526. 1: 'string.open',
  527. 2: {
  528. 'language': 'ruby'
  529. },
  530. 3: 'string.close'
  531. },
  532. 'pattern': /(\#\{)(.*?)(\})/g
  533. }],
  534. 3: 'string.close'
  535. },
  536. 'pattern': /("|`)(.*?[^\\\1])?(\1)/g
  537. },
  538. {
  539. 'name': 'string',
  540. 'pattern': /('|"|`)([^\\\1\n]|\\.)*?\1/g
  541. },
  542. {
  543. 'name': 'string',
  544. 'pattern': /%[qQ](?=(\(|\[|\{|<|.)(.*?)(?:'|\)|\]|\}|>|\1))(?:\(\2\)|\[\2\]|\{\2\}|\<\2>|\1\2\1)/g
  545. },
  546. /**
  547. * Heredocs
  548. * Heredocs of the form `<<'HTML' ... HTML` are unsupported.
  549. */
  550. {
  551. 'matches': {
  552. 1: 'string',
  553. 2: 'string',
  554. 3: 'string'
  555. },
  556. 'pattern': /(&lt;&lt;)(\w+).*?$([\s\S]*?^\2)/gm
  557. },
  558. {
  559. 'matches': {
  560. 1: 'string',
  561. 2: 'string',
  562. 3: 'string'
  563. },
  564. 'pattern': /(&lt;&lt;\-)(\w+).*?$([\s\S]*?\2)/gm
  565. },
  566. /**
  567. * Regular expressions
  568. * Escaped delimiter (`/\//`) is unsupported.
  569. */
  570. {
  571. 'name': 'string.regexp',
  572. 'matches': {
  573. 1: 'string.regexp',
  574. 2: {
  575. 'name': 'string.regexp',
  576. 'pattern': /\\(.){1}/g
  577. },
  578. 3: 'string.regexp',
  579. 4: 'string.regexp'
  580. },
  581. 'pattern': /(\/)(.*?)(\/)([a-z]*)/g
  582. },
  583. {
  584. 'name': 'string.regexp',
  585. 'matches': {
  586. 1: 'string.regexp',
  587. 2: {
  588. 'name': 'string.regexp',
  589. 'pattern': /\\(.){1}/g
  590. },
  591. 3: 'string.regexp',
  592. 4: 'string.regexp'
  593. },
  594. 'pattern': /%r(?=(\(|\[|\{|&lt;|.)(.*?)('|\)|\]|\}|&gt;|\1))(?:\(\2\)|\[\2\]|\{\2\}|\&lt;\2&gt;|\1\2\1)([a-z]*)/g
  595. },
  596. /**
  597. * Comments
  598. */
  599. {
  600. 'name': 'comment',
  601. 'pattern': /#.*$/gm
  602. },
  603. {
  604. 'name': 'comment',
  605. 'pattern': /^\=begin[\s\S]*?\=end$/gm
  606. },
  607. /**
  608. * Symbols
  609. */
  610. {
  611. 'matches': {
  612. 1: 'constant'
  613. },
  614. 'pattern': /(\w+:)[^:]/g
  615. },
  616. {
  617. 'matches': {
  618. 1: 'constant.symbol'
  619. },
  620. 'pattern': /[^:](:(?:\w+|(?=['"](.*?)['"])(?:"\2"|'\2')))/g
  621. },
  622. {
  623. 'name': 'constant.numeric',
  624. 'pattern': /\b(0x[\da-f]+|\d+)\b/g
  625. },
  626. {
  627. 'name': 'support.class',
  628. 'pattern': /\b[A-Z]\w*(?=((\.|::)[A-Za-z]|\[))/g
  629. },
  630. {
  631. 'name': 'constant',
  632. 'pattern': /\b[A-Z]\w*\b/g
  633. },
  634. /**
  635. * Keywords, variables, constants, and operators
  636. * In Ruby some keywords are valid method names, e.g., MyClass#yield
  637. * Don't mark those instances as "keywords"
  638. */
  639. {
  640. 'matches': {
  641. 1: 'storage.class',
  642. 2: 'entity.name.class',
  643. 3: 'entity.other.inherited-class'
  644. },
  645. 'pattern': /\s*(class)\s+((?:(?:::)?[A-Z]\w*)+)(?:\s+&lt;\s+((?:(?:::)?[A-Z]\w*)+))?/g
  646. },
  647. {
  648. 'matches': {
  649. 1: 'storage.module',
  650. 2: 'entity.name.class'
  651. },
  652. 'pattern': /\s*(module)\s+((?:(?:::)?[A-Z]\w*)+)/g
  653. },
  654. {
  655. 'name': 'variable.global',
  656. 'pattern': /\$([a-zA-Z_]\w*)\b/g
  657. },
  658. {
  659. 'name': 'variable.class',
  660. 'pattern': /@@([a-zA-Z_]\w*)\b/g
  661. },
  662. {
  663. 'name': 'variable.instance',
  664. 'pattern': /@([a-zA-Z_]\w*)\b/g
  665. },
  666. {
  667. 'matches': {
  668. 1: 'keyword.control'
  669. },
  670. 'pattern': /[^\.]\b(BEGIN|begin|case|class|do|else|elsif|END|end|ensure|for|if|in|module|rescue|then|unless|until|when|while)\b(?![?!])/g
  671. },
  672. {
  673. 'matches': {
  674. 1: 'keyword.control.pseudo-method'
  675. },
  676. 'pattern': /[^\.]\b(alias|alias_method|break|next|redo|retry|return|super|undef|yield)\b(?![?!])|\bdefined\?|\bblock_given\?/g
  677. },
  678. {
  679. 'matches': {
  680. 1: 'constant.language'
  681. },
  682. 'pattern': /\b(nil|true|false)\b(?![?!])/g
  683. },
  684. {
  685. 'matches': {
  686. 1: 'variable.language'
  687. },
  688. 'pattern': /\b(__(FILE|LINE)__|self)\b(?![?!])/g
  689. },
  690. {
  691. 'matches': {
  692. 1: 'keyword.special-method'
  693. },
  694. 'pattern': /\b(require|gem|initialize|new|loop|include|extend|raise|attr_reader|attr_writer|attr_accessor|attr|catch|throw|private|module_function|public|protected)\b(?![?!])/g
  695. },
  696. {
  697. 'name': 'keyword.operator',
  698. 'pattern': /\s\?\s|=|&lt;&lt;|&lt;&lt;=|%=|&=|\*=|\*\*=|\+=|\-=|\^=|\|{1,2}=|&lt;&lt;|&lt;=&gt;|&lt;(?!&lt;|=)|&gt;(?!&lt;|=|&gt;)|&lt;=|&gt;=|===|==|=~|!=|!~|%|&amp;|\*\*|\*|\+|\-|\/|\||~|&gt;&gt;/g
  699. },
  700. {
  701. 'matches': {
  702. 1: 'keyword.operator.logical'
  703. },
  704. 'pattern': /[^\.]\b(and|not|or)\b/g
  705. },
  706. /**
  707. * Functions
  708. * 1. No support for marking function parameters
  709. */
  710. {
  711. 'matches': {
  712. 1: 'storage.function',
  713. 2: 'entity.name.function'
  714. },
  715. 'pattern': /(def)\s(.*?)(?=(\s|\())/g
  716. }
  717. ], true);
  718. Rainbow.extend('go', [
  719. {
  720. 'matches': {
  721. 1: {
  722. 'name': 'keyword.operator',
  723. 'pattern': /\=/g
  724. },
  725. 2: {
  726. 'name': 'string',
  727. 'matches': {
  728. 'name': 'constant.character.escape',
  729. 'pattern': /\\(`|"){1}/g
  730. }
  731. }
  732. },
  733. 'pattern': /(\(|\s|\[|\=|:)((`|")([^\\\1]|\\.)*?(\3))/gm
  734. },
  735. {
  736. 'name': 'comment',
  737. 'pattern': /\/\*[\s\S]*?\*\/|(\/\/)[\s\S]*?$/gm
  738. },
  739. {
  740. 'name': 'constant.numeric',
  741. 'pattern': /\b(\d+(\.\d+)?(e(\+|\-)?\d+)?(f|d)?|0x[\da-f]+)\b/gi
  742. },
  743. {
  744. 'matches': {
  745. 1: 'keyword'
  746. },
  747. 'pattern': /\b(break|c(ase|onst|ontinue)|d(efault|efer)|else|fallthrough|for|go(to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)(?=\(|\b)/gi
  748. },
  749. {
  750. 'name': 'constant.language',
  751. 'pattern': /true|false|null|string|byte|rune|u?int(8|16|32|64)?|float(32|64)|complex(64|128)/g
  752. },
  753. {
  754. 'name': 'keyword.operator',
  755. 'pattern': /\+|\!|\-|&(gt|lt|amp);|\||\*|\:?=/g
  756. },
  757. {
  758. 'matches': {
  759. 1: 'function.call'
  760. },
  761. 'pattern': /(\w+?)(?=\()/g
  762. },
  763. {
  764. 'matches': {
  765. 1: 'storage.function',
  766. 2: 'entity.name.function'
  767. },
  768. 'pattern': /(func)\s(.*?)(?=\()/g
  769. }
  770. ]);