Пример #1
0
        protected override IEnumerable <GnToken> GetTokens()
        {
            int     braceNesting    = 0;
            string  currentConfig   = null;
            bool    inPdfiumLibrary = false;
            GnToken token;

            while ((token = GetToken()) != null)
            {
                switch (token.Type)
                {
                case GnTokenType.BraceOpen:
                    yield return(token);

                    braceNesting++;
                    break;

                case GnTokenType.BraceClose:
                    yield return(token);

                    braceNesting--;
                    if (braceNesting == 0)
                    {
                        currentConfig   = null;
                        inPdfiumLibrary = false;
                    }
                    break;

                case GnTokenType.Identifier:
                    if (braceNesting == 0 && token.Text == "config")
                    {
                        yield return(token);

                        yield return(GetToken(GnTokenType.ParenOpen));

                        yield return(token = GetToken(GnTokenType.String));

                        currentConfig = ParseString(token.Text);
                        yield return(GetToken(GnTokenType.ParenClose));
                    }
                    else if (currentConfig == "pdfium_common_config" && token.Text == "include_dirs")
                    {
                        yield return(token);

                        yield return(token = GetToken());

                        if (token.Type == GnTokenType.Equals)
                        {
                            foreach (var child in AddToList(new GnToken(GnTokenType.String, "\"v8/include\"")))
                            {
                                yield return(child);
                            }
                        }
                    }
                    else if (currentConfig == "pdfium_common_config" && token.Text == "defines")
                    {
                        yield return(token);

                        yield return(token = GetToken());

                        if (token.Type == GnTokenType.Equals)
                        {
                            foreach (var child in AddToList(new GnToken(GnTokenType.String, "\"FPDFSDK_EXPORTS\"")))
                            {
                                yield return(child);
                            }
                        }
                    }
                    else if (inPdfiumLibrary && token.Text == "sources" && _contribs.Count > 0)
                    {
                        yield return(token);

                        yield return(token = GetToken());

                        if (token.Type == GnTokenType.Equals)
                        {
                            var extraTokens = new List <GnToken>();

                            foreach (var contrib in _contribs)
                            {
                                if (extraTokens.Count > 0)
                                {
                                    extraTokens.Add(new GnToken(GnTokenType.Comma));
                                }

                                extraTokens.Add(new GnToken(
                                                    GnTokenType.String,
                                                    "\"" + contrib.Replace(Path.DirectorySeparatorChar, '/') + "\""
                                                    ));
                            }

                            foreach (var child in AddToList(extraTokens))
                            {
                                yield return(child);
                            }
                        }
                    }
                    else if (braceNesting == 0 && (token.Text == "static_library" || token.Text == "jumbo_static_library"))
                    {
                        var tokens = new List <GnToken>();
                        tokens.Add(token);

                        tokens.Add(GetToken(GnTokenType.ParenOpen));
                        token = GetToken(GnTokenType.String);
                        tokens.Add(token);
                        inPdfiumLibrary = ParseString(token.Text) == "pdfium";
                        tokens.Add(GetToken(GnTokenType.ParenClose));

                        if (inPdfiumLibrary)
                        {
                            tokens[0] = new GnToken(GnTokenType.Identifier, "shared_library");
                        }

                        foreach (var child in tokens)
                        {
                            yield return(child);
                        }
                    }
                    else
                    {
                        yield return(token);
                    }
                    break;

                default:
                    yield return(token);

                    break;
                }
            }
        }
Пример #2
0
 private IEnumerable <GnToken> AddToList(GnToken token)
 {
     return(AddToList(new[] { token }));
 }