当前位置: 首页>>代码示例>>C#>>正文


C# Token.SetIsCommandArgument方法代码示例

本文整理汇总了C#中System.Management.Automation.Language.Token.SetIsCommandArgument方法的典型用法代码示例。如果您正苦于以下问题:C# Token.SetIsCommandArgument方法的具体用法?C# Token.SetIsCommandArgument怎么用?C# Token.SetIsCommandArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Language.Token的用法示例。


在下文中一共展示了Token.SetIsCommandArgument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCommandArgument

        private ExpressionAst GetCommandArgument(CommandArgumentContext context, Token token)
        {
            ExpressionAst ast;
            List<ExpressionAst> source = null;
            Token token2 = null;
            bool flag = false;
        Label_0006:
            switch (token.Kind)
            {
                case TokenKind.Variable:
                case TokenKind.SplattedVariable:
                case TokenKind.Number:
                case TokenKind.StringLiteral:
                case TokenKind.StringExpandable:
                case TokenKind.HereStringLiteral:
                case TokenKind.HereStringExpandable:
                case TokenKind.LParen:
                case TokenKind.LCurly:
                case TokenKind.AtParen:
                case TokenKind.AtCurly:
                case TokenKind.DollarParen:
                    this.UngetToken(token);
                    ast = this.PrimaryExpressionRule(true);
                    break;

                case TokenKind.Generic:
                    {
                        if ((context & CommandArgumentContext.CommandName) != 0)
                        {
                            token.TokenFlags |= TokenFlags.CommandName;
                        }
                        StringToken token3 = (StringToken)token;
                        StringExpandableToken expandableStringToken = token3 as StringExpandableToken;
                        if ((expandableStringToken != null) && (context != CommandArgumentContext.CommandName))
                        {
                            List<ExpressionAst> nestedExpressions = this.ParseNestedExpressions(expandableStringToken);
                            ast = new ExpandableStringExpressionAst(expandableStringToken, expandableStringToken.Value, expandableStringToken.FormatString, nestedExpressions);
                        }
                        else
                        {
                            ast = new StringConstantExpressionAst(token3.Extent, token3.Value, StringConstantType.BareWord);
                            if (string.Equals(token3.Value, "--%", StringComparison.OrdinalIgnoreCase))
                            {
                                flag = true;
                            }
                        }
                        break;
                    }
                case TokenKind.NewLine:
                case TokenKind.EndOfInput:
                case TokenKind.RParen:
                case TokenKind.RCurly:
                case TokenKind.Semi:
                case TokenKind.AndAnd:
                case TokenKind.OrOr:
                case TokenKind.Ampersand:
                case TokenKind.Pipe:
                case TokenKind.Comma:
                case TokenKind.MinusMinus:
                case TokenKind.Redirection:
                case TokenKind.RedirectInStd:
                    this.UngetToken(token);
                    if (token2 != null)
                    {
                        this.ReportIncompleteInput(After(token2), ParserStrings.MissingExpression, new object[] { "," });
                        return new ErrorExpressionAst(ExtentOf(source.First<ExpressionAst>(), token2), (IEnumerable<Ast>)source);
                    }
                    return null;

                default:
                    ast = new StringConstantExpressionAst(token.Extent, token.Text, StringConstantType.BareWord);
                    switch (context)
                    {
                        case CommandArgumentContext.CommandName:
                        case CommandArgumentContext.CommandNameAfterInvocationOperator:
                            token.TokenFlags |= TokenFlags.CommandName;
                            break;

                        case CommandArgumentContext.FileName:
                        case CommandArgumentContext.CommandArgument:
                        case CommandArgumentContext.SwitchCondition:
                            token.SetIsCommandArgument();
                            break;
                    }
                    break;
            }
            if ((context == CommandArgumentContext.CommandArgument) && !flag)
            {
                token = this.PeekToken();
                if (token.Kind == TokenKind.Comma)
                {
                    token2 = token;
                    if (source == null)
                    {
                        source = new List<ExpressionAst>();
                    }
                    source.Add(ast);
                    this.SkipToken();
                    this.SkipNewlines();
                    token = this.NextToken();
//.........这里部分代码省略.........
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:Parser.cs

示例2: GetCommandArgument


//.........这里部分代码省略.........
                    case TokenKind.StringExpandable:
                    case TokenKind.HereStringLiteral:
                    case TokenKind.StringLiteral:
                    case TokenKind.LParen:
                    case TokenKind.DollarParen:
                    case TokenKind.AtParen:
                    case TokenKind.AtCurly:
                    case TokenKind.LCurly:
                        UngetToken(token);
                        exprAst = PrimaryExpressionRule(withMemberAccess: true);
                        Diagnostics.Assert(exprAst != null, "PrimaryExpressionRule should never return null");
                        break;

                    case TokenKind.Generic:
                        if ((context & CommandArgumentContext.CommandName) != 0)
                        {
                            token.TokenFlags |= TokenFlags.CommandName;
                        }

                        var genericToken = (StringToken)token;
                        var expandableToken = genericToken as StringExpandableToken;
                        // A command name w/o invocation operator is not expandable even if the token has expandable parts
                        // If we have seen an invocation operator, the command name is expandable.
                        if (expandableToken != null && context != CommandArgumentContext.CommandName)
                        {
                            var nestedExpressions = ParseNestedExpressions(expandableToken);
                            exprAst = new ExpandableStringExpressionAst(expandableToken, expandableToken.Value,
                                                                        expandableToken.FormatString, nestedExpressions);
                        }
                        else
                        {
                            exprAst = new StringConstantExpressionAst(genericToken.Extent, genericToken.Value, StringConstantType.BareWord);

                            // If this is a verbatim argument, then don't continue peeking
                            if (String.Equals(genericToken.Value, VERBATIM_ARGUMENT, StringComparison.OrdinalIgnoreCase))
                            {
                                foundVerbatimArgument = true;
                            }
                        }
                        break;

                    default:
                        exprAst = new StringConstantExpressionAst(token.Extent, token.Text, StringConstantType.BareWord);

                        // A command/argument that matches a keyword isn't really a keyword, so don't color it that way
                        token.TokenFlags &= ~TokenFlags.Keyword;

                        switch (context)
                        {
                            case CommandArgumentContext.CommandName:
                            case CommandArgumentContext.CommandNameAfterInvocationOperator:
                                token.TokenFlags |= TokenFlags.CommandName;
                                break;
                            case CommandArgumentContext.FileName:
                            case CommandArgumentContext.CommandArgument:
                            case CommandArgumentContext.SwitchCondition:
                                token.SetIsCommandArgument();
                                break;
                        }
                        break;
                }

                if (context != CommandArgumentContext.CommandArgument)
                {
                    break;
                }

                if (foundVerbatimArgument)
                {
                    break;
                }

                token = PeekToken();
                if (token.Kind != TokenKind.Comma)
                {
                    break;
                }
                commaToken = token;
                if (commandArgs == null)
                {
                    commandArgs = new List<ExpressionAst>();
                }
                commandArgs.Add(exprAst);

                SkipToken();
                SkipNewlines();

                token = NextToken();
            }

            Diagnostics.Assert(commandArgs != null || exprAst != null, "How did that happen?");

            if (commandArgs != null)
            {
                commandArgs.Add(exprAst);
                return new ArrayLiteralAst(ExtentOf(commandArgs[0], commandArgs[commandArgs.Count - 1]), commandArgs);
            }

            return exprAst;
        }
开发者ID:dfinke,项目名称:powershell,代码行数:101,代码来源:Parser.cs


注:本文中的System.Management.Automation.Language.Token.SetIsCommandArgument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。