powershell.js 5.3 KB

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