public override int GetLength()
 {
     return(PkgdefToken.GetLength(this.tokens));
 }
Exemplo n.º 2
0
        internal static PkgdefRegistryKeyDataItemSegment ParseRegistryKeyDataItem(PkgdefTokenizer tokenizer, Action <PkgdefIssue> onIssue)
        {
            PreCondition.AssertNotNull(tokenizer, nameof(tokenizer));
            PreCondition.AssertTrue(tokenizer.HasCurrent(), "tokenizer.HasCurrent()");
            PreCondition.AssertOneOf(tokenizer.GetCurrent().GetTokenType(), new[] { PkgdefTokenType.AtSign, PkgdefTokenType.DoubleQuote }, "tokenizer.GetCurrent().GetTokenType()");
            PreCondition.AssertNotNull(onIssue, nameof(onIssue));

            PkgdefToken        registryKeyDataItemNameFirstToken = tokenizer.TakeCurrent();
            List <PkgdefToken> tokens = new List <PkgdefToken>()
            {
                registryKeyDataItemNameFirstToken
            };
            bool dataItemDone = false;

            if (registryKeyDataItemNameFirstToken.GetTokenType() == PkgdefTokenType.DoubleQuote)
            {
                if (!tokenizer.HasCurrent())
                {
                    onIssue(new PkgdefIssue(registryKeyDataItemNameFirstToken.GetStartIndex(), registryKeyDataItemNameFirstToken.GetLength(), "Missing registry key data item name closing double-quote ('\"')."));
                    dataItemDone = true;
                }
                else
                {
                    while (tokenizer.HasCurrent())
                    {
                        PkgdefTokenType tokenType = tokenizer.GetCurrent().GetTokenType();
                        if (tokenType == PkgdefTokenType.NewLine)
                        {
                            onIssue(new PkgdefIssue(PkgdefToken.GetStartIndex(tokens), PkgdefToken.GetLength(tokens), "Missing registry key data item name closing double-quote ('\"')."));
                            dataItemDone = true;
                            break;
                        }
                        else
                        {
                            PkgdefToken token = tokenizer.TakeCurrent();
                            tokens.Add(token);
                            if (token.GetTokenType() == PkgdefTokenType.DoubleQuote)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (!dataItemDone)
            {
                if (!tokenizer.HasCurrent())
                {
                    onIssue(new PkgdefIssue(PkgdefToken.GetStartIndex(tokens), PkgdefToken.GetLength(tokens), "Missing registry key data item equals sign ('=')."));
                    dataItemDone = true;
                }
                else
                {
                    while (tokenizer.HasCurrent())
                    {
                        PkgdefTokenType tokenType = tokenizer.GetCurrent().GetTokenType();
                        if (tokenType == PkgdefTokenType.NewLine)
                        {
                            onIssue(new PkgdefIssue(PkgdefToken.GetStartIndex(tokens), PkgdefToken.GetLength(tokens), "Missing registry key data item equals sign ('=')."));
                            dataItemDone = true;
                            break;
                        }
                        else
                        {
                            PkgdefToken token = tokenizer.TakeCurrent();
                            tokens.Add(token);
                            if (token.GetTokenType() == PkgdefTokenType.EqualsSign)
                            {
                                break;
                            }
                            else if (token.GetTokenType() != PkgdefTokenType.Whitespace)
                            {
                                onIssue(new PkgdefIssue(token.GetStartIndex(), token.GetLength(), "Expected registry key data item equals sign ('=')."));
                            }
                        }
                    }
                }
            }

            if (!dataItemDone)
            {
                if (!tokenizer.HasCurrent())
                {
                    onIssue(new PkgdefIssue(PkgdefToken.GetStartIndex(tokens), PkgdefToken.GetLength(tokens), "Missing registry key data item value."));
                }
                else
                {
                    int dataItemValueTokenCount = 0;
                    while (tokenizer.HasCurrent())
                    {
                        PkgdefTokenType tokenType = tokenizer.GetCurrent().GetTokenType();
                        if (tokenType == PkgdefTokenType.NewLine)
                        {
                            if (dataItemValueTokenCount == 0)
                            {
                                onIssue(new PkgdefIssue(PkgdefToken.GetStartIndex(tokens), PkgdefToken.GetLength(tokens), "Missing registry key data item value."));
                            }
                            break;
                        }
                        else
                        {
                            PkgdefToken token = tokenizer.TakeCurrent();
                            tokens.Add(token);
                            if (token.GetTokenType() != PkgdefTokenType.Whitespace)
                            {
                                dataItemValueTokenCount++;
                            }
                        }
                    }
                }
            }

            return(new PkgdefRegistryKeyDataItemSegment(tokens));
        }