prism-fsharp.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Prism.languages.fsharp = Prism.languages.extend('clike', {
  2. 'comment': [
  3. {
  4. pattern: /(^|[^\\])\(\*[\s\S]*?\*\)/,
  5. lookbehind: true
  6. },
  7. {
  8. pattern: /(^|[^\\:])\/\/.*/,
  9. lookbehind: true
  10. }
  11. ],
  12. 'string': {
  13. pattern: /(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/,
  14. greedy: true
  15. },
  16. 'class-name': {
  17. pattern: /(\b(?:exception|inherit|interface|new|of|type)\s+|\w\s*:\s*|\s:\??>\s*)[.\w]+\b(?:\s*(?:->|\*)\s*[.\w]+\b)*(?!\s*[:.])/,
  18. lookbehind: true,
  19. inside: {
  20. 'operator': /->|\*/,
  21. 'punctuation': /\./
  22. }
  23. },
  24. 'keyword': /\b(?:let|return|use|yield)(?:!\B|\b)|\b(?:abstract|and|as|assert|base|begin|class|default|delegate|do|done|downcast|downto|elif|else|end|exception|extern|false|finally|for|fun|function|global|if|in|inherit|inline|interface|internal|lazy|match|member|module|mutable|namespace|new|not|null|of|open|or|override|private|public|rec|select|static|struct|then|to|true|try|type|upcast|val|void|when|while|with|asr|land|lor|lsl|lsr|lxor|mod|sig|atomic|break|checked|component|const|constraint|constructor|continue|eager|event|external|fixed|functor|include|method|mixin|object|parallel|process|protected|pure|sealed|tailcall|trait|virtual|volatile)\b/,
  25. 'number': [
  26. /\b0x[\da-fA-F]+(?:un|lf|LF)?\b/,
  27. /\b0b[01]+(?:y|uy)?\b/,
  28. /(?:\b\d+\.?\d*|\B\.\d+)(?:[fm]|e[+-]?\d+)?\b/i,
  29. /\b\d+(?:[IlLsy]|u[lsy]?|UL)?\b/
  30. ],
  31. 'operator': /([<>~&^])\1\1|([*.:<>&])\2|<-|->|[!=:]=|<?\|{1,3}>?|\??(?:<=|>=|<>|[-+*/%=<>])\??|[!?^&]|~[+~-]|:>|:\?>?/
  32. });
  33. Prism.languages.insertBefore('fsharp', 'keyword', {
  34. 'preprocessor': {
  35. pattern: /^[^\r\n\S]*#.*/m,
  36. alias: 'property',
  37. inside: {
  38. 'directive': {
  39. pattern: /(\s*#)\b(?:else|endif|if|light|line|nowarn)\b/,
  40. lookbehind: true,
  41. alias: 'keyword'
  42. }
  43. }
  44. }
  45. });
  46. Prism.languages.insertBefore('fsharp', 'punctuation', {
  47. 'computation-expression': {
  48. pattern: /[_a-z]\w*(?=\s*\{)/i,
  49. alias: 'keyword'
  50. }
  51. });
  52. Prism.languages.insertBefore('fsharp', 'string', {
  53. 'annotation': {
  54. pattern: /\[<.+?>\]/,
  55. inside: {
  56. 'punctuation': /^\[<|>\]$/,
  57. 'class-name': {
  58. pattern: /^\w+$|(^|;\s*)[A-Z]\w*(?=\()/,
  59. lookbehind: true
  60. },
  61. 'annotation-content': {
  62. pattern: /[\s\S]+/,
  63. inside: Prism.languages.fsharp
  64. }
  65. }
  66. }
  67. });