csharp.js 8.1 KB

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