python.js 7.1 KB

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