prism-fsharp.js 2.4 KB

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