Пример #1
0
        private static PkgdefSegment ParseSegment(PkgdefTokenizer tokenizer, Action <PkgdefIssue> onIssue)
        {
            PreCondition.AssertNotNull(tokenizer, nameof(tokenizer));
            PreCondition.AssertTrue(tokenizer.HasCurrent(), "tokenizer.HasCurrent()");
            PreCondition.AssertNotNull(onIssue, nameof(onIssue));

            PkgdefSegment result;

            switch (tokenizer.GetCurrent().GetTokenType())
            {
            case PkgdefTokenType.Whitespace:
                result = PkgdefSegment.Whitespace(tokenizer.GetCurrent().GetStartIndex(), tokenizer.GetCurrent().GetText());
                tokenizer.Next();
                break;

            case PkgdefTokenType.NewLine:
                result = PkgdefSegment.NewLine(tokenizer.GetCurrent().GetStartIndex(), tokenizer.GetCurrent().GetText());
                tokenizer.Next();
                break;

            case PkgdefTokenType.ForwardSlash:
                result = PkgdefDocument.ParseLineComment(tokenizer, onIssue);
                break;

            case PkgdefTokenType.LeftSquareBracket:
                result = PkgdefDocument.ParseRegistryKeyPath(tokenizer, onIssue);
                break;

            case PkgdefTokenType.AtSign:
            case PkgdefTokenType.DoubleQuote:
                result = PkgdefDocument.ParseRegistryKeyDataItem(tokenizer, onIssue);
                break;

            default:
                result = PkgdefSegment.Unrecognized(tokenizer.GetCurrent().GetStartIndex(), tokenizer.GetCurrent().GetText());
                tokenizer.Next();
                break;
            }

            return(result);
        }
Пример #2
0
        internal static PkgdefRegistryKeyDataItemSegment ParseRegistryKeyDataItem(int startIndex, string text)
        {
            PreCondition.AssertGreaterThanOrEqualTo(startIndex, 0, nameof(startIndex));
            PreCondition.AssertNotNullAndNotEmpty(text, nameof(text));
            PreCondition.AssertOneOf(text[0], "@\"", "text[0]");

            Action <PkgdefIssue> onIssue   = PkgdefDocument.IgnoreIssue;
            PkgdefTokenizer      tokenizer = PkgdefTokenizer.Create(startIndex, text, onIssue);

            tokenizer.Next();
            return(PkgdefDocument.ParseRegistryKeyDataItem(tokenizer, onIssue));
        }
Пример #3
0
        internal static PkgdefSegment ParseLineComment(PkgdefTokenizer tokenizer, Action <PkgdefIssue> onIssue)
        {
            PreCondition.AssertNotNull(tokenizer, nameof(tokenizer));
            PreCondition.AssertTrue(tokenizer.HasCurrent(), "tokenizer.HasCurrent()");
            PreCondition.AssertEqual(tokenizer.GetCurrent().GetTokenType(), PkgdefTokenType.ForwardSlash, "tokenizer.GetCurrent().GetTokenType()");
            PreCondition.AssertNotNull(onIssue, nameof(onIssue));

            PkgdefSegment result;
            int           startIndex = tokenizer.TakeCurrent().GetStartIndex();
            StringBuilder builder    = new StringBuilder().Append('/');

            if (!tokenizer.HasCurrent())
            {
                onIssue(new PkgdefIssue(startIndex, 1, "Missing line-comment's second forward slash ('/')."));
                result = PkgdefSegment.Unrecognized(startIndex, builder.ToString());
            }
            else if (tokenizer.GetCurrent().GetTokenType() != PkgdefTokenType.ForwardSlash)
            {
                onIssue.Invoke(new PkgdefIssue(startIndex + 1, 1, "Expected line-comment's second forward slash ('/')."));
                result = PkgdefSegment.Unrecognized(startIndex, builder.ToString());
            }
            else
            {
                builder.Append('/');
                tokenizer.Next();

                while (tokenizer.HasCurrent() && tokenizer.GetCurrent().GetTokenType() != PkgdefTokenType.NewLine)
                {
                    builder.Append(tokenizer.TakeCurrent().GetText());
                }
                string text = builder.ToString();
                result = PkgdefSegment.LineComment(startIndex, text);
            }

            return(result);
        }