示例#1
0
        public bool Parse(string commandLine, IVSMacroExpander macros, string execName)
        {
            List <string> args = null;

            try {
                args = TokenizeArgs(commandLine, macros, execName);
            } catch {
                return(false);
            }
            return(Parse(args));
        }
示例#2
0
        List <string> TokenizeArgs(string commandLine, IVSMacroExpander macros, string execName = "")
        {
            List <string> arguments = new List <string>();
            StringBuilder arg       = new StringBuilder();
            bool          foundExec = string.IsNullOrEmpty(execName);

            foreach (Match token in Lexer.Tokenize(commandLine + " "))
            {
                // Additional " " ensures loop will always end with whitespace processing

                if (!foundExec)
                {
                    if (!token.TokenText()
                        .EndsWith(execName,
                                  StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    foundExec = true;
                }

                var tokenType = token.TokenType();
                if (tokenType == Token.Newline)
                {
                    break;
                }
                else if (tokenType == Token.Whitespace)
                {
                    // This will always run at the end of the loop

                    if (arg.Length > 0)
                    {
                        var argData = arg.ToString();
                        arg.Clear();
                        if (argData.StartsWith("@"))
                        {
                            var      workingDir     = macros.ExpandString("$(MSBuildProjectDirectory)");
                            var      optFilePath    = macros.ExpandString(argData.Substring(1));
                            string[] additionalArgs = File.ReadAllLines(
                                Path.Combine(workingDir, optFilePath));
                            if (additionalArgs != null)
                            {
                                var additionalArgsString = string.Join(" ", additionalArgs
                                                                       .Select(x => "\"" + x.Replace("\"", "\\\"") + "\""));
                                arguments.AddRange(TokenizeArgs(additionalArgsString, macros));
                            }
                        }
                        else
                        {
                            arguments.Add(argData);
                        }
                    }
                }
                else
                {
                    arg.Append(token.TokenText());
                }
            }
            return(arguments);
        }