Beispiel #1
0
        public IEnumerable <T> GetTokens(LineToken input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.Kind != LineTokenKind.Line)
            {
                throw new ArgumentException($"Input must be line token of kind '{LineTokenKind.Line}', but is kind '{input.Kind}'");
            }


            var currentValue = new StringBuilder();

            var startColumn = 1;

            if (input.Value !.Length == 0)
            {
                yield return(CreateEolToken(input.LineNumber, startColumn));

                yield break;
            }

            for (var i = 0; i < input.Value.Length; i++)
            {
                var currentChar = input.Value[i];
                if (TryMatchSingleCharToken(currentChar, input.LineNumber, i + 1, out var matchedToken))
                {
                    if (currentValue.Length > 0)
                    {
                        var value = currentValue.GetValueAndClear();
                        yield return(CreateStringToken(value, input.LineNumber, startColumn));

                        startColumn += value.Length;
                    }
                    yield return(matchedToken);

                    startColumn += 1;
                }
                else
                {
                    currentValue.Append(currentChar);
                }
            }

            // if any input is left in currentValue, return it as String token
            if (currentValue.Length > 0)
            {
                var value = currentValue.GetValueAndClear();
                yield return(CreateStringToken(value, input.LineNumber, startColumn));

                startColumn += value.Length;
            }

            yield return(CreateEolToken(input.LineNumber, startColumn));
        }
Beispiel #2
0
        /// <summary>
        /// Determines if the specified input is the start of a footer (i.e. the line starts with a valid footer key)
        /// </summary>
        public static bool IsFooter(LineToken input)
        {
            if (input is null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.Kind != LineTokenKind.Line)
            {
                return(false);
            }

            return(new FooterParser(input).IsFooterStart());
        }
Beispiel #3
0
        private HeaderParser(LineToken input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.Kind != LineTokenKind.Line)
            {
                throw new ArgumentException($"Input must be line token of kind '{LineTokenKind.Line}', but is kind '{input.Kind}'");
            }

            m_Input = input;
        }
Beispiel #4
0
        public static CommitMessageHeader Parse(LineToken input)
        {
            var parser = new HeaderParser(input);

            return(parser.Parse());
        }
Beispiel #5
0
 /// <summary>
 /// Parses the specified commit footer.
 /// </summary>
 public static CommitMessageFooter Parse(LineToken input) => new FooterParser(input).Parse();