powershell.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. exports.conf = {
  9. // the default separators except `$-`
  10. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  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. folding: {
  35. markers: {
  36. start: new RegExp("^\\s*#region\\b"),
  37. end: new RegExp("^\\s*#endregion\\b")
  38. }
  39. }
  40. };
  41. exports.language = {
  42. defaultToken: '',
  43. ignoreCase: true,
  44. tokenPostfix: '.ps1',
  45. brackets: [
  46. { token: 'delimiter.curly', open: '{', close: '}' },
  47. { token: 'delimiter.square', open: '[', close: ']' },
  48. { token: 'delimiter.parenthesis', open: '(', close: ')' }
  49. ],
  50. keywords: [
  51. 'begin', 'break', 'catch', 'class', 'continue', 'data',
  52. 'define', 'do', 'dynamicparam', 'else', 'elseif', 'end',
  53. 'exit', 'filter', 'finally', 'for', 'foreach', 'from',
  54. 'function', 'if', 'in', 'param', 'process', 'return',
  55. 'switch', 'throw', 'trap', 'try', 'until', 'using',
  56. 'var', 'while', 'workflow', 'parallel', 'sequence', 'inlinescript', 'configuration'
  57. ],
  58. helpKeywords: /SYNOPSIS|DESCRIPTION|PARAMETER|EXAMPLE|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|ROLE|FUNCTIONALITY|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP/,
  59. // we include these common regular expressions
  60. symbols: /[=><!~?&%|+\-*\/\^;\.,]+/,
  61. escapes: /`(?:[abfnrtv\\"'$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  62. // The main tokenizer for our languages
  63. tokenizer: {
  64. root: [
  65. // commands and keywords
  66. [/[a-zA-Z_][\w-]*/, {
  67. cases: {
  68. '@keywords': { token: 'keyword.$0' },
  69. '@default': ''
  70. }
  71. }],
  72. // whitespace
  73. [/[ \t\r\n]+/, ''],
  74. // labels
  75. [/^:\w*/, 'metatag'],
  76. // variables
  77. [/\$(\{((global|local|private|script|using):)?[\w]+\}|((global|local|private|script|using):)?[\w]+)/, 'variable'],
  78. // Comments
  79. [/<#/, 'comment', '@comment'],
  80. [/#.*$/, 'comment'],
  81. // delimiters
  82. [/[{}()\[\]]/, '@brackets'],
  83. [/@symbols/, 'delimiter'],
  84. // numbers
  85. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  86. [/0[xX][0-9a-fA-F_]*[0-9a-fA-F]/, 'number.hex'],
  87. [/\d+?/, 'number'],
  88. // delimiter: after number because of .\d floats
  89. [/[;,.]/, 'delimiter'],
  90. // strings:
  91. [/\@"/, 'string', '@herestring."'],
  92. [/\@'/, 'string', '@herestring.\''],
  93. [/"/, {
  94. cases: {
  95. '@eos': 'string',
  96. '@default': { token: 'string', next: '@string."' }
  97. }
  98. }],
  99. [/'/, {
  100. cases: {
  101. '@eos': 'string',
  102. '@default': { token: 'string', next: '@string.\'' }
  103. }
  104. }],
  105. ],
  106. string: [
  107. [/[^"'\$`]+/, {
  108. cases: {
  109. '@eos': { token: 'string', next: '@popall' },
  110. '@default': 'string'
  111. }
  112. }],
  113. [/@escapes/, {
  114. cases: {
  115. '@eos': { token: 'string.escape', next: '@popall' },
  116. '@default': 'string.escape'
  117. }
  118. }],
  119. [/`./, {
  120. cases: {
  121. '@eos': { token: 'string.escape.invalid', next: '@popall' },
  122. '@default': 'string.escape.invalid'
  123. }
  124. }],
  125. [/\$[\w]+$/, {
  126. cases: {
  127. '$S2=="': { token: 'variable', next: '@popall' },
  128. '@default': { token: 'string', next: '@popall' }
  129. }
  130. }],
  131. [/\$[\w]+/, {
  132. cases: {
  133. '$S2=="': 'variable',
  134. '@default': 'string'
  135. }
  136. }],
  137. [/["']/, {
  138. cases: {
  139. '$#==$S2': { token: 'string', next: '@pop' },
  140. '@default': {
  141. cases: {
  142. '@eos': { token: 'string', next: '@popall' },
  143. '@default': 'string'
  144. }
  145. }
  146. }
  147. }],
  148. ],
  149. herestring: [
  150. [/^\s*(["'])@/, {
  151. cases: {
  152. '$1==$S2': { token: 'string', next: '@pop' },
  153. '@default': 'string'
  154. }
  155. }],
  156. [/[^\$`]+/, 'string'],
  157. [/@escapes/, 'string.escape'],
  158. [/`./, 'string.escape.invalid'],
  159. [/\$[\w]+/, {
  160. cases: {
  161. '$S2=="': 'variable',
  162. '@default': 'string'
  163. }
  164. }],
  165. ],
  166. comment: [
  167. [/[^#\.]+/, 'comment'],
  168. [/#>/, 'comment', '@pop'],
  169. [/(\.)(@helpKeywords)(?!\w)/, { token: 'comment.keyword.$2' }],
  170. [/[\.#]/, 'comment']
  171. ],
  172. },
  173. };
  174. });