fsharp.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export var conf = {
  6. comments: {
  7. lineComment: '//',
  8. blockComment: ['(*', '*)']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')']
  14. ],
  15. autoClosingPairs: [
  16. { open: '{', close: '}' },
  17. { open: '[', close: ']' },
  18. { open: '(', close: ')' },
  19. { open: '"', close: '"' }
  20. ],
  21. surroundingPairs: [
  22. { open: '{', close: '}' },
  23. { open: '[', close: ']' },
  24. { open: '(', close: ')' },
  25. { open: '"', close: '"' },
  26. { open: "'", close: "'" }
  27. ],
  28. folding: {
  29. markers: {
  30. start: new RegExp('^\\s*//\\s*#region\\b|^\\s*\\(\\*\\s*#region(.*)\\*\\)'),
  31. end: new RegExp('^\\s*//\\s*#endregion\\b|^\\s*\\(\\*\\s*#endregion\\s*\\*\\)')
  32. }
  33. }
  34. };
  35. export var language = {
  36. defaultToken: '',
  37. tokenPostfix: '.fs',
  38. keywords: [
  39. 'abstract',
  40. 'and',
  41. 'atomic',
  42. 'as',
  43. 'assert',
  44. 'asr',
  45. 'base',
  46. 'begin',
  47. 'break',
  48. 'checked',
  49. 'component',
  50. 'const',
  51. 'constraint',
  52. 'constructor',
  53. 'continue',
  54. 'class',
  55. 'default',
  56. 'delegate',
  57. 'do',
  58. 'done',
  59. 'downcast',
  60. 'downto',
  61. 'elif',
  62. 'else',
  63. 'end',
  64. 'exception',
  65. 'eager',
  66. 'event',
  67. 'external',
  68. 'extern',
  69. 'false',
  70. 'finally',
  71. 'for',
  72. 'fun',
  73. 'function',
  74. 'fixed',
  75. 'functor',
  76. 'global',
  77. 'if',
  78. 'in',
  79. 'include',
  80. 'inherit',
  81. 'inline',
  82. 'interface',
  83. 'internal',
  84. 'land',
  85. 'lor',
  86. 'lsl',
  87. 'lsr',
  88. 'lxor',
  89. 'lazy',
  90. 'let',
  91. 'match',
  92. 'member',
  93. 'mod',
  94. 'module',
  95. 'mutable',
  96. 'namespace',
  97. 'method',
  98. 'mixin',
  99. 'new',
  100. 'not',
  101. 'null',
  102. 'of',
  103. 'open',
  104. 'or',
  105. 'object',
  106. 'override',
  107. 'private',
  108. 'parallel',
  109. 'process',
  110. 'protected',
  111. 'pure',
  112. 'public',
  113. 'rec',
  114. 'return',
  115. 'static',
  116. 'sealed',
  117. 'struct',
  118. 'sig',
  119. 'then',
  120. 'to',
  121. 'true',
  122. 'tailcall',
  123. 'trait',
  124. 'try',
  125. 'type',
  126. 'upcast',
  127. 'use',
  128. 'val',
  129. 'void',
  130. 'virtual',
  131. 'volatile',
  132. 'when',
  133. 'while',
  134. 'with',
  135. 'yield'
  136. ],
  137. // we include these common regular expressions
  138. symbols: /[=><!~?:&|+\-*\^%;\.,\/]+/,
  139. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  140. integersuffix: /[uU]?[yslnLI]?/,
  141. floatsuffix: /[fFmM]?/,
  142. // The main tokenizer for our languages
  143. tokenizer: {
  144. root: [
  145. // identifiers and keywords
  146. [
  147. /[a-zA-Z_]\w*/,
  148. {
  149. cases: {
  150. '@keywords': { token: 'keyword.$0' },
  151. '@default': 'identifier'
  152. }
  153. }
  154. ],
  155. // whitespace
  156. { include: '@whitespace' },
  157. // [< attributes >].
  158. [/\[<.*>\]/, 'annotation'],
  159. // Preprocessor directive
  160. [/^#(if|else|endif)/, 'keyword'],
  161. // delimiters and operators
  162. [/[{}()\[\]]/, '@brackets'],
  163. [/[<>](?!@symbols)/, '@brackets'],
  164. [/@symbols/, 'delimiter'],
  165. // numbers
  166. [/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  167. [/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  168. [/0x[0-9a-fA-F]+LF/, 'number.float'],
  169. [/0x[0-9a-fA-F]+(@integersuffix)/, 'number.hex'],
  170. [/0b[0-1]+(@integersuffix)/, 'number.bin'],
  171. [/\d+(@integersuffix)/, 'number'],
  172. // delimiter: after number because of .\d floats
  173. [/[;,.]/, 'delimiter'],
  174. // strings
  175. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  176. [/"""/, 'string', '@string."""'],
  177. [/"/, 'string', '@string."'],
  178. // literal string
  179. [/\@"/, { token: 'string.quote', next: '@litstring' }],
  180. // characters
  181. [/'[^\\']'B?/, 'string'],
  182. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  183. [/'/, 'string.invalid']
  184. ],
  185. whitespace: [
  186. [/[ \t\r\n]+/, ''],
  187. [/\(\*(?!\))/, 'comment', '@comment'],
  188. [/\/\/.*$/, 'comment']
  189. ],
  190. comment: [
  191. [/[^*(]+/, 'comment'],
  192. [/\*\)/, 'comment', '@pop'],
  193. [/\*/, 'comment'],
  194. [/\(\*\)/, 'comment'],
  195. [/\(/, 'comment']
  196. ],
  197. string: [
  198. [/[^\\"]+/, 'string'],
  199. [/@escapes/, 'string.escape'],
  200. [/\\./, 'string.escape.invalid'],
  201. [
  202. /("""|"B?)/,
  203. {
  204. cases: {
  205. '$#==$S2': { token: 'string', next: '@pop' },
  206. '@default': 'string'
  207. }
  208. }
  209. ]
  210. ],
  211. litstring: [
  212. [/[^"]+/, 'string'],
  213. [/""/, 'string.escape'],
  214. [/"/, { token: 'string.quote', next: '@pop' }]
  215. ]
  216. }
  217. };