// Returns the parsed command line. If ErrorDescription is non-null, then the parse failed.
    internal static CommandLineOptions ParseCommandLine(string[] args)
    {
        var result = new CommandLineOptions();

        result.ParseCommandLineStrings(args);

        // Convert the language strings to language values.
        var languageTokenizer = new CommandlineTokenizer <Lang>(Lang.Ambiguous)
                                .AddKeyword(Lang.CSharp)
                                .AddKeyword(Lang.Cx, "cppcx")
                                .AddKeyword(Lang.Cx)
                                .AddKeyword(Lang.Cppwinrt)
                                .AddKeyword(Lang.Cppwinrt, "winrtcpp")
                                .AddKeyword(Lang.LottieYaml)
                                .AddKeyword(Lang.WinCompDgml, "dgml")
                                .AddKeyword(Lang.Stats);

        var languages = new List <Lang>();

        // Parse the language string.
        foreach (var languageString in result._languageStrings)
        {
            languageTokenizer.TryMatchKeyword(languageString, out var language);
            languages.Add(language);
            switch (language)
            {
            case Lang.Unknown:
                result.ErrorDescription = $"Unrecognized language: {languageString}";
                break;

            case Lang.Ambiguous:
                result.ErrorDescription = $"Ambiguous language: {languageString}";
                break;
            }
        }

        result.Languages = languages.Distinct().ToArray();

        // Sort any additional interfaces and remove duplicates.
        var additionalInterfaces = result._additionalInterfaces.OrderBy(name => name).Distinct().ToArray();

        result._additionalInterfaces.Clear();
        result._additionalInterfaces.AddRange(additionalInterfaces);

        return(result);
    }
Exemple #2
0
    // Returns the parsed command line. If ErrorDescription is non-null, then the parse failed.
    internal static CommandLineOptions ParseCommandLine(string[] args)
    {
        var result = new CommandLineOptions();

        result.ParseCommandLineStrings(args);

        // Convert the language strings to language values.
        var languageTokenizer = new CommandlineTokenizer <Lang>(Lang.Ambiguous)
                                .AddKeyword("csharp", Lang.CSharp)
                                .AddKeyword("cppcx", Lang.Cx)
                                .AddKeyword("cx", Lang.Cx)
                                .AddKeyword("cppwinrt", Lang.Cppwinrt)
                                .AddKeyword("winrtcpp", Lang.Cppwinrt)
                                .AddKeyword("lottiexml", Lang.LottieXml)
                                .AddKeyword("lottieyaml", Lang.LottieYaml)
                                .AddKeyword("wincompxml", Lang.WinCompXml)
                                .AddKeyword("dgml", Lang.WinCompDgml)
                                .AddKeyword("stats", Lang.Stats);

        var languages = new List <Lang>();

        // Parse the language string.
        foreach (var languageString in result._languageStrings)
        {
            languageTokenizer.TryMatchKeyword(languageString, out var language);
            languages.Add(language);
            switch (language)
            {
            case Lang.Unknown:
                result.ErrorDescription = $"Unrecognized language: {languageString}";
                break;

            case Lang.Ambiguous:
                result.ErrorDescription = $"Ambiguous language: {languageString}";
                break;
            }
        }

        result.Languages = languages.Distinct();

        return(result);
    }