python.ts 4.4 KB

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