csharp.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.IRichLanguageConfiguration;
  7. import ILanguage = monaco.languages.IMonarchLanguage;
  8. export var conf:IRichLanguageConfiguration = {
  9. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  10. comments: {
  11. lineComment: '//',
  12. blockComment: ['/*', '*/'],
  13. },
  14. brackets: [['{','}'], ['[',']'], ['(',')'], ['<','>']],
  15. autoClosingPairs: [
  16. { open: '"', close: '"', notIn: ['string', 'comment'] },
  17. { open: '\'', close: '\'', notIn: ['string', 'comment'] },
  18. { open: '{', close: '}', notIn: ['string', 'comment'] },
  19. { open: '[', close: ']', notIn: ['string', 'comment'] },
  20. { open: '(', close: ')', notIn: ['string', 'comment'] },
  21. ]
  22. };
  23. export var language = <ILanguage> {
  24. defaultToken: '',
  25. tokenPostfix: '.cs',
  26. brackets: [
  27. { open: '{', close: '}', token: 'delimiter.curly' },
  28. { open: '[', close: ']', token: 'delimiter.square' },
  29. { open: '(', close: ')', token: 'delimiter.parenthesis' },
  30. { open: '<', close: '>', token: 'delimiter.angle' }
  31. ],
  32. keywords: [
  33. 'extern', 'alias', 'using', 'bool', 'decimal', 'sbyte', 'byte', 'short',
  34. 'ushort', 'int', 'uint', 'long', 'ulong', 'char', 'float', 'double',
  35. 'object', 'dynamic', 'string', 'assembly', 'is', 'as', 'ref',
  36. 'out', 'this', 'base', 'new', 'typeof', 'void', 'checked', 'unchecked',
  37. 'default', 'delegate', 'var', 'const', 'if', 'else', 'switch', 'case',
  38. 'while', 'do', 'for', 'foreach', 'in', 'break', 'continue', 'goto',
  39. 'return', 'throw', 'try', 'catch', 'finally', 'lock', 'yield', 'from',
  40. 'let', 'where', 'join', 'on', 'equals', 'into', 'orderby', 'ascending',
  41. 'descending', 'select', 'group', 'by', 'namespace', 'partial', 'class',
  42. 'field', 'event', 'method', 'param', 'property', 'public', 'protected',
  43. 'internal', 'private', 'abstract', 'sealed', 'static', 'struct', 'readonly',
  44. 'volatile', 'virtual', 'override', 'params', 'get', 'set', 'add', 'remove',
  45. 'operator', 'true', 'false', 'implicit', 'explicit', 'interface', 'enum',
  46. 'null', 'async', 'await','fixed','sizeof','stackalloc','unsafe', 'nameof',
  47. 'when'
  48. ],
  49. namespaceFollows: [
  50. 'namespace', 'using',
  51. ],
  52. parenFollows: [
  53. 'if', 'for', 'while', 'switch', 'foreach', 'using', 'catch', 'when'
  54. ],
  55. operators: [
  56. '=', '??', '||', '&&', '|', '^', '&', '==', '!=', '<=', '>=', '<<',
  57. '+', '-', '*', '/', '%', '!', '~', '++', '--','+=',
  58. '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>=', '>>', '=>'
  59. ],
  60. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  61. // escape sequences
  62. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  63. // The main tokenizer for our languages
  64. tokenizer: {
  65. root: [
  66. // identifiers and keywords
  67. [/\@?[a-zA-Z_]\w*/, { cases: {
  68. '@namespaceFollows': { token: 'keyword.$0', next: '@namespace' },
  69. '@keywords': { token: 'keyword.$0', next: '@qualified' },
  70. '@default': { token: 'identifier', next: '@qualified' }
  71. }
  72. }],
  73. // whitespace
  74. { include: '@whitespace' },
  75. // delimiters and operators
  76. [/}/, { cases: {
  77. '$S2==interpolatedstring' : { token: 'string.quote', bracket: '@close', next: '@pop' }
  78. , '@default' : '@brackets' } }],
  79. [/[{}()\[\]]/, '@brackets'],
  80. [/[<>](?!@symbols)/, '@brackets'],
  81. [/@symbols/, { cases: { '@operators': 'delimiter', '@default' : '' } } ],
  82. // literal string
  83. [/\@"/, { token: 'string.quote', bracket: '@open', next: '@litstring' } ],
  84. // interpolated string
  85. [/\$"/, { token: 'string.quote', bracket: '@open', next: '@interpolatedstring' } ],
  86. // numbers
  87. [/\d*\.\d+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'],
  88. [/0[xX][0-9a-fA-F]+/, 'number.hex'],
  89. [/\d+/, 'number'],
  90. // delimiter: after number because of .\d floats
  91. [/[;,.]/, 'delimiter'],
  92. // strings
  93. [/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
  94. [/"/, { token: 'string.quote', bracket: '@open', next: '@string' } ],
  95. // characters
  96. [/'[^\\']'/, 'string'],
  97. [/(')(@escapes)(')/, ['string','string.escape','string']],
  98. [/'/, 'string.invalid']
  99. ],
  100. qualified: [
  101. [/[a-zA-Z_][\w]*/, { cases:
  102. { '@keywords': {token:'keyword.$0'},
  103. '@default': 'identifier' }
  104. }],
  105. [/\./, 'delimiter'],
  106. ['','','@pop'],
  107. ],
  108. namespace: [
  109. { include: '@whitespace' },
  110. [/[A-Z]\w*/, 'namespace'],
  111. [/[\.=]/, 'delimiter'],
  112. ['','','@pop'],
  113. ],
  114. comment: [
  115. [/[^\/*]+/, 'comment' ],
  116. // [/\/\*/, 'comment', '@push' ], // no nested comments :-(
  117. ['\\*/', 'comment', '@pop' ],
  118. [/[\/*]/, 'comment' ]
  119. ],
  120. string: [
  121. [/[^\\"]+/, 'string'],
  122. [/@escapes/, 'string.escape'],
  123. [/\\./, 'string.escape.invalid'],
  124. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ]
  125. ],
  126. litstring: [
  127. [/[^"]+/, 'string'],
  128. [/""/, 'string.escape'],
  129. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ]
  130. ],
  131. interpolatedstring: [
  132. [/[^\\"{]+/, 'string'],
  133. [/@escapes/, 'string.escape'],
  134. [/\\./, 'string.escape.invalid'],
  135. [/{{/, 'string.escape'],
  136. [/}}/, 'string.escape'],
  137. [/{/, { token: 'string.quote', bracket: '@open', next: 'root.interpolatedstring' } ],
  138. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ]
  139. ],
  140. whitespace: [
  141. [/^[ \t\v\f]*#\w.*$/, 'namespace.cpp' ],
  142. [/[ \t\v\f\r\n]+/, ''],
  143. [/\/\*/, 'comment', '@comment' ],
  144. [/\/\/.*$/, 'comment'],
  145. ],
  146. },
  147. };