Exemplo n.º 1
0
        private void PushTokenOnOpeningMark(Stack <Token> openedTokens, MarkTranslatorElement mark, string text,
                                            int index)
        {
            var fatherToken    = openedTokens.Count == 0 ? null : openedTokens.Peek();
            var token          = new Token(index + mark.From.Opening.Length, mark, fatherToken);
            var indexAfterMark = token.StartIndex + token.MarkToTranslate.From.Opening.Length;

            if (indexAfterMark >= text.Length ||
                indexAfterMark < text.Length && !char.IsWhiteSpace(text[indexAfterMark]))
            {
                openedTokens.Push(token);
            }
        }
Exemplo n.º 2
0
        private bool IsClosing(Stack <Token> openedTokens, MarkTranslatorElement mark, string text, int index)
        {
            var indexBeforeMark    = index - 1;
            var isWhiteSpaceBefore = indexBeforeMark > 0 && char.IsWhiteSpace(text[indexBeforeMark]);

            if (isWhiteSpaceBefore || openedTokens.Count == 0)
            {
                return(false);
            }
            var previousToken = openedTokens.Peek();

            while (previousToken != null)
            {
                if (previousToken.MarkToTranslate.From.Equals(mark.From) && previousToken.StartIndex != index)
                {
                    return(true);
                }
                previousToken = previousToken.ParentToken;
            }

            return(false);
        }
Exemplo n.º 3
0
 private static bool IsBetweenDigits(MarkTranslatorElement mark, string text, int index)
 => IsDigitBefore(text, index) && IsDigitAfter(mark, text, index);
Exemplo n.º 4
0
        private static void PlaceToken(Stack <Token> openedTokens, ICollection <Token> tokens, MarkTranslatorElement mark,
                                       int index, string text)
        {
            var previousToken = openedTokens.Pop();

            while (!previousToken.MarkToTranslate.From.Equals(mark.From))
            {
                previousToken = openedTokens.Pop();
            }
            previousToken.EndIndex = index - 1;
            previousToken.Value    = text
                                     .Substring(previousToken.StartIndex, previousToken.EndIndex - previousToken.StartIndex + 1);
            if (previousToken.ParentToken == null)
            {
                tokens.Add(previousToken);
            }
            else
            {
                previousToken.ParentToken.ChildTokens.Add(previousToken);
            }
        }
Exemplo n.º 5
0
 private static bool IsDigitAfter(MarkTranslatorElement mark, string text, int index)
 {
     return(index + mark.From.Opening.Length < text.Length &&
            char.IsDigit(text[index + mark.From.Opening.Length]));
 }
Exemplo n.º 6
0
 public Token(int startIndex, MarkTranslatorElement markToTranslate, Token parentToken = null)
 {
     StartIndex      = startIndex;
     MarkToTranslate = markToTranslate;
     ParentToken     = parentToken;
 }