MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections;5using System.Collections.Generic;6using System.Collections.ObjectModel;7using System.Diagnostics.CodeAnalysis;8using System.Globalization;9using System.Management.Automation.Internal;10using System.Text;11 12namespace System.Management.Automation.Language13{14 /// <summary>15 /// The specific kind of token.16 /// </summary>17 [SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]18 public enum TokenKind19 {20 // When adding any new tokens, be sure to update the following tables:21 // * TokenTraits.StaticTokenFlags22 // * TokenTraits.Text23 24 #region Unclassified Tokens25 26 /// <summary>An unknown token, signifies an error condition.</summary>27 Unknown = 0,28 29 /// <summary>30 /// A variable token, always begins with '$' and followed by the variable name, possibly enclose in curly braces.31 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.VariableToken"/>.32 /// </summary>33 Variable = 1,34 35 /// <summary>36 /// A splatted variable token, always begins with '@' and followed by the variable name.37 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.VariableToken"/>.38 /// </summary>39 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]40 SplattedVariable = 2,41 42 /// <summary>43 /// A parameter to a command, always begins with a dash ('-'), followed by the parameter name.44 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.ParameterToken"/>.45 /// </summary>46 Parameter = 3,47 48 /// <summary>49 /// Any numerical literal token.50 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.NumberToken"/>.51 /// </summary>52 Number = 4,53 54 /// <summary>55 /// A label token - always begins with ':', followed by the label name.56 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.LabelToken"/>.57 /// </summary>58 Label = 5,59 60 /// <summary>61 /// A simple identifier, always begins with a letter or '_', and is followed by letters, numbers, or '_'.62 /// </summary>63 Identifier = 6,64 65 /// <summary>66 /// A token that is only valid as a command name, command argument, function name, or configuration name. It may contain67 /// characters not allowed in identifiers.68 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringLiteralToken"/>69 /// or <see cref="System.Management.Automation.Language.StringExpandableToken"/> if the token contains variable70 /// references or subexpressions.71 /// </summary>72 Generic = 7,73 74 /// <summary>A newline (one of '\n', '\r', or '\r\n').</summary>75 NewLine = 8,76 77 /// <summary>A line continuation (backtick followed by newline).</summary>78 LineContinuation = 9,79 80 /// <summary>A single line comment, or a delimited comment.</summary>81 Comment = 10,82 83 /// <summary>Marks the end of the input script or file.</summary>84 EndOfInput = 11,85 86 #endregion Unclassified Tokens87 88 #region Strings89 90 /// <summary>91 /// A single quoted string literal.92 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringLiteralToken"/>.93 /// </summary>94 StringLiteral = 12,95 96 /// <summary>97 /// A double quoted string literal.98 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringExpandableToken"/>99 /// even if there are no nested tokens to expand.100 /// </summary>101 StringExpandable = 13,102 103 /// <summary>104 /// A single quoted here string literal.105 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringLiteralToken"/>.106 /// </summary>107 HereStringLiteral = 14,108 109 /// <summary>110 /// A double quoted here string literal.111 /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringExpandableToken"/>.112 /// even if there are no nested tokens to expand.113 /// </summary>114 HereStringExpandable = 15,115 116 #endregion Strings117 118 #region Punctuators119 120 /// <summary>The opening parenthesis token '('.</summary>121 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]122 LParen = 16,123 124 /// <summary>The closing parenthesis token ')'.</summary>125 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]126 RParen = 17,127 128 /// <summary>The opening curly brace token '{'.</summary>129 LCurly = 18,130 131 /// <summary>The closing curly brace token '}'.</summary>132 RCurly = 19,133 134 /// <summary>The opening square brace token '['.</summary>135 LBracket = 20,136 137 /// <summary>The closing square brace token ']'.</summary>138 RBracket = 21,139 140 /// <summary>The opening token of an array expression '@('.</summary>141 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]142 AtParen = 22,143 144 /// <summary>The opening token of a hash expression '@{'.</summary>145 AtCurly = 23,146 147 /// <summary>The opening token of a sub-expression '$('.</summary>148 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]149 DollarParen = 24,150 151 /// <summary>The statement terminator ';'.</summary>152 Semi = 25,153 154 #endregion Punctuators155 156 #region Operators157 158 /// <summary>The (unimplemented) operator '&&'.</summary>159 AndAnd = 26,160 161 /// <summary>The (unimplemented) operator '||'.</summary>162 OrOr = 27,163 164 /// <summary>The invocation operator '&'.</summary>165 Ampersand = 28,166 167 /// <summary>The pipe operator '|'.</summary>168 Pipe = 29,169 170 /// <summary>The unary or binary array operator ','.</summary>171 Comma = 30,172 173 /// <summary>The pre-decrement operator '--'.</summary>174 MinusMinus = 31,175 176 /// <summary>The pre-increment operator '++'.</summary>177 PlusPlus = 32,178 179 /// <summary>The range operator '..'.</summary>180 DotDot = 33,181 182 /// <summary>The static member access operator '::'.</summary>183 ColonColon = 34,184 185 /// <summary>The instance member access or dot source invocation operator '.'.</summary>186 Dot = 35,187 188 /// <summary>The logical not operator '!'.</summary>189 Exclaim = 36,190 191 /// <summary>The multiplication operator '*'.</summary>192 Multiply = 37,193 194 /// <summary>The division operator '/'.</summary>195 Divide = 38,196 197 /// <summary>The modulo division (remainder) operator '%'.</summary>198 Rem = 39,199 200 /// <summary>The addition operator '+'.</summary>201 Plus = 40,202 203 /// <summary>The subtraction operator '-'.</summary>204 Minus = 41,205 206 /// <summary>The assignment operator '='.</summary>207 Equals = 42,208 209 /// <summary>The addition assignment operator '+='.</summary>210 PlusEquals = 43,211 212 /// <summary>The subtraction assignment operator '-='.</summary>213 MinusEquals = 44,214 215 /// <summary>The multiplication assignment operator '*='.</summary>216 MultiplyEquals = 45,217 218 /// <summary>The division assignment operator '/='.</summary>219 DivideEquals = 46,220 221 /// <summary>The modulo division (remainder) assignment operator '%='.</summary>222 RemainderEquals = 47,223 224 /// <summary>A redirection operator such as '2>&1' or '>>'.</summary>225 Redirection = 48,226 227 /// <summary>The (unimplemented) stdin redirection operator '<'.</summary>228 RedirectInStd = 49,229 230 /// <summary>The string format operator '-f'.</summary>231 Format = 50,232 233 /// <summary>The logical not operator '-not'.</summary>234 Not = 51,235 236 /// <summary>The bitwise not operator '-bnot'.</summary>237 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]238 Bnot = 52,239 240 /// <summary>The logical and operator '-and'.</summary>241 And = 53,242 243 /// <summary>The logical or operator '-or'.</summary>244 Or = 54,245 246 /// <summary>The logical exclusive or operator '-xor'.</summary>247 Xor = 55,248 249 /// <summary>The bitwise and operator '-band'.</summary>250 Band = 56,251 252 /// <summary>The bitwise or operator '-bor'.</summary>253 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]254 Bor = 57,255 256 /// <summary>The bitwise exclusive or operator '-xor'.</summary>257 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]258 Bxor = 58,259 260 /// <summary>The join operator '-join'.</summary>261 Join = 59,262 263 /// <summary>The case insensitive equal operator '-ieq' or '-eq'.</summary>264 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]265 Ieq = 60,266 267 /// <summary>The case insensitive not equal operator '-ine' or '-ne'.</summary>268 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]269 Ine = 61,270 271 /// <summary>The case insensitive greater than or equal operator '-ige' or '-ge'.</summary>272 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]273 Ige = 62,274 275 /// <summary>The case insensitive greater than operator '-igt' or '-gt'.</summary>276 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]277 Igt = 63,278 279 /// <summary>The case insensitive less than operator '-ilt' or '-lt'.</summary>280 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]281 Ilt = 64,282 283 /// <summary>The case insensitive less than or equal operator '-ile' or '-le'.</summary>284 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]285 Ile = 65,286 287 /// <summary>The case insensitive like operator '-ilike' or '-like'.</summary>288 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]289 Ilike = 66,290 291 /// <summary>The case insensitive not like operator '-inotlike' or '-notlike'.</summary>292 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]293 Inotlike = 67,294 295 /// <summary>The case insensitive match operator '-imatch' or '-match'.</summary>296 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]297 Imatch = 68,298 299 /// <summary>The case insensitive not match operator '-inotmatch' or '-notmatch'.</summary>300 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]301 Inotmatch = 69,302 303 /// <summary>The case insensitive replace operator '-ireplace' or '-replace'.</summary>304 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]305 Ireplace = 70,306 307 /// <summary>The case insensitive contains operator '-icontains' or '-contains'.</summary>308 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]309 Icontains = 71,310 311 /// <summary>The case insensitive notcontains operator '-inotcontains' or '-notcontains'.</summary>312 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]313 Inotcontains = 72,314 315 /// <summary>The case insensitive in operator '-iin' or '-in'.</summary>316 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]317 Iin = 73,318 319 /// <summary>The case insensitive notin operator '-inotin' or '-notin'</summary>320 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]321 Inotin = 74,322 323 /// <summary>The case insensitive split operator '-isplit' or '-split'.</summary>324 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]325 Isplit = 75,326 327 /// <summary>The case sensitive equal operator '-ceq'.</summary>328 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]329 Ceq = 76,330 331 /// <summary>The case sensitive not equal operator '-cne'.</summary>332 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]333 Cne = 77,334 335 /// <summary>The case sensitive greater than or equal operator '-cge'.</summary>336 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]337 Cge = 78,338 339 /// <summary>The case sensitive greater than operator '-cgt'.</summary>340 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]341 Cgt = 79,342 343 /// <summary>The case sensitive less than operator '-clt'.</summary>344 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]345 Clt = 80,346 347 /// <summary>The case sensitive less than or equal operator '-cle'.</summary>348 Cle = 81,349 350 /// <summary>The case sensitive like operator '-clike'.</summary>351 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]352 Clike = 82,353 354 /// <summary>The case sensitive notlike operator '-cnotlike'.</summary>355 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]356 Cnotlike = 83,357 358 /// <summary>The case sensitive match operator '-cmatch'.</summary>359 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]360 Cmatch = 84,361 362 /// <summary>The case sensitive not match operator '-cnotmatch'.</summary>363 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]364 Cnotmatch = 85,365 366 /// <summary>The case sensitive replace operator '-creplace'.</summary>367 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]368 Creplace = 86,369 370 /// <summary>The case sensitive contains operator '-ccontains'.</summary>371 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]372 Ccontains = 87,373 374 /// <summary>The case sensitive not contains operator '-cnotcontains'.</summary>375 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]376 Cnotcontains = 88,377 378 /// <summary>The case sensitive in operator '-cin'.</summary>379 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]380 Cin = 89,381 382 /// <summary>The case sensitive not in operator '-notin'.</summary>383 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]384 Cnotin = 90,385 386 /// <summary>The case sensitive split operator '-csplit'.</summary>387 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]388 Csplit = 91,389 390 /// <summary>The type test operator '-is'.</summary>391 Is = 92,392 393 /// <summary>The type test operator '-isnot'.</summary>394 IsNot = 93,395 396 /// <summary>The type conversion operator '-as'.</summary>397 As = 94,398 399 /// <summary>The post-increment operator '++'.</summary>400 PostfixPlusPlus = 95,401 402 /// <summary>The post-decrement operator '--'.</summary>403 PostfixMinusMinus = 96,404 405 /// <summary>The shift left operator.</summary>406 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]407 Shl = 97,408 409 /// <summary>The shift right operator.</summary>410 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]411 Shr = 98,412 413 /// <summary>The PS class base class and implemented interfaces operator ':'. Also used in base class ctor calls.</summary>414 Colon = 99,415 416 /// <summary>The ternary operator '?'.</summary>417 QuestionMark = 100,418 419 /// <summary>The null conditional assignment operator '??='.</summary>420 QuestionQuestionEquals = 101,421 422 /// <summary>The null coalesce operator '??'.</summary>423 QuestionQuestion = 102,424 425 /// <summary>The null conditional member access operator '?.'.</summary>426 QuestionDot = 103,427 428 /// <summary>The null conditional index access operator '?[]'.</summary>429 QuestionLBracket = 104,430 431 #endregion Operators432 433 #region Keywords434 435 /// <summary>The 'begin' keyword.</summary>436 Begin = 119,437 438 /// <summary>The 'break' keyword.</summary>439 Break = 120,440 441 /// <summary>The 'catch' keyword.</summary>442 Catch = 121,443 444 /// <summary>The 'class' keyword.</summary>445 Class = 122,446 447 /// <summary>The 'continue' keyword.</summary>448 Continue = 123,449 450 /// <summary>The 'data' keyword.</summary>451 Data = 124,452 453 /// <summary>The (unimplemented) 'define' keyword.</summary>454 Define = 125,455 456 /// <summary>The 'do' keyword.</summary>457 Do = 126,458 459 /// <summary>The 'dynamicparam' keyword.</summary>460 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]461 Dynamicparam = 127,462 463 /// <summary>The 'else' keyword.</summary>464 Else = 128,465 466 /// <summary>The 'elseif' keyword.</summary>467 ElseIf = 129,468 469 /// <summary>The 'end' keyword.</summary>470 End = 130,471 472 /// <summary>The 'exit' keyword.</summary>473 Exit = 131,474 475 /// <summary>The 'filter' keyword.</summary>476 Filter = 132,477 478 /// <summary>The 'finally' keyword.</summary>479 Finally = 133,480 481 /// <summary>The 'for' keyword.</summary>482 For = 134,483 484 /// <summary>The 'foreach' keyword.</summary>485 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]486 Foreach = 135,487 488 /// <summary>The (unimplemented) 'from' keyword.</summary>489 From = 136,490 491 /// <summary>The 'function' keyword.</summary>492 Function = 137,493 494 /// <summary>The 'if' keyword.</summary>495 If = 138,496 497 /// <summary>The 'in' keyword.</summary>498 In = 139,499 500 /// <summary>The 'param' keyword.</summary>501 [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]502 Param = 140,503 504 /// <summary>The 'process' keyword.</summary>505 Process = 141,506 507 /// <summary>The 'return' keyword.</summary>508 Return = 142,509 510 /// <summary>The 'switch' keyword.</summary>511 Switch = 143,512 513 /// <summary>The 'throw' keyword.</summary>514 Throw = 144,515 516 /// <summary>The 'trap' keyword.</summary>517 Trap = 145,518 519 /// <summary>The 'try' keyword.</summary>520 Try = 146,521 522 /// <summary>The 'until' keyword.</summary>523 Until = 147,524 525 /// <summary>The (unimplemented) 'using' keyword.</summary>526 Using = 148,527 528 /// <summary>The (unimplemented) 'var' keyword.</summary>529 Var = 149,530 531 /// <summary>The 'while' keyword.</summary>532 While = 150,533 534 /// <summary>The 'workflow' keyword.</summary>535 Workflow = 151,536 537 /// <summary>The 'parallel' keyword.</summary>538 Parallel = 152,539 540 /// <summary>The 'sequence' keyword.</summary>541 Sequence = 153,542 543 /// <summary>The 'InlineScript' keyword</summary>544 InlineScript = 154,545 546 /// <summary>The "configuration" keyword</summary>547 Configuration = 155,548 549 /// <summary>The token kind for dynamic keywords</summary>550 DynamicKeyword = 156,551 552 /// <summary>The 'public' keyword</summary>553 Public = 157,554 555 /// <summary>The 'private' keyword</summary>556 Private = 158,557 558 /// <summary>The 'static' keyword</summary>559 Static = 159,560 561 /// <summary>The 'interface' keyword</summary>562 Interface = 160,563 564 /// <summary>The 'enum' keyword</summary>565 Enum = 161,566 567 /// <summary>The 'namespace' keyword</summary>568 Namespace = 162,569 570 /// <summary>The 'module' keyword</summary>571 Module = 163,572 573 /// <summary>The 'type' keyword</summary>574 Type = 164,575 576 /// <summary>The 'assembly' keyword</summary>577 Assembly = 165,578 579 /// <summary>The 'command' keyword</summary>580 Command = 166,581 582 /// <summary>The 'hidden' keyword</summary>583 Hidden = 167,584 585 /// <summary>The 'base' keyword</summary>586 Base = 168,587 588 /// <summary>The 'default' keyword</summary>589 Default = 169,590 591 /// <summary>The 'clean' keyword.</summary>592 Clean = 170,593 594 #endregion Keywords595 }596 597 /// <summary>598 /// Flags that specify additional information about a given token.599 /// </summary>600 [Flags]601 public enum TokenFlags602 {603 /// <summary>604 /// The token has no flags.605 /// </summary>606 None = 0x00000000,607 608 #region Precedence Values609 610 /// <summary>611 /// The precedence of the logical operators '-and', '-or', and '-xor'.612 /// </summary>613 BinaryPrecedenceLogical = 0x1,614 615 /// <summary>616 /// The precedence of the bitwise operators '-band', '-bor', and '-bxor'617 /// </summary>618 BinaryPrecedenceBitwise = 0x2,619 620 /// <summary>621 /// The precedence of comparison operators including: '-eq', '-ne', '-ge', '-gt', '-lt', '-le', '-like', '-notlike',622 /// '-match', '-notmatch', '-replace', '-contains', '-notcontains', '-in', '-notin', '-split', '-join', '-is', '-isnot', '-as',623 /// and all of the case sensitive variants of these operators, if they exists.624 /// </summary>625 BinaryPrecedenceComparison = 0x5,626 627 /// <summary>628 /// The precedence of null coalesce operator '??'.629 /// </summary>630 BinaryPrecedenceCoalesce = 0x7,631 632 /// <summary>633 /// The precedence of the binary operators '+' and '-'.634 /// </summary>635 BinaryPrecedenceAdd = 0x9,636 637 /// <summary>638 /// The precedence of the operators '*', '/', and '%'.639 /// </summary>640 BinaryPrecedenceMultiply = 0xa,641 642 /// <summary>643 /// The precedence of the '-f' operator.644 /// </summary>645 BinaryPrecedenceFormat = 0xc,646 647 /// <summary>648 /// The precedence of the '..' operator.649 /// </summary>650 BinaryPrecedenceRange = 0xd,651 652 #endregion Precedence Values653 654 /// <summary>655 /// A bitmask to get the precedence of binary operators.656 /// </summary>657 BinaryPrecedenceMask = 0x0000000f,658 659 /// <summary>660 /// The token is a keyword.661 /// </summary>662 Keyword = 0x00000010,663 664 /// <summary>665 /// The token is one of the keywords that is a part of a script block: 'begin', 'process', 'end', 'clean', or 'dynamicparam'.666 /// </summary>667 ScriptBlockBlockName = 0x00000020,668 669 /// <summary>670 /// The token is a binary operator.671 /// </summary>672 BinaryOperator = 0x00000100,673 674 /// <summary>675 /// The token is a unary operator.676 /// </summary>677 UnaryOperator = 0x00000200,678 679 /// <summary>680 /// The token is a case sensitive operator such as '-ceq' or '-ccontains'.681 /// </summary>682 CaseSensitiveOperator = 0x00000400,683 684 /// <summary>685 /// The token is a ternary operator '?'.686 /// </summary>687 TernaryOperator = 0x00000800,688 689 /// <summary>690 /// The operators '&', '|', and the member access operators ':' and '::'.691 /// </summary>692 SpecialOperator = 0x00001000,693 694 /// <summary>695 /// The token is one of the assignment operators: '=', '+=', '-=', '*=', '/=', '%=' or '??='696 /// </summary>697 AssignmentOperator = 0x00002000,698 699 /// <summary>700 /// The token is scanned identically in expression mode or command mode.701 /// </summary>702 ParseModeInvariant = 0x00008000,703 704 /// <summary>705 /// The token has some error associated with it. For example, it may be a string missing it's terminator.706 /// </summary>707 TokenInError = 0x00010000,708 709 /// <summary>710 /// The operator is not allowed in restricted language mode or in the data language.711 /// </summary>712 DisallowedInRestrictedMode = 0x00020000,713 714 /// <summary>715 /// The token is either a prefix or postfix '++' or '--'.716 /// </summary>717 PrefixOrPostfixOperator = 0x00040000,718 719 /// <summary>720 /// The token names a command in a pipeline.721 /// </summary>722 CommandName = 0x00080000,723 724 /// <summary>725 /// The token names a member of a class.726 /// </summary>727 MemberName = 0x00100000,728 729 /// <summary>730 /// The token names a type.731 /// </summary>732 TypeName = 0x00200000,733 734 /// <summary>735 /// The token names an attribute.736 /// </summary>737 AttributeName = 0x00400000,738 739 /// <summary>740 /// The token is a valid operator to use when doing constant folding.741 /// </summary>742 // Some operators that could be marked with this flag aren't because the current implementation depends743 // on the execution context (e.g. -split, -join, -like, etc.)744 // If the operator is culture sensitive (e.g. -f), then it shouldn't be marked as suitable for constant745 // folding because evaluation of the operator could differ if the thread's culture changes.746 CanConstantFold = 0x00800000,747 748 /// <summary>749 /// The token is a statement but does not support attributes.750 /// </summary>751 StatementDoesntSupportAttributes = 0x01000000,752 }753 754 /// <summary>755 /// A utility class to get statically known traits and invariant traits about PowerShell tokens.756 /// </summary>757 public static class TokenTraits758 {759 private static readonly TokenFlags[] s_staticTokenFlags = new TokenFlags[]760 {761 #region Flags for unclassified tokens762 763 /* Unknown */ TokenFlags.None,764 /* Variable */ TokenFlags.None,765 /* SplattedVariable */ TokenFlags.None,766 /* Parameter */ TokenFlags.None,767 /* Number */ TokenFlags.None,768 /* Label */ TokenFlags.None,769 /* Identifier */ TokenFlags.None,770 771 /* Generic */ TokenFlags.None,772 /* Newline */ TokenFlags.ParseModeInvariant,773 /* LineContinuation */ TokenFlags.ParseModeInvariant,774 /* Comment */ TokenFlags.ParseModeInvariant,775 /* EndOfInput */ TokenFlags.ParseModeInvariant,776 777 #endregion Flags for unclassified tokens778 779 #region Flags for strings780 781 /* StringLiteral */ TokenFlags.ParseModeInvariant,782 /* StringExpandable */ TokenFlags.ParseModeInvariant,783 /* HereStringLiteral */ TokenFlags.ParseModeInvariant,784 /* HereStringExpandable */ TokenFlags.ParseModeInvariant,785 786 #endregion Flags for strings787 788 #region Flags for punctuators789 790 /* LParen */ TokenFlags.ParseModeInvariant,791 /* RParen */ TokenFlags.ParseModeInvariant,792 /* LCurly */ TokenFlags.ParseModeInvariant,793 /* RCurly */ TokenFlags.ParseModeInvariant,794 /* LBracket */ TokenFlags.None,795 /* RBracket */ TokenFlags.ParseModeInvariant,796 /* AtParen */ TokenFlags.ParseModeInvariant,797 /* AtCurly */ TokenFlags.ParseModeInvariant,798 /* DollarParen */ TokenFlags.ParseModeInvariant,799 /* Semi */ TokenFlags.ParseModeInvariant,800 801 #endregion Flags for punctuators802 803 #region Flags for operators804 805 /* AndAnd */ TokenFlags.ParseModeInvariant,806 /* OrOr */ TokenFlags.ParseModeInvariant,807 /* Ampersand */ TokenFlags.SpecialOperator | TokenFlags.ParseModeInvariant,808 /* Pipe */ TokenFlags.SpecialOperator | TokenFlags.ParseModeInvariant,809 /* Comma */ TokenFlags.UnaryOperator | TokenFlags.ParseModeInvariant,810 /* MinusMinus */ TokenFlags.UnaryOperator | TokenFlags.PrefixOrPostfixOperator | TokenFlags.DisallowedInRestrictedMode,811 /* PlusPlus */ TokenFlags.UnaryOperator | TokenFlags.PrefixOrPostfixOperator | TokenFlags.DisallowedInRestrictedMode,812 /* DotDot */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceRange | TokenFlags.DisallowedInRestrictedMode,813 /* ColonColon */ TokenFlags.SpecialOperator | TokenFlags.DisallowedInRestrictedMode,814 /* Dot */ TokenFlags.SpecialOperator | TokenFlags.DisallowedInRestrictedMode,815 /* Exclaim */ TokenFlags.UnaryOperator | TokenFlags.CanConstantFold,816 /* Multiply */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceMultiply | TokenFlags.CanConstantFold,817 /* Divide */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceMultiply | TokenFlags.CanConstantFold,818 /* Rem */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceMultiply | TokenFlags.CanConstantFold,819 /* Plus */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceAdd | TokenFlags.UnaryOperator | TokenFlags.CanConstantFold,820 /* Minus */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceAdd | TokenFlags.UnaryOperator | TokenFlags.CanConstantFold,821 /* Equals */ TokenFlags.AssignmentOperator,822 /* PlusEquals */ TokenFlags.AssignmentOperator,823 /* MinusEquals */ TokenFlags.AssignmentOperator,824 /* MultiplyEquals */ TokenFlags.AssignmentOperator,825 /* DivideEquals */ TokenFlags.AssignmentOperator,826 /* RemainderEquals */ TokenFlags.AssignmentOperator,827 /* Redirection */ TokenFlags.DisallowedInRestrictedMode,828 /* RedirectInStd */ TokenFlags.ParseModeInvariant | TokenFlags.DisallowedInRestrictedMode,829 /* Format */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceFormat | TokenFlags.DisallowedInRestrictedMode,830 /* Not */ TokenFlags.UnaryOperator | TokenFlags.CanConstantFold,831 /* Bnot */ TokenFlags.UnaryOperator | TokenFlags.CanConstantFold,832 /* And */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceLogical | TokenFlags.CanConstantFold,833 /* Or */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceLogical | TokenFlags.CanConstantFold,834 /* Xor */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceLogical | TokenFlags.CanConstantFold,835 /* Band */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceBitwise | TokenFlags.CanConstantFold,836 /* Bor */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceBitwise | TokenFlags.CanConstantFold,837 /* Bxor */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceBitwise | TokenFlags.CanConstantFold,838 /* Join */ TokenFlags.BinaryOperator | TokenFlags.UnaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.DisallowedInRestrictedMode,839 /* Ieq */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,840 /* Ine */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,841 /* Ige */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,842 /* Igt */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,843 /* Ilt */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,844 /* Ile */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,845 /* Ilike */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,846 /* Inotlike */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,847 /* Imatch */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.DisallowedInRestrictedMode,848 /* Inotmatch */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.DisallowedInRestrictedMode,849 /* Ireplace */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.DisallowedInRestrictedMode,850 /* Icontains */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,851 /* Inotcontains */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,852 /* Iin */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,853 /* Inotin */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,854 /* Isplit */ TokenFlags.BinaryOperator | TokenFlags.UnaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.DisallowedInRestrictedMode,855 /* Ceq */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,856 /* Cne */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,857 /* Cge */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,858 /* Cgt */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,859 /* Clt */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,860 /* Cle */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,861 /* Clike */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,862 /* Cnotlike */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,863 /* Cmatch */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator | TokenFlags.DisallowedInRestrictedMode,864 /* Cnotmatch */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator | TokenFlags.DisallowedInRestrictedMode,865 /* Creplace */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator | TokenFlags.DisallowedInRestrictedMode,866 /* Ccontains */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,867 /* Cnotcontains */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,868 /* Cin */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,869 /* Cnotin */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator,870 /* Csplit */ TokenFlags.BinaryOperator | TokenFlags.UnaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CaseSensitiveOperator | TokenFlags.DisallowedInRestrictedMode,871 /* Is */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,872 /* IsNot */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison,873 /* As */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.DisallowedInRestrictedMode,874 /* PostFixPlusPlus */ TokenFlags.UnaryOperator | TokenFlags.PrefixOrPostfixOperator | TokenFlags.DisallowedInRestrictedMode,875 /* PostFixMinusMinus */ TokenFlags.UnaryOperator | TokenFlags.PrefixOrPostfixOperator | TokenFlags.DisallowedInRestrictedMode,876 /* Shl */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CanConstantFold,877 /* Shr */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CanConstantFold,878 /* Colon */ TokenFlags.SpecialOperator | TokenFlags.DisallowedInRestrictedMode,879 /* QuestionMark */ TokenFlags.TernaryOperator | TokenFlags.DisallowedInRestrictedMode,880 /* QuestionQuestionEquals */ TokenFlags.AssignmentOperator,881 /* QuestionQuestion */ TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceCoalesce,882 /* QuestionDot */ TokenFlags.SpecialOperator | TokenFlags.DisallowedInRestrictedMode,883 /* QuestionLBracket */ TokenFlags.None,884 /* Reserved slot 7 */ TokenFlags.None,885 /* Reserved slot 8 */ TokenFlags.None,886 /* Reserved slot 9 */ TokenFlags.None,887 /* Reserved slot 10 */ TokenFlags.None,888 /* Reserved slot 11 */ TokenFlags.None,889 /* Reserved slot 12 */ TokenFlags.None,890 /* Reserved slot 13 */ TokenFlags.None,891 /* Reserved slot 14 */ TokenFlags.None,892 /* Reserved slot 15 */ TokenFlags.None,893 /* Reserved slot 16 */ TokenFlags.None,894 /* Reserved slot 17 */ TokenFlags.None,895 /* Reserved slot 18 */ TokenFlags.None,896 /* Reserved slot 19 */ TokenFlags.None,897 /* Reserved slot 20 */ TokenFlags.None,898 899 #endregion Flags for operators900 901 #region Flags for keywords902 903 /* Begin */ TokenFlags.Keyword | TokenFlags.ScriptBlockBlockName,904 /* Break */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,905 /* Catch */ TokenFlags.Keyword,906 /* Class */ TokenFlags.Keyword,907 /* Continue */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,908 /* Data */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,909 /* Define */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,910 /* Do */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,911 /* Dynamicparam */ TokenFlags.Keyword | TokenFlags.ScriptBlockBlockName,912 /* Else */ TokenFlags.Keyword,913 /* ElseIf */ TokenFlags.Keyword,914 /* End */ TokenFlags.Keyword | TokenFlags.ScriptBlockBlockName,915 /* Exit */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,916 /* Filter */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,917 /* Finally */ TokenFlags.Keyword,918 /* For */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,919 /* Foreach */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,920 /* From */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,921 /* Function */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,922 /* If */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,923 /* In */ TokenFlags.Keyword,924 /* Param */ TokenFlags.Keyword,925 /* Process */ TokenFlags.Keyword | TokenFlags.ScriptBlockBlockName,926 /* Return */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,927 /* Switch */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,928 /* Throw */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,929 /* Trap */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,930 /* Try */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,931 /* Until */ TokenFlags.Keyword,932 /* Using */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,933 /* Var */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,934 /* While */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,935 /* Workflow */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,936 /* Parallel */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,937 /* Sequence */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,938 /* InlineScript */ TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes,939 /* Configuration */ TokenFlags.Keyword,940 /* <dynamic keyword> */ TokenFlags.Keyword,941 /* Public */ TokenFlags.Keyword,942 /* Private */ TokenFlags.Keyword,943 /* Static */ TokenFlags.Keyword,944 /* Interface */ TokenFlags.Keyword,945 /* Enum */ TokenFlags.Keyword,946 /* Namespace */ TokenFlags.Keyword,947 /* Module */ TokenFlags.Keyword,948 /* Type */ TokenFlags.Keyword,949 /* Assembly */ TokenFlags.Keyword,950 /* Command */ TokenFlags.Keyword,951 /* Hidden */ TokenFlags.Keyword,952 /* Base */ TokenFlags.Keyword,953 /* Default */ TokenFlags.Keyword,954 /* Clean */ TokenFlags.Keyword | TokenFlags.ScriptBlockBlockName,955 956 #endregion Flags for keywords957 };958 959 private static readonly string[] s_tokenText = new string[]960 {961 #region Text for unclassified tokens962 963 /* Unknown */ "unknown",964 /* Variable */ "var",965 /* SplattedVariable */ "@var",966 /* Parameter */ "param",967 /* Number */ "number",968 /* Label */ "label",969 /* Identifier */ "ident",970 971 /* Generic */ "generic",972 /* Newline */ "newline",973 /* LineContinuation */ "line continuation",974 /* Comment */ "comment",975 /* EndOfInput */ "eof",976 977 #endregion Text for unclassified tokens978 979 #region Text for strings980 981 /* StringLiteral */ "sqstr",982 /* StringExpandable */ "dqstr",983 /* HereStringLiteral */ "sq here string",984 /* HereStringExpandable */ "dq here string",985 986 #endregion Text for strings987 988 #region Text for punctuators989 990 /* LParen */ "(",991 /* RParen */ ")",992 /* LCurly */ "{",993 /* RCurly */ "}",994 /* LBracket */ "[",995 /* RBracket */ "]",996 /* AtParen */ "@(",997 /* AtCurly */ "@{",998 /* DollarParen */ "$(",999 /* Semi */ ";",1000 1001 #endregion Text for punctuators1002 1003 #region Text for operators1004 1005 /* AndAnd */ "&&",1006 /* OrOr */ "||",1007 /* Ampersand */ "&",1008 /* Pipe */ "|",1009 /* Comma */ ",",1010 /* MinusMinus */ "--",1011 /* PlusPlus */ "++",1012 /* DotDot */ "..",1013 /* ColonColon */ "::",1014 /* Dot */ ".",1015 /* Exclaim */ "!",1016 /* Multiply */ "*",1017 /* Divide */ "/",1018 /* Rem */ "%",1019 /* Plus */ "+",1020 /* Minus */ "-",1021 /* Equals */ "=",1022 /* PlusEquals */ "+=",1023 /* MinusEquals */ "-=",1024 /* MultiplyEquals */ "*=",1025 /* DivideEquals */ "/=",1026 /* RemainderEquals */ "%=",1027 /* Redirection */ "redirection",1028 /* RedirectInStd */ "<",1029 /* Format */ "-f",1030 /* Not */ "-not",1031 /* Bnot */ "-bnot",1032 /* And */ "-and",1033 /* Or */ "-or",1034 /* Xor */ "-xor",1035 /* Band */ "-band",1036 /* Bor */ "-bor",1037 /* Bxor */ "-bxor",1038 /* Join */ "-join",1039 /* Ieq */ "-eq",1040 /* Ine */ "-ne",1041 /* Ige */ "-ge",1042 /* Igt */ "-gt",1043 /* Ilt */ "-lt",1044 /* Ile */ "-le",1045 /* Ilike */ "-ilike",1046 /* Inotlike */ "-inotlike",1047 /* Imatch */ "-imatch",1048 /* Inotmatch */ "-inotmatch",1049 /* Ireplace */ "-ireplace",1050 /* Icontains */ "-icontains",1051 /* Inotcontains */ "-inotcontains",1052 /* Iin */ "-iin",1053 /* Inotin */ "-inotin",1054 /* Isplit */ "-isplit",1055 /* Ceq */ "-ceq",1056 /* Cne */ "-cne",1057 /* Cge */ "-cge",1058 /* Cgt */ "-cgt",1059 /* Clt */ "-clt",1060 /* Cle */ "-cle",1061 /* Clike */ "-clike",1062 /* Cnotlike */ "-cnotlike",1063 /* Cmatch */ "-cmatch",1064 /* Cnotmatch */ "-cnotmatch",1065 /* Creplace */ "-creplace",1066 /* Ccontains */ "-ccontains",1067 /* Cnotcontains */ "-cnotcontains",1068 /* Cin */ "-cin",1069 /* Cnotin */ "-cnotin",1070 /* Csplit */ "-csplit",1071 /* Is */ "-is",1072 /* IsNot */ "-isnot",1073 /* As */ "-as",1074 /* PostFixPlusPlus */ "++",1075 /* PostFixMinusMinus */ "--",1076 /* Shl */ "-shl",1077 /* Shr */ "-shr",1078 /* Colon */ ":",1079 /* QuestionMark */ "?",1080 /* QuestionQuestionEquals */ "??=",1081 /* QuestionQuestion */ "??",1082 /* QuestionDot */ "?.",1083 /* QuestionLBracket */ "?[",1084 /* Reserved slot 7 */ string.Empty,1085 /* Reserved slot 8 */ string.Empty,1086 /* Reserved slot 9 */ string.Empty,1087 /* Reserved slot 10 */ string.Empty,1088 /* Reserved slot 11 */ string.Empty,1089 /* Reserved slot 12 */ string.Empty,1090 /* Reserved slot 13 */ string.Empty,1091 /* Reserved slot 14 */ string.Empty,1092 /* Reserved slot 15 */ string.Empty,1093 /* Reserved slot 16 */ string.Empty,1094 /* Reserved slot 17 */ string.Empty,1095 /* Reserved slot 18 */ string.Empty,1096 /* Reserved slot 19 */ string.Empty,1097 /* Reserved slot 20 */ string.Empty,1098 1099 #endregion Text for operators1100 1101 #region Text for keywords1102 1103 /* Begin */ "begin",1104 /* Break */ "break",1105 /* Catch */ "catch",1106 /* Class */ "class",1107 /* Continue */ "continue",1108 /* Data */ "data",1109 /* Define */ "define",1110 /* Do */ "do",1111 /* Dynamicparam */ "dynamicparam",1112 /* Else */ "else",1113 /* ElseIf */ "elseif",1114 /* End */ "end",1115 /* Exit */ "exit",1116 /* Filter */ "filter",1117 /* Finally */ "finally",1118 /* For */ "for",1119 /* Foreach */ "foreach",1120 /* From */ "from",1121 /* Function */ "function",1122 /* If */ "if",1123 /* In */ "in",1124 /* Param */ "param",1125 /* Process */ "process",1126 /* Return */ "return",1127 /* Switch */ "switch",1128 /* Throw */ "throw",1129 /* Trap */ "trap",1130 /* Try */ "try",1131 /* Until */ "until",1132 /* Using */ "using",1133 /* Var */ "var",1134 /* While */ "while",1135 /* Workflow */ "workflow",1136 /* Parallel */ "parallel",1137 /* Sequence */ "sequence",1138 /* InlineScript */ "inlinescript",1139 /* Configuration */ "configuration",1140 /* <dynamic keyword> */ "<dynamic keyword>",1141 /* Public */ "public",1142 /* Private */ "private",1143 /* Static */ "static",1144 /* Interface */ "interface",1145 /* Enum */ "enum",1146 /* Namespace */ "namespace",1147 /* Module */ "module",1148 /* Type */ "type",1149 /* Assembly */ "assembly",1150 /* Command */ "command",1151 /* Hidden */ "hidden",1152 /* Base */ "base",1153 /* Default */ "default",1154 /* Clean */ "clean",1155 1156 #endregion Text for keywords1157 };1158 1159#if DEBUG1160 static TokenTraits()1161 {1162 Diagnostics.Assert(1163 s_staticTokenFlags.Length == ((int)TokenKind.Clean + 1),1164 "Table size out of sync with enum - _staticTokenFlags");1165 Diagnostics.Assert(1166 s_tokenText.Length == ((int)TokenKind.Clean + 1),1167 "Table size out of sync with enum - _tokenText");1168 // Some random assertions to make sure the enum and the traits are in sync1169 Diagnostics.Assert(GetTraits(TokenKind.Begin) == (TokenFlags.Keyword | TokenFlags.ScriptBlockBlockName),1170 "Table out of sync with enum - flags Begin");1171 Diagnostics.Assert(GetTraits(TokenKind.Workflow) == (TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes),1172 "Table out of sync with enum - flags Workflow");1173 Diagnostics.Assert(GetTraits(TokenKind.Sequence) == (TokenFlags.Keyword | TokenFlags.StatementDoesntSupportAttributes),1174 "Table out of sync with enum - flags Sequence");1175 Diagnostics.Assert(GetTraits(TokenKind.Shr) == (TokenFlags.BinaryOperator | TokenFlags.BinaryPrecedenceComparison | TokenFlags.CanConstantFold),1176 "Table out of sync with enum - flags Shr");1177 Diagnostics.Assert(s_tokenText[(int)TokenKind.Shr].Equals("-shr", StringComparison.OrdinalIgnoreCase),1178 "Table out of sync with enum - text Shr");1179 }1180#endif1181 1182 /// <summary>1183 /// Return all the flags for a given <see cref="TokenKind" />.1184 /// </summary>1185 public static TokenFlags GetTraits(this TokenKind kind)1186 {1187 return s_staticTokenFlags[(int)kind];1188 }1189 1190 /// <summary>1191 /// Return true if the <see cref="TokenKind" /> has the given trait.1192 /// </summary>1193 public static bool HasTrait(this TokenKind kind, TokenFlags flag)1194 {1195 return (GetTraits(kind) & flag) != TokenFlags.None;1196 }1197 1198 internal static int GetBinaryPrecedence(this TokenKind kind)1199 {1200 Diagnostics.Assert(HasTrait(kind, TokenFlags.BinaryOperator), "Token doesn't have binary precedence.");