powershell.js 8.2 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('vs/basic-languages/powershell/powershell',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. // the default separators except `$-`
  11. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  12. comments: {
  13. lineComment: '#',
  14. blockComment: ['<#', '#>']
  15. },
  16. brackets: [
  17. ['{', '}'],
  18. ['[', ']'],
  19. ['(', ')']
  20. ],
  21. autoClosingPairs: [
  22. { open: '{', close: '}' },
  23. { open: '[', close: ']' },
  24. { open: '(', close: ')' },
  25. { open: '"', close: '"', notIn: ['string'] },
  26. { open: "'", close: "'", notIn: ['string', 'comment'] }
  27. ],
  28. surroundingPairs: [
  29. { open: '{', close: '}' },
  30. { open: '[', close: ']' },
  31. { open: '(', close: ')' },
  32. { open: '"', close: '"' },
  33. { open: "'", close: "'" }
  34. ],
  35. folding: {
  36. markers: {
  37. start: new RegExp('^\\s*#region\\b'),
  38. end: new RegExp('^\\s*#endregion\\b')
  39. }
  40. }
  41. };
  42. exports.language = {
  43. defaultToken: '',
  44. ignoreCase: true,
  45. tokenPostfix: '.ps1',
  46. brackets: [
  47. { token: 'delimiter.curly', open: '{', close: '}' },
  48. { token: 'delimiter.square', open: '[', close: ']' },
  49. { token: 'delimiter.parenthesis', open: '(', close: ')' }
  50. ],
  51. keywords: [
  52. 'begin',
  53. 'break',
  54. 'catch',
  55. 'class',
  56. 'continue',
  57. 'data',
  58. 'define',
  59. 'do',
  60. 'dynamicparam',
  61. 'else',
  62. 'elseif',
  63. 'end',
  64. 'exit',
  65. 'filter',
  66. 'finally',
  67. 'for',
  68. 'foreach',
  69. 'from',
  70. 'function',
  71. 'if',
  72. 'in',
  73. 'param',
  74. 'process',
  75. 'return',
  76. 'switch',
  77. 'throw',
  78. 'trap',
  79. 'try',
  80. 'until',
  81. 'using',
  82. 'var',
  83. 'while',
  84. 'workflow',
  85. 'parallel',
  86. 'sequence',
  87. 'inlinescript',
  88. 'configuration'
  89. ],
  90. helpKeywords: /SYNOPSIS|DESCRIPTION|PARAMETER|EXAMPLE|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|ROLE|FUNCTIONALITY|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP/,
  91. // we include these common regular expressions
  92. symbols: /[=><!~?&%|+\-*\/\^;\.,]+/,
  93. escapes: /`(?:[abfnrtv\\"'$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  94. // The main tokenizer for our languages
  95. tokenizer: {
  96. root: [
  97. // commands and keywords
  98. [
  99. /[a-zA-Z_][\w-]*/,
  100. {
  101. cases: {
  102. '@keywords': { token: 'keyword.$0' },
  103. '@default': ''
  104. }
  105. }
  106. ],
  107. // whitespace
  108. [/[ \t\r\n]+/, ''],
  109. // labels
  110. [/^:\w*/, 'metatag'],
  111. // variables
  112. [
  113. /\$(\{((global|local|private|script|using):)?[\w]+\}|((global|local|private|script|using):)?[\w]+)/,
  114. 'variable'
  115. ],
  116. // Comments
  117. [/<#/, 'comment', '@comment'],
  118. [/#.*$/, 'comment'],
  119. // delimiters
  120. [/[{}()\[\]]/, '@brackets'],
  121. [/@symbols/, 'delimiter'],
  122. // numbers
  123. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  124. [/0[xX][0-9a-fA-F_]*[0-9a-fA-F]/, 'number.hex'],
  125. [/\d+?/, 'number'],
  126. // delimiter: after number because of .\d floats
  127. [/[;,.]/, 'delimiter'],
  128. // strings:
  129. [/\@"/, 'string', '@herestring."'],
  130. [/\@'/, 'string', "@herestring.'"],
  131. [
  132. /"/,
  133. {
  134. cases: {
  135. '@eos': 'string',
  136. '@default': { token: 'string', next: '@string."' }
  137. }
  138. }
  139. ],
  140. [
  141. /'/,
  142. {
  143. cases: {
  144. '@eos': 'string',
  145. '@default': { token: 'string', next: "@string.'" }
  146. }
  147. }
  148. ]
  149. ],
  150. string: [
  151. [
  152. /[^"'\$`]+/,
  153. {
  154. cases: {
  155. '@eos': { token: 'string', next: '@popall' },
  156. '@default': 'string'
  157. }
  158. }
  159. ],
  160. [
  161. /@escapes/,
  162. {
  163. cases: {
  164. '@eos': { token: 'string.escape', next: '@popall' },
  165. '@default': 'string.escape'
  166. }
  167. }
  168. ],
  169. [
  170. /`./,
  171. {
  172. cases: {
  173. '@eos': {
  174. token: 'string.escape.invalid',
  175. next: '@popall'
  176. },
  177. '@default': 'string.escape.invalid'
  178. }
  179. }
  180. ],
  181. [
  182. /\$[\w]+$/,
  183. {
  184. cases: {
  185. '$S2=="': { token: 'variable', next: '@popall' },
  186. '@default': { token: 'string', next: '@popall' }
  187. }
  188. }
  189. ],
  190. [
  191. /\$[\w]+/,
  192. {
  193. cases: {
  194. '$S2=="': 'variable',
  195. '@default': 'string'
  196. }
  197. }
  198. ],
  199. [
  200. /["']/,
  201. {
  202. cases: {
  203. '$#==$S2': { token: 'string', next: '@pop' },
  204. '@default': {
  205. cases: {
  206. '@eos': { token: 'string', next: '@popall' },
  207. '@default': 'string'
  208. }
  209. }
  210. }
  211. }
  212. ]
  213. ],
  214. herestring: [
  215. [
  216. /^\s*(["'])@/,
  217. {
  218. cases: {
  219. '$1==$S2': { token: 'string', next: '@pop' },
  220. '@default': 'string'
  221. }
  222. }
  223. ],
  224. [/[^\$`]+/, 'string'],
  225. [/@escapes/, 'string.escape'],
  226. [/`./, 'string.escape.invalid'],
  227. [
  228. /\$[\w]+/,
  229. {
  230. cases: {
  231. '$S2=="': 'variable',
  232. '@default': 'string'
  233. }
  234. }
  235. ]
  236. ],
  237. comment: [
  238. [/[^#\.]+/, 'comment'],
  239. [/#>/, 'comment', '@pop'],
  240. [/(\.)(@helpKeywords)(?!\w)/, { token: 'comment.keyword.$2' }],
  241. [/[\.#]/, 'comment']
  242. ]
  243. }
  244. };
  245. });