powershell.js 7.1 KB

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