fsharp.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. 'use strict';
  6. import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
  7. import ILanguage = monaco.languages.IMonarchLanguage;
  8. export const conf: IRichLanguageConfiguration = {
  9. comments: {
  10. lineComment: '//',
  11. blockComment: ['(*', '*)'],
  12. },
  13. brackets: [
  14. ['{', '}'],
  15. ['[', ']'],
  16. ['(', ')']
  17. ],
  18. autoClosingPairs: [
  19. { open: '{', close: '}' },
  20. { open: '[', close: ']' },
  21. { open: '(', close: ')' },
  22. { open: '"', close: '"' }
  23. ],
  24. surroundingPairs: [
  25. { open: '{', close: '}' },
  26. { open: '[', close: ']' },
  27. { open: '(', close: ')' },
  28. { open: '"', close: '"' },
  29. { open: '\'', close: '\'' }
  30. ]
  31. };
  32. export const language = <ILanguage>{
  33. defaultToken: '',
  34. tokenPostfix: '.fs',
  35. keywords: [
  36. 'abstract', 'and', 'atomic', 'as',
  37. 'assert', 'asr', 'base', 'begin',
  38. 'break', 'checked', 'component',
  39. 'const', 'constraint', 'constructor',
  40. 'continue', 'class', 'default',
  41. 'delegate', 'do', 'done', 'downcast',
  42. 'downto', 'elif', 'else', 'end',
  43. 'exception', 'eager', 'event', 'external',
  44. 'extern', 'false', 'finally', 'for',
  45. 'fun', 'function', 'fixed', 'functor',
  46. 'global', 'if', 'in', 'include', 'inherit',
  47. 'inline', 'interface', 'internal', 'land',
  48. 'lor', 'lsl', 'lsr', 'lxor', 'lazy', 'let',
  49. 'match', 'member', 'mod', 'module', 'mutable',
  50. 'namespace', 'method', 'mixin', 'new', 'not',
  51. 'null', 'of', 'open', 'or', 'object',
  52. 'override', 'private', 'parallel', 'process',
  53. 'protected', 'pure', 'public', 'rec', 'return',
  54. 'static', 'sealed', 'struct', 'sig', 'then',
  55. 'to', 'true', 'tailcall', 'trait',
  56. 'try', 'type', 'upcast', 'use',
  57. 'val', 'void', 'virtual', 'volatile',
  58. 'when', 'while', 'with', 'yield'
  59. ],
  60. // we include these common regular expressions
  61. symbols: /[=><!~?:&|+\-*\^%;\.,\/]+/,
  62. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  63. integersuffix: /[uU]?[yslnLI]?/,
  64. floatsuffix: /[fFmM]?/,
  65. // The main tokenizer for our languages
  66. tokenizer: {
  67. root: [
  68. // identifiers and keywords
  69. [/[a-zA-Z_]\w*/, {
  70. cases: {
  71. '@keywords': { token: 'keyword.$0' },
  72. '@default': 'identifier'
  73. }
  74. }],
  75. // whitespace
  76. { include: '@whitespace' },
  77. // [< attributes >].
  78. [/\[<.*>\]/, 'annotation'],
  79. // Preprocessor directive
  80. [/^#(if|else|endif)/, 'keyword'],
  81. // delimiters and operators
  82. [/[{}()\[\]]/, '@brackets'],
  83. [/[<>](?!@symbols)/, '@brackets'],
  84. [/@symbols/, 'delimiter'],
  85. // numbers
  86. [/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  87. [/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  88. [/0x[0-9a-fA-F]+LF/, 'number.float'],
  89. [/0x[0-9a-fA-F]+(@integersuffix)/, 'number.hex'],
  90. [/0b[0-1]+(@integersuffix)/, 'number.bin'],
  91. [/\d+(@integersuffix)/, 'number'],
  92. // delimiter: after number because of .\d floats
  93. [/[;,.]/, 'delimiter'],
  94. // strings
  95. [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
  96. [/"""/, 'string', '@string."""'],
  97. [/"/, 'string', '@string."'],
  98. // literal string
  99. [/\@"/, { token: 'string.quote', next: '@litstring' }],
  100. // characters
  101. [/'[^\\']'B?/, 'string'],
  102. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  103. [/'/, 'string.invalid']
  104. ],
  105. whitespace: [
  106. [/[ \t\r\n]+/, ''],
  107. [/\(\*(?!\))/, 'comment', '@comment'],
  108. [/\/\/.*$/, 'comment'],
  109. ],
  110. comment: [
  111. [/[^\*]+/, 'comment'],
  112. [/\*\)/, 'comment', '@pop'],
  113. [/\*/, 'comment']
  114. ],
  115. string: [
  116. [/[^\\"]+/, 'string'],
  117. [/@escapes/, 'string.escape'],
  118. [/\\./, 'string.escape.invalid'],
  119. [/("""|"B?)/, {
  120. cases: {
  121. '$#==$S2': { token: 'string', next: '@pop' },
  122. '@default': 'string'
  123. }
  124. }]
  125. ],
  126. litstring: [
  127. [/[^"]+/, 'string'],
  128. [/""/, 'string.escape'],
  129. [/"/, { token: 'string.quote', next: '@pop' }]
  130. ],
  131. },
  132. };