python.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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('vs/basic-languages/python/python',["require", "exports", "../fillers/monaco-editor-core"], function (require, exports, monaco_editor_core_1) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  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'] },
  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. ],
  33. onEnterRules: [
  34. {
  35. beforeText: new RegExp('^\\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\\s*$'),
  36. action: { indentAction: monaco_editor_core_1.languages.IndentAction.Indent }
  37. }
  38. ],
  39. folding: {
  40. offSide: true,
  41. markers: {
  42. start: new RegExp('^\\s*#region\\b'),
  43. end: new RegExp('^\\s*#endregion\\b')
  44. }
  45. }
  46. };
  47. exports.language = {
  48. defaultToken: '',
  49. tokenPostfix: '.python',
  50. keywords: [
  51. // This section is the result of running
  52. // `for k in keyword.kwlist: print(' "' + k + '",')` in a Python REPL,
  53. // though note that the output from Python 3 is not a strict superset of the
  54. // output from Python 2.
  55. 'False',
  56. 'None',
  57. 'True',
  58. 'and',
  59. 'as',
  60. 'assert',
  61. 'async',
  62. 'await',
  63. 'break',
  64. 'class',
  65. 'continue',
  66. 'def',
  67. 'del',
  68. 'elif',
  69. 'else',
  70. 'except',
  71. 'exec',
  72. 'finally',
  73. 'for',
  74. 'from',
  75. 'global',
  76. 'if',
  77. 'import',
  78. 'in',
  79. 'is',
  80. 'lambda',
  81. 'nonlocal',
  82. 'not',
  83. 'or',
  84. 'pass',
  85. 'print',
  86. 'raise',
  87. 'return',
  88. 'try',
  89. 'while',
  90. 'with',
  91. 'yield',
  92. 'int',
  93. 'float',
  94. 'long',
  95. 'complex',
  96. 'hex',
  97. 'abs',
  98. 'all',
  99. 'any',
  100. 'apply',
  101. 'basestring',
  102. 'bin',
  103. 'bool',
  104. 'buffer',
  105. 'bytearray',
  106. 'callable',
  107. 'chr',
  108. 'classmethod',
  109. 'cmp',
  110. 'coerce',
  111. 'compile',
  112. 'complex',
  113. 'delattr',
  114. 'dict',
  115. 'dir',
  116. 'divmod',
  117. 'enumerate',
  118. 'eval',
  119. 'execfile',
  120. 'file',
  121. 'filter',
  122. 'format',
  123. 'frozenset',
  124. 'getattr',
  125. 'globals',
  126. 'hasattr',
  127. 'hash',
  128. 'help',
  129. 'id',
  130. 'input',
  131. 'intern',
  132. 'isinstance',
  133. 'issubclass',
  134. 'iter',
  135. 'len',
  136. 'locals',
  137. 'list',
  138. 'map',
  139. 'max',
  140. 'memoryview',
  141. 'min',
  142. 'next',
  143. 'object',
  144. 'oct',
  145. 'open',
  146. 'ord',
  147. 'pow',
  148. 'print',
  149. 'property',
  150. 'reversed',
  151. 'range',
  152. 'raw_input',
  153. 'reduce',
  154. 'reload',
  155. 'repr',
  156. 'reversed',
  157. 'round',
  158. 'self',
  159. 'set',
  160. 'setattr',
  161. 'slice',
  162. 'sorted',
  163. 'staticmethod',
  164. 'str',
  165. 'sum',
  166. 'super',
  167. 'tuple',
  168. 'type',
  169. 'unichr',
  170. 'unicode',
  171. 'vars',
  172. 'xrange',
  173. 'zip',
  174. '__dict__',
  175. '__methods__',
  176. '__members__',
  177. '__class__',
  178. '__bases__',
  179. '__name__',
  180. '__mro__',
  181. '__subclasses__',
  182. '__init__',
  183. '__import__'
  184. ],
  185. brackets: [
  186. { open: '{', close: '}', token: 'delimiter.curly' },
  187. { open: '[', close: ']', token: 'delimiter.bracket' },
  188. { open: '(', close: ')', token: 'delimiter.parenthesis' }
  189. ],
  190. tokenizer: {
  191. root: [
  192. { include: '@whitespace' },
  193. { include: '@numbers' },
  194. { include: '@strings' },
  195. [/[,:;]/, 'delimiter'],
  196. [/[{}\[\]()]/, '@brackets'],
  197. [/@[a-zA-Z_]\w*/, 'tag'],
  198. [
  199. /[a-zA-Z_]\w*/,
  200. {
  201. cases: {
  202. '@keywords': 'keyword',
  203. '@default': 'identifier'
  204. }
  205. }
  206. ]
  207. ],
  208. // Deal with white space, including single and multi-line comments
  209. whitespace: [
  210. [/\s+/, 'white'],
  211. [/(^#.*$)/, 'comment'],
  212. [/'''/, 'string', '@endDocString'],
  213. [/"""/, 'string', '@endDblDocString']
  214. ],
  215. endDocString: [
  216. [/[^']+/, 'string'],
  217. [/\\'/, 'string'],
  218. [/'''/, 'string', '@popall'],
  219. [/'/, 'string']
  220. ],
  221. endDblDocString: [
  222. [/[^"]+/, 'string'],
  223. [/\\"/, 'string'],
  224. [/"""/, 'string', '@popall'],
  225. [/"/, 'string']
  226. ],
  227. // Recognize hex, negatives, decimals, imaginaries, longs, and scientific notation
  228. numbers: [
  229. [/-?0x([abcdef]|[ABCDEF]|\d)+[lL]?/, 'number.hex'],
  230. [/-?(\d*\.)?\d+([eE][+\-]?\d+)?[jJ]?[lL]?/, 'number']
  231. ],
  232. // Recognize strings, including those broken across lines with \ (but not without)
  233. strings: [
  234. [/'$/, 'string.escape', '@popall'],
  235. [/'/, 'string.escape', '@stringBody'],
  236. [/"$/, 'string.escape', '@popall'],
  237. [/"/, 'string.escape', '@dblStringBody']
  238. ],
  239. stringBody: [
  240. [/[^\\']+$/, 'string', '@popall'],
  241. [/[^\\']+/, 'string'],
  242. [/\\./, 'string'],
  243. [/'/, 'string.escape', '@popall'],
  244. [/\\$/, 'string']
  245. ],
  246. dblStringBody: [
  247. [/[^\\"]+$/, 'string', '@popall'],
  248. [/[^\\"]+/, 'string'],
  249. [/\\./, 'string'],
  250. [/"/, 'string.escape', '@popall'],
  251. [/\\$/, 'string']
  252. ]
  253. }
  254. };
  255. });