You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

500 lines
16KB

  1. %YAML 1.2
  2. ---
  3. # http://www.sublimetext.com/docs/3/syntax.html
  4. name: fsharp
  5. file_extensions:
  6. - fs
  7. scope: source.fsharp
  8. contexts:
  9. main:
  10. - include: compiler_directives
  11. - include: comments
  12. - include: constants
  13. - include: strings
  14. - include: chars
  15. - include: double_tick
  16. - include: definition
  17. - include: abstract_definition
  18. - include: attributes
  19. - include: modules
  20. - include: anonymous_functions
  21. - include: du_declaration
  22. - include: record_declaration
  23. - include: keywords
  24. - include: records
  25. - include: cexprs
  26. - include: text
  27. abstract_definition:
  28. - match: '\b(abstract)\s+(member)?(\s+\[\<.*\>\])?\s*([_[:alpha:]0-9,\._`\s]+)(:)'
  29. captures:
  30. 1: keyword.fsharp
  31. 2: keyword.fsharp
  32. 3: support.function.attribute.fsharp
  33. 5: keyword.fsharp
  34. push:
  35. - meta_scope: abstract.definition.fsharp
  36. - match: \s*(with)\b|=|$
  37. captures:
  38. 1: keyword.fsharp
  39. pop: true
  40. - include: comments
  41. - include: common_declaration
  42. - match: '\?{0,1}([[:alpha:]0-9''`^._ ]+)\s*(:)(\s*([?[:alpha:]0-9''`^._ ]+)){0,1}'
  43. captures:
  44. 1: variable.parameter.fsharp
  45. 2: keyword.symbol.fsharp
  46. 3: entity.name.type.fsharp
  47. - match: '(?!with|get|set\b)\b([\w0-9''`^._]+)'
  48. captures:
  49. 1: entity.name.type.fsharp
  50. - include: keywords
  51. anonymous_functions:
  52. - match: \b(fun)\b
  53. captures:
  54. 1: keyword.fsharp
  55. push:
  56. - meta_scope: function.anonymous
  57. - match: (->)
  58. captures:
  59. 1: keyword.fsharp
  60. pop: true
  61. - include: comments
  62. - include: member_declaration
  63. - match: '(:)(\s*([?[:alpha:]0-9''`<>^._ ]+))*'
  64. captures:
  65. 1: keyword.symbol.fsharp
  66. 2: entity.name.type.fsharp
  67. - include: variables
  68. attributes:
  69. - match: '\[\<'
  70. push:
  71. - meta_scope: support.function.attribute.fsharp
  72. - match: '\>\]|\]'
  73. pop: true
  74. - include: main
  75. cexprs:
  76. - match: '\b(async|seq|promise|task|maybe|asyncMaybe|controller|scope|application|pipeline)\s*\{'
  77. scope: cexpr.fsharp
  78. captures:
  79. 0: keyword.fsharp
  80. chars:
  81. - match: ('\\?.')
  82. scope: char.fsharp
  83. captures:
  84. 1: string.quoted.single.fsharp
  85. comments:
  86. - match: ^\s*(\(\*\*(?!\)))(?!\*\))$
  87. captures:
  88. 1: comment.block.fsharp
  89. push:
  90. - meta_scope: comment.block.markdown.fsharp
  91. - match: \*\)
  92. captures:
  93. 1: comment.block.fsharp
  94. pop: true
  95. - include: scope:text.html.markdown
  96. - match: ^(\s*\*\)$)
  97. scope: comment.block.markdown.fsharp.end
  98. captures:
  99. 1: comment.block.fsharp
  100. - match: (\(\*(?!\)))
  101. captures:
  102. 1: comment.block.fsharp
  103. push:
  104. - meta_scope: comment.block.fsharp
  105. - match: (\*\))
  106. captures:
  107. 1: comment.block.fsharp
  108. pop: true
  109. - match: ///
  110. push:
  111. - meta_scope: comment.line.markdown.fsharp
  112. - match: (\r)?\n
  113. pop: true
  114. - include: scope:text.html.markdown
  115. - match: //.*$
  116. scope: comment.line.double-slash.fsharp
  117. common_declaration:
  118. - match: '\s*(->)\s*([[:alpha:]0-9''`^._ ]+)(<)'
  119. captures:
  120. 1: keyword.symbol.fsharp
  121. 2: entity.name.type.fsharp
  122. 3: keyword.symbol.fsharp
  123. push:
  124. - match: (>)
  125. captures:
  126. 1: keyword.symbol.fsharp
  127. pop: true
  128. - match: "([[:alpha:]0-9'`^._ ]+)"
  129. captures:
  130. 1: entity.name.type.fsharp
  131. - include: keywords
  132. - match: '\s*(->)\s*(?!with|get|set\b)\b([\w0-9''`^._]+)'
  133. captures:
  134. 1: keyword.symbol.fsharp
  135. 2: entity.name.type.fsharp
  136. - match: '\?{0,1}([[:alpha:]0-9''`^._ ]+)\s*(:)(\s*([?[:alpha:]0-9''`^._ ]+)(<))'
  137. captures:
  138. 1: variable.parameter.fsharp
  139. 2: keyword.symbol.fsharp
  140. 3: keyword.symbol.fsharp
  141. 4: entity.name.type.fsharp
  142. push:
  143. - match: (>)
  144. captures:
  145. 1: keyword.symbol.fsharp
  146. pop: true
  147. - match: "([[:alpha:]0-9'`^._ ]+)"
  148. captures:
  149. 1: entity.name.type.fsharp
  150. - include: keywords
  151. compiler_directives:
  152. - match: \s?(#if|#elif|#else|#elseif|#endif|#light|#nowarn)
  153. scope: compiler_directive.fsharp
  154. captures:
  155. constants:
  156. - match: \(\)
  157. scope: constant.language.unit.fsharp
  158. - match: '\b-?[0-9][0-9_]*((\.([0-9][0-9_]*([eE][+-]??[0-9][0-9_]*)?)?)|([eE][+-]??[0-9][0-9_]*))'
  159. scope: constant.numeric.floating-point.fsharp
  160. - match: '\b(-?((0(x|X)[0-9a-fA-F][0-9a-fA-F_]*)|(0(o|O)[0-7][0-7_]*)|(0(b|B)[01][01_]*)|([0-9][0-9_]*)))'
  161. scope: constant.numeric.integer.nativeint.fsharp
  162. - match: \b(true|false|null|unit)\b
  163. scope: constant.others.fsharp
  164. definition:
  165. - match: '\b(val mutable|val|let mutable|let inline|let|member val|member|static member|override|let!)(\s+rec|mutable)?(\s+\[\<.*\>\])?\s*(private|internal|public)?\s+(\[[^-=]*\]|[_[:alpha:]]([_[:alpha:]0-9,\._]+)*|``[_[:alpha:]]([_[:alpha:]0-9,\._`\s]+|(?<=,)\s)*)?'
  166. captures:
  167. 1: keyword.fsharp
  168. 2: keyword.fsharp
  169. 3: support.function.attribute.fsharp
  170. 4: keyword.fsharp
  171. 5: variable.fsharp
  172. push:
  173. - meta_scope: binding.fsharp
  174. - match: \s*(with\b|=|\n+=|(?<=\=))
  175. captures:
  176. 1: keyword.fsharp
  177. pop: true
  178. - include: comments
  179. - include: attributes
  180. - match: (:)\s*(\()
  181. captures:
  182. 1: keyword.symbol.fsharp
  183. 2: keyword.symbol.fsharp
  184. push:
  185. - match: '(\)\s*(([?[:alpha:]0-9''`^._ ]+))+)'
  186. captures:
  187. 1: keyword.symbol.fsharp
  188. 2: entity.name.type.fsharp
  189. pop: true
  190. - include: tuple_signature
  191. - match: '(:)\s*([?[:alpha:]0-9''`^._ ]+)*'
  192. captures:
  193. 1: keyword.symbol.fsharp
  194. 2: entity.name.type.fsharp
  195. - match: '(->)\s*(\()?\s*([?[:alpha:]0-9''`^._ ]+)*'
  196. captures:
  197. 1: keyword.symbol.fsharp
  198. 2: keyword.symbol.fsharp
  199. 3: entity.name.type.fsharp
  200. - match: (\*)\s*(\()
  201. captures:
  202. 1: keyword.symbol.fsharp
  203. 2: keyword.symbol.fsharp
  204. push:
  205. - match: '(\)\s*(([?[:alpha:]0-9''`^._ ]+))+)'
  206. captures:
  207. 1: keyword.symbol.fsharp
  208. 2: entity.name.type.fsharp
  209. pop: true
  210. - include: tuple_signature
  211. - match: '(\*)(\s*([?[:alpha:]0-9''`^._ ]+))*'
  212. captures:
  213. 1: keyword.symbol.fsharp
  214. 2: entity.name.type.fsharp
  215. - match: '(<(?![[:space:]]*\)))'
  216. captures:
  217. 1: keyword.symbol.fsharp
  218. push:
  219. - match: (>)
  220. captures:
  221. 1: keyword.symbol.fsharp
  222. pop: true
  223. - include: generic_declaration
  224. - match: "({)"
  225. captures:
  226. 1: keyword.symbol.fsharp
  227. push:
  228. - match: "(})"
  229. captures:
  230. 1: keyword.symbol.fsharp
  231. pop: true
  232. - include: record_signature
  233. - include: variables
  234. - include: keywords
  235. double_tick:
  236. - match: (``)(.*)(``)
  237. scope: variable.other.binding.fsharp
  238. captures:
  239. 1: string.quoted.single.fsharp
  240. 2: variable.other.binding.fsharp
  241. 3: string.quoted.single.fsharp
  242. du_declaration:
  243. - match: \b(of)\b
  244. captures:
  245. 1: keyword.fsharp
  246. push:
  247. - meta_scope: du_declaration.fsharp
  248. - match: $|(\|)
  249. captures:
  250. 1: keyword.symbol.fsharp
  251. pop: true
  252. - include: comments
  253. - match: '([[:alpha:]0-9''`<>^._]+|``[[:alpha:]0-9'' <>^._]+``)\s*(:)\s*([[:alpha:]0-9''`<>^._]+|``[[:alpha:]0-9'' <>^._]+``)'
  254. captures:
  255. 1: variable.parameter.fsharp
  256. 2: keyword.symbol.fsharp
  257. 3: entity.name.type.fsharp
  258. - match: "([[:alpha:]0-9'`^._]+)|``([[:alpha:]0-9'^._ ]+)``"
  259. captures:
  260. 1: entity.name.type.fsharp
  261. - include: keywords
  262. generic_declaration:
  263. - match: "([^<>,*()-])"
  264. captures:
  265. 1: entity.name.type.fsharp
  266. - match: (<)
  267. captures:
  268. 1: keyword.symbol.fsharp
  269. push:
  270. - match: (>)
  271. captures:
  272. 1: keyword.symbol.fsharp
  273. pop: true
  274. - match: "([^<>,*()-])"
  275. captures:
  276. 1: entity.name.type.fsharp
  277. - include: tuple_signature
  278. - include: generic_declaration
  279. - include: keywords
  280. keywords:
  281. - match: \b(private|to|public|internal|function|yield!|yield|class|exception|match|delegate|of|new|in|as|if|then|else|elif|for|begin|end|inherit|do|let\!|return\!|return|interface|with|abstract|property|union|enum|member|try|finally|and|when|use|use\!|struct|while|mutable)(?!')\b
  282. scope: keyword.fsharp
  283. - match: '(&&&|\|\|\||\^\^\^|~~~|<<<|>>>|\|>|\->|\<\-|:>|:\?>|:|\[|\]|\;|<>|=|@|\|\||&&|{|}|\||_|\.\.|\,|\+|\-|\*|\/|\^|\!|\>|\>\=|\>\>|\<|\<\=|\(|\)|\<\<)'
  284. scope: keyword.symbol.fsharp
  285. member_declaration:
  286. - match: (\()
  287. captures:
  288. 1: keyword.symbol.fsharp
  289. push:
  290. - match: (\))
  291. captures:
  292. 1: keyword.symbol.fsharp
  293. pop: true
  294. - include: comments
  295. - include: common_declaration
  296. - match: '\?{0,1}([[:alpha:]0-9''`^._ ]+)\s*(:{0,1})(\s*([?[:alpha:]0-9''`<>^._ ]+)){0,1}'
  297. captures:
  298. 1: variable.parameter.fsharp
  299. 2: keyword.symbol.fsharp
  300. 3: entity.name.type.fsharp
  301. - include: keywords
  302. modules:
  303. - match: '\b(namespace|module)\s*(public|internal|private)?\s+([[:alpha:]][[:alpha:]0-9''_. ]*)'
  304. captures:
  305. 1: keyword.fsharp
  306. 2: keyword.fsharp
  307. 3: entity.name.section.fsharp
  308. push:
  309. - meta_scope: entity.name.section.fsharp
  310. - match: (\s?=|\s|$)
  311. captures:
  312. 1: keyword.symbol.fsharp
  313. pop: true
  314. - match: '(\.)([A-Z][[:alpha:]0-9''_]*)'
  315. scope: entity.name.section.fsharp
  316. captures:
  317. 1: punctuation.separator.namespace-reference.fsharp
  318. 2: entity.name.section.fsharp
  319. - match: '\b(open)\s+([[:alpha:]][[:alpha:]0-9''_]*)(?=(\.[A-Z][[:alpha:]0-9_]*)*)'
  320. captures:
  321. 1: keyword.fsharp
  322. 2: entity.name.section.fsharp
  323. push:
  324. - meta_scope: namespace.open.fsharp
  325. - match: (\s|$)
  326. pop: true
  327. - match: '(\.)([[:alpha:]][[:alpha:]0-9''_]*)'
  328. scope: entity.name.section.fsharp
  329. captures:
  330. 1: punctuation.separator.namespace-reference.fsharp
  331. 2: entity.name.section.fsharp
  332. - match: '^\s*(module)\s+([A-Z][[:alpha:]0-9''_]*)\s*(=)\s*([A-Z][[:alpha:]0-9''_]*)'
  333. captures:
  334. 1: keyword.fsharp
  335. 2: entity.name.type.namespace.fsharp
  336. 3: punctuation.separator.namespace-definition.fsharp
  337. 4: entity.name.section.fsharp
  338. push:
  339. - meta_scope: namespace.alias.fsharp
  340. - match: (\s|$)
  341. pop: true
  342. - match: '(\.)([A-Z][[:alpha:]0-9''_]*)'
  343. scope: entity.name.section.fsharp
  344. captures:
  345. 1: punctuation.separator.namespace-reference.fsharp
  346. 2: entity.name.section.fsharp
  347. record_declaration:
  348. - match: '(\{)'
  349. captures:
  350. 1: keyword.symbol.fsharp
  351. push:
  352. - match: '(?<=\})'
  353. pop: true
  354. - include: comments
  355. - match: '(((mutable)\s[[:alpha:]]+)|[[:alpha:]0-9''`<>^._]*)\s*((?<!:):(?!:))\s*'
  356. captures:
  357. 3: keyword.fsharp
  358. 4: keyword.symbol.fsharp
  359. push:
  360. - match: '$|(;|\})'
  361. captures:
  362. 1: keyword.symbol.fsharp
  363. pop: true
  364. - include: comments
  365. - match: "([[:alpha:]0-9'`^_ ]+)"
  366. captures:
  367. 1: entity.name.type.fsharp
  368. - include: keywords
  369. - include: chars
  370. - include: compiler_directives
  371. - include: constants
  372. - include: strings
  373. - include: chars
  374. - include: double_tick
  375. - include: definition
  376. - include: attributes
  377. - include: anonymous_functions
  378. - include: keywords
  379. - include: cexprs
  380. - include: text
  381. record_signature:
  382. - match: "[[:alpha:]0-9'`^_ ]+(=)([[:alpha:]0-9'`^_ ]+)"
  383. captures:
  384. 1: keyword.symbol.fsharp
  385. 2: variable.parameter.fsharp
  386. - match: "({)"
  387. captures:
  388. 1: keyword.symbol.fsharp
  389. push:
  390. - match: "(})"
  391. captures:
  392. 1: keyword.symbol.fsharp
  393. pop: true
  394. - match: "[[:alpha:]0-9'`^_ ]+(=)([[:alpha:]0-9'`^_ ]+)"
  395. captures:
  396. 1: keyword.symbol.fsharp
  397. 2: variable.parameter.fsharp
  398. - include: record_signature
  399. - include: keywords
  400. records:
  401. - match: '\b(type)[\s]+(private|internal|public)?\s*'
  402. captures:
  403. 1: keyword.fsharp
  404. 2: keyword.fsharp
  405. 3: support.function.attribute.fsharp
  406. push:
  407. - meta_scope: record.fsharp
  408. - match: '\s*((with)|((as)\s*([[:alpha:]0-9'']+))|(=)|[\n=]|(\(\)))'
  409. captures:
  410. 2: keyword.fsharp
  411. 3: keyword.fsharp
  412. 4: keyword.fsharp
  413. 5: variable.parameter.fsharp
  414. 6: keyword.symbol.fsharp
  415. 7: constant.language.unit.fsharp
  416. pop: true
  417. - include: comments
  418. - include: attributes
  419. - match: "([[:alpha:]0-9'`^:,._]+|``[[:alpha:]0-9'`^:,._ ]+``)(<)"
  420. captures:
  421. 1: entity.name.type.fsharp
  422. 2: keyword.symbol.fsharp
  423. - match: \s*(>)\s*(private|internal|public)?
  424. captures:
  425. 1: keyword.symbol.fsharp
  426. 2: keyword.fsharp
  427. - match: "([[:alpha:]0-9'`^._ ]+)"
  428. captures:
  429. 1: entity.name.type.fsharp
  430. - include: member_declaration
  431. - include: keywords
  432. string_formatter:
  433. - match: (%0?-?(\d+)?((a|t)|(\.\d+)?(f|F|e|E|g|G|M)|(b|c|s|d|i|x|X|o|u)|(s|b|O)|(\+?A)))
  434. scope: entity.name.type.format.specifier.fsharp
  435. captures:
  436. 1: keyword.format.specifier.fsharp
  437. strings:
  438. - match: '(?=[^\\])(@")'
  439. captures:
  440. 1: punctuation.definition.string.begin.fsharp
  441. push:
  442. - meta_scope: string.quoted.literal.fsharp
  443. - match: (")(?!")
  444. captures:
  445. 1: punctuation.definition.string.end.fsharp
  446. pop: true
  447. - match: '"(")'
  448. scope: constant.character.string.escape.fsharp
  449. - match: '(?=[^\\])(""")'
  450. captures:
  451. 1: punctuation.definition.string.begin.fsharp
  452. push:
  453. - meta_scope: string.quoted.triple.fsharp
  454. - match: (""")
  455. captures:
  456. 1: punctuation.definition.string.end.fsharp
  457. pop: true
  458. - include: string_formatter
  459. - match: '(?=[^\\])(")'
  460. captures:
  461. 1: punctuation.definition.string.begin.fsharp
  462. push:
  463. - meta_scope: string.quoted.double.fsharp
  464. - match: (")
  465. captures:
  466. 1: punctuation.definition.string.end.fsharp
  467. pop: true
  468. - match: '\\$[ \t]*'
  469. scope: punctuation.separator.string.ignore-eol.fsharp
  470. - match: '\\([\\''''ntbr]|u[a-fA-F0-9]{4}|u[a-fA-F0-9]{8})'
  471. scope: constant.character.string.escape.fsharp
  472. - match: '\\(?![\\''''ntbr]|u[a-fA-F0-9]{4}|u[a-fA-F0-9]{8}).'
  473. scope: invalid.illeagal.character.string.fsharp
  474. - include: string_formatter
  475. text:
  476. - match: \\
  477. scope: text.fsharp
  478. tuple_signature:
  479. - match: "(([?[:alpha:]0-9'`^._ ]+))+"
  480. captures:
  481. 1: entity.name.type.fsharp
  482. - match: (\()
  483. captures:
  484. 1: keyword.symbol.fsharp
  485. push:
  486. - match: (\))
  487. captures:
  488. 1: keyword.symbol.fsharp
  489. pop: true
  490. - match: "(([?[:alpha:]0-9'`^._ ]+))+"
  491. captures:
  492. 1: entity.name.type.fsharp
  493. - include: tuple_signature
  494. - include: keywords
  495. variables:
  496. - match: \(\)
  497. scope: constant.language.unit.fsharp
  498. - match: '``[[:alpha:]0-9''`^:,._ ]+``|[[:alpha:]0-9''`<>^._ ]\w*'
  499. scope: variable.parameter.fsharp