jsdoc.cson 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. 'scopeName': 'source.jsdoc'
  2. 'name': 'JSDoc'
  3. 'patterns': [
  4. {
  5. # @access private|protected|public
  6. 'captures':
  7. '1':
  8. 'name': 'storage.type.class.jsdoc'
  9. '2':
  10. 'name': 'punctuation.definition.block.tag.jsdoc'
  11. '3':
  12. 'name': 'constant.language.access-type.jsdoc'
  13. 'match': '''(?x)
  14. ((@)(?:access|api))
  15. \\s+
  16. (private|protected|public)
  17. \\b
  18. '''
  19. }
  20. {
  21. # @author name [<email>]
  22. 'match': '''(?x)
  23. ((@)author)
  24. \\s+
  25. (
  26. [^@\\s<>*/]
  27. (?:[^@<>*/]|\\*[^/])*
  28. )
  29. (?:
  30. \\s*
  31. (<)
  32. ([^>\\s]+)
  33. (>)
  34. )?
  35. '''
  36. 'captures':
  37. '1':
  38. 'name': 'storage.type.class.jsdoc'
  39. '2':
  40. 'name': 'punctuation.definition.block.tag.jsdoc'
  41. '3':
  42. 'name': 'entity.name.type.instance.jsdoc'
  43. '4':
  44. 'name': 'punctuation.definition.bracket.angle.begin.jsdoc'
  45. '5':
  46. 'name': 'constant.other.email.link.underline.jsdoc'
  47. '6':
  48. 'name': 'punctuation.definition.bracket.angle.end.jsdoc'
  49. }
  50. {
  51. # @borrows <that namepath> as <this namepath>
  52. 'match': '''(?x)
  53. ((@)borrows) \\s+
  54. ((?:[^@\\s*/]|\\*[^/])+) # <that namepath>
  55. \\s+ (as) \\s+ # as
  56. ((?:[^@\\s*/]|\\*[^/])+) # <this namepath>
  57. '''
  58. 'captures':
  59. '1':
  60. 'name': 'storage.type.class.jsdoc'
  61. '2':
  62. 'name': 'punctuation.definition.block.tag.jsdoc'
  63. '3':
  64. 'name': 'entity.name.type.instance.jsdoc'
  65. '4':
  66. 'name': 'keyword.operator.control.jsdoc'
  67. '5':
  68. 'name': 'entity.name.type.instance.jsdoc'
  69. }
  70. {
  71. # @example text();
  72. 'name': 'meta.example.jsdoc'
  73. 'begin': '((@)example)\\s+'
  74. 'end': '(?=@|\\*/)'
  75. 'beginCaptures':
  76. '1':
  77. 'name': 'storage.type.class.jsdoc'
  78. '2':
  79. 'name': 'punctuation.definition.block.tag.jsdoc'
  80. 'patterns': [
  81. {
  82. # Match to prevent leading asterisk being highlighted as JS
  83. 'match': '^\\s\\*\\s+'
  84. }
  85. {
  86. # Leading <caption>…</caption> before example
  87. 'begin': '\\G(<)caption(>)'
  88. 'beginCaptures':
  89. '0':
  90. 'name': 'entity.name.tag.inline.jsdoc'
  91. '1':
  92. 'name': 'punctuation.definition.bracket.angle.begin.jsdoc'
  93. '2':
  94. 'name': 'punctuation.definition.bracket.angle.end.jsdoc'
  95. 'contentName': 'constant.other.description.jsdoc'
  96. 'end': '(</)caption(>)|(?=\\*/)'
  97. 'endCaptures':
  98. '0':
  99. 'name': 'entity.name.tag.inline.jsdoc'
  100. '1':
  101. 'name': 'punctuation.definition.bracket.angle.begin.jsdoc'
  102. '2':
  103. 'name': 'punctuation.definition.bracket.angle.end.jsdoc'
  104. }
  105. {
  106. # Highlighted JavaScript example
  107. 'match': '[^\\s@*](?:[^*]|\\*[^/])*'
  108. 'captures':
  109. '0':
  110. 'name': 'source.embedded.js'
  111. 'patterns': [
  112. {
  113. 'include': 'source.js'
  114. }
  115. ]
  116. }
  117. ]
  118. }
  119. {
  120. # @kind type
  121. 'captures':
  122. '1':
  123. 'name': 'storage.type.class.jsdoc'
  124. '2':
  125. 'name': 'punctuation.definition.block.tag.jsdoc'
  126. '3':
  127. 'name': 'constant.language.symbol-type.jsdoc'
  128. 'match': '''(?x)
  129. ((@)kind)
  130. \\s+
  131. (class|constant|event|external|file|function|member|mixin|module|namespace|typedef)
  132. \\b
  133. '''
  134. }
  135. {
  136. # @see namepathOrURL
  137. 'captures':
  138. '1':
  139. 'name': 'storage.type.class.jsdoc'
  140. '2':
  141. 'name': 'punctuation.definition.block.tag.jsdoc'
  142. '3':
  143. 'name': 'variable.other.link.underline.jsdoc'
  144. '4':
  145. 'name': 'entity.name.type.instance.jsdoc'
  146. 'match': '''(?x)
  147. ((@)see)
  148. \\s+
  149. (?:
  150. # URL
  151. (
  152. (?=https?://)
  153. (?:[^\\s*]|\\*[^/])+
  154. )
  155. |
  156. # JSDoc namepath
  157. (
  158. (?!
  159. # Avoid matching bare URIs (also acceptable as links)
  160. https?://
  161. |
  162. # Avoid matching {@inline tags}; we match those below
  163. (?:\\[[^\\[\\]]*\\])? # Possible description [preceding]{@tag}
  164. {@(?:link|linkcode|linkplain|tutorial)\\b
  165. )
  166. # Matched namepath
  167. (?:[^@\\s*/]|\\*[^/])+
  168. )
  169. )
  170. '''
  171. }
  172. {
  173. # @template Foo,Bar
  174. 'captures':
  175. '1':
  176. 'name': 'storage.type.class.jsdoc'
  177. '2':
  178. 'name': 'punctuation.definition.block.tag.jsdoc'
  179. '3':
  180. 'name': 'variable.other.jsdoc'
  181. 'patterns': [
  182. {
  183. 'match': ','
  184. 'name': 'punctuation.delimiter.object.comma.jsdoc'
  185. }
  186. ]
  187. 'match': '''(?x)
  188. ((@)template)
  189. \\s+
  190. # One or more valid identifiers
  191. (
  192. [A-Za-z_$] # First character: non-numeric word character
  193. [\\w$.\\[\\]]* # Rest of identifier
  194. (?: # Possible list of additional identifiers
  195. \\s* , \\s*
  196. [A-Za-z_$]
  197. [\\w$.\\[\\]]*
  198. )*
  199. )
  200. '''
  201. }
  202. {
  203. # Tags followed by an identifier token
  204. # - @<tag> identifier
  205. 'captures':
  206. '1':
  207. 'name': 'storage.type.class.jsdoc'
  208. '2':
  209. 'name': 'punctuation.definition.block.tag.jsdoc'
  210. '3':
  211. 'name': 'variable.other.jsdoc'
  212. 'match': '''(?x)
  213. (
  214. (@)
  215. (?:arg|argument|const|constant|member|namespace|param|var)
  216. )
  217. \\s+
  218. (
  219. [A-Za-z_$]
  220. [\\w$.\\[\\]]*
  221. )
  222. '''
  223. }
  224. {
  225. # Tags followed by a type expression, then a namepath
  226. # - @<tag> {type} namepath
  227. 'begin': '((@)typedef)\\s+(?={)'
  228. 'beginCaptures':
  229. '1':
  230. 'name': 'storage.type.class.jsdoc'
  231. '2':
  232. 'name': 'punctuation.definition.block.tag.jsdoc'
  233. 'end': '(?=\\s|\\*/|[^{}\\[\\]A-Za-z_$])'
  234. 'patterns': [
  235. {
  236. 'include': '#type'
  237. }
  238. {
  239. 'name': 'entity.name.type.instance.jsdoc'
  240. 'match': '(?:[^@\\s*/]|\\*[^/])+'
  241. }
  242. ]
  243. }
  244. {
  245. # Tags followed by a type expression, then an identifier
  246. # - @<tag> {type} identifier
  247. 'begin': '((@)(?:arg|argument|const|constant|member|namespace|param|prop|property|var))\\s+(?={)'
  248. 'beginCaptures':
  249. '1':
  250. 'name': 'storage.type.class.jsdoc'
  251. '2':
  252. 'name': 'punctuation.definition.block.tag.jsdoc'
  253. 'end': '(?=\\s|\\*/|[^{}\\[\\]A-Za-z_$])'
  254. 'patterns': [
  255. {
  256. 'include': '#type'
  257. }
  258. {
  259. 'match': '([A-Za-z_$][\\w$.\\[\\]]*)'
  260. 'name': 'variable.other.jsdoc'
  261. }
  262. {
  263. # Optional value
  264. 'name': 'variable.other.jsdoc'
  265. 'match': '''(?x)
  266. (\\[)\\s*
  267. [\\w$]+
  268. (?:
  269. (?:\\[\\])? # Foo[].bar properties within an array
  270. \\. # Foo.Bar namespaced parameter
  271. [\\w$]+
  272. )*
  273. (?:
  274. \\s*
  275. (=) # [foo=bar] Default parameter value
  276. \\s*
  277. (
  278. # The inner regexes are to stop the match early at */ and to not stop at escaped quotes
  279. (?>
  280. "(?:(?:\\*(?!/))|(?:\\\\(?!"))|[^*\\\\])*?" | # [foo="bar"] Double-quoted
  281. '(?:(?:\\*(?!/))|(?:\\\\(?!'))|[^*\\\\])*?' | # [foo='bar'] Single-quoted
  282. \\[ (?:(?:\\*(?!/))|[^*])*? \\] | # [foo=[1,2]] Array literal
  283. (?:(?:\\*(?!/))|\\s(?!\\s*\\])|\\[.*?(?:\\]|(?=\\*/))|[^*\\s\\[\\]])* # Everything else (sorry)
  284. )*
  285. )
  286. )?
  287. \\s*(?:(\\])((?:[^*\\s]|\\*[^\\s/])+)?|(?=\\*/))
  288. '''
  289. 'captures':
  290. '1':
  291. 'name': 'punctuation.definition.optional-value.begin.bracket.square.jsdoc'
  292. '2':
  293. 'name': 'keyword.operator.assignment.jsdoc'
  294. '3':
  295. 'name': 'source.embedded.js'
  296. 'patterns': [
  297. {
  298. 'include': '#inline-tags'
  299. }
  300. {
  301. 'include': 'source.js'
  302. }
  303. ]
  304. '4':
  305. 'name': 'punctuation.definition.optional-value.end.bracket.square.jsdoc'
  306. '5':
  307. 'name': 'invalid.illegal.syntax.jsdoc'
  308. }
  309. ]
  310. }
  311. {
  312. # Tags followed by a type expression
  313. # - @<tag> {type}
  314. 'begin': '''(?x)
  315. (
  316. (@)
  317. (?:define|enum|exception|export|extends|lends|implements|modifies
  318. |namespace|private|protected|returns?|suppress|this|throws|type
  319. |yields?)
  320. )
  321. \\s+(?={)
  322. '''
  323. 'beginCaptures':
  324. '1':
  325. 'name': 'storage.type.class.jsdoc'
  326. '2':
  327. 'name': 'punctuation.definition.block.tag.jsdoc'
  328. 'end': '(?=\\s|\\*/|[^{}\\[\\]A-Za-z_$])'
  329. 'patterns': [
  330. {
  331. 'include': '#type'
  332. }
  333. ]
  334. }
  335. {
  336. # Tags followed by a namepath
  337. # - @<tag> namepath
  338. 'captures':
  339. '1':
  340. 'name': 'storage.type.class.jsdoc'
  341. '2':
  342. 'name': 'punctuation.definition.block.tag.jsdoc'
  343. '3':
  344. 'name': 'entity.name.type.instance.jsdoc'
  345. 'match': '''(?x)
  346. (
  347. (@)
  348. (?:alias|augments|callback|constructs|emits|event|fires|exports?
  349. |extends|external|function|func|host|lends|listens|interface|memberof!?
  350. |method|module|mixes|mixin|name|requires|see|this|typedef|uses)
  351. )
  352. \\s+
  353. (
  354. (?:
  355. [^{}@\\s*] | \\*[^/]
  356. )+
  357. )
  358. '''
  359. }
  360. {
  361. # Tags followed by a quoted arbitrary value
  362. # - @<tag> "Quoted value"
  363. 'begin': '((@)(?:default(?:value)?|license|version))\\s+(([\'"]))'
  364. 'beginCaptures':
  365. '1':
  366. 'name': 'storage.type.class.jsdoc'
  367. '2':
  368. 'name': 'punctuation.definition.block.tag.jsdoc'
  369. '3':
  370. 'name': 'variable.other.jsdoc'
  371. '4':
  372. 'name': 'punctuation.definition.string.begin.jsdoc'
  373. 'contentName': 'variable.other.jsdoc'
  374. 'end': '(\\3)|(?=$|\\*/)'
  375. 'endCaptures':
  376. '0':
  377. 'name': 'variable.other.jsdoc'
  378. '1':
  379. 'name': 'punctuation.definition.string.end.jsdoc'
  380. }
  381. {
  382. # Tags followed by an arbitrary value
  383. # - @<tag> value
  384. 'captures':
  385. '1':
  386. 'name': 'storage.type.class.jsdoc'
  387. '2':
  388. 'name': 'punctuation.definition.block.tag.jsdoc'
  389. '3':
  390. 'name': 'variable.other.jsdoc'
  391. 'match': '((@)(?:default(?:value)?|license|tutorial|variation|version))\\s+([^\\s*]+)'
  392. }
  393. {
  394. # Tags without arguments, or a tag without expected arguments. Because JSDoc permits
  395. # tags to be spread across lines, we should at least highlight the opening tag for
  396. # stuff like this:
  397. #
  398. # /**
  399. # * @param
  400. # * {type}
  401. # * name
  402. 'captures':
  403. '1':
  404. 'name': 'punctuation.definition.block.tag.jsdoc'
  405. 'match': '''(?x) (@)
  406. (?:abstract|access|alias|api|arg|argument|async|attribute|augments|author|beta|borrows|bubbles
  407. |callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright
  408. |default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exception
  409. |exports?|extends|extension(?:_?for)?|external|externs|file|fileoverview|final|fires|for|func
  410. |function|generator|global|hideconstructor|host|ignore|implements|implicitCast|inherit[Dd]oc
  411. |inner|instance|interface|internal|kind|lends|license|listens|main|member|memberof!?|method
  412. |mixes|mixins?|modifies|module|name|namespace|noalias|nocollapse|nocompile|nosideeffects
  413. |override|overview|package|param|polymer(?:Behavior)?|preserve|private|prop|property|protected
  414. |public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule|summary
  415. |suppress|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation
  416. |version|virtual|writeOnce|yields?)
  417. \\b
  418. '''
  419. 'name': 'storage.type.class.jsdoc'
  420. }
  421. {
  422. 'include': '#inline-tags'
  423. }
  424. ]
  425. 'repository':
  426. # Balanced brackets (square or curly)
  427. 'brackets':
  428. 'patterns': [
  429. {
  430. 'begin': '{'
  431. 'end': '}|(?=\\*/)'
  432. 'patterns': [
  433. {
  434. 'include': '#brackets'
  435. }
  436. ]
  437. }
  438. {
  439. 'begin': '\\['
  440. 'end': '\\]|(?=\\*/)'
  441. 'patterns': [
  442. {
  443. 'include': '#brackets'
  444. }
  445. ]
  446. }
  447. ]
  448. 'inline-tags':
  449. 'patterns': [
  450. {
  451. # Description preceding {@inline tag}
  452. 'captures':
  453. '1':
  454. 'name': 'punctuation.definition.bracket.square.begin.jsdoc'
  455. '2':
  456. 'name': 'punctuation.definition.bracket.square.end.jsdoc'
  457. 'match': '(\\[)[^\\]]+(\\])(?={@(?:link|linkcode|linkplain|tutorial))'
  458. 'name': 'constant.other.description.jsdoc'
  459. }
  460. {
  461. # {@link|@tutorial …}
  462. 'begin': '({)((@)(?:link(?:code|plain)?|tutorial))\\s*'
  463. 'beginCaptures':
  464. '1':
  465. 'name': 'punctuation.definition.bracket.curly.begin.jsdoc'
  466. '2':
  467. 'name': 'storage.type.class.jsdoc'
  468. '3':
  469. 'name': 'punctuation.definition.inline.tag.jsdoc'
  470. 'end': '}|(?=\\*/)'
  471. 'endCaptures':
  472. '0':
  473. 'name': 'punctuation.definition.bracket.curly.end.jsdoc'
  474. 'name': 'entity.name.type.instance.jsdoc'
  475. 'patterns': [
  476. {
  477. 'captures':
  478. '1':
  479. 'name': 'variable.other.link.underline.jsdoc'
  480. '2':
  481. 'name': 'punctuation.separator.pipe.jsdoc'
  482. 'match': '\\G((?=https?://)(?:[^|}\\s*]|\\*[/])+)(\\|)?'
  483. }
  484. {
  485. 'captures':
  486. '1':
  487. 'name': 'variable.other.description.jsdoc'
  488. '2':
  489. 'name': 'punctuation.separator.pipe.jsdoc'
  490. 'match': '\\G((?:[^{}@\\s|*]|\\*[^/])+)(\\|)?'
  491. }
  492. ]
  493. }
  494. ]
  495. # {type}
  496. 'type':
  497. 'patterns': [
  498. {
  499. # {unclosed
  500. 'match': '\\G{(?:[^}*]|\\*[^/}])+$'
  501. 'name': 'invalid.illegal.type.jsdoc'
  502. }
  503. {
  504. 'begin': '\\G({)'
  505. 'beginCaptures':
  506. '0':
  507. 'name': 'entity.name.type.instance.jsdoc'
  508. '1':
  509. 'name': 'punctuation.definition.bracket.curly.begin.jsdoc'
  510. 'contentName': 'entity.name.type.instance.jsdoc'
  511. 'end': '((}))\\s*|(?=\\*/)'
  512. 'endCaptures':
  513. '1':
  514. 'name': 'entity.name.type.instance.jsdoc'
  515. '2':
  516. 'name': 'punctuation.definition.bracket.curly.end.jsdoc'
  517. 'patterns': [
  518. {
  519. 'include': '#brackets'
  520. }
  521. ]
  522. }
  523. ]