////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Block Comment.
        /// </summary>
        /// <param name="c">  The char c.</param>
        /// <returns>
        ///  The SourcePreview.TokenType value.
        /// </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private TokenType BlockComment(char c)
        {
            while (c != '\0')
            {
                switch (c)
                {
                case '\n':
                    if (Scanner.Token.Length > 0)
                    {
                        return(TokenType.Comment);
                    }
                    return(Scanner.ScanEol());

                case '\r':
                    c = Scanner.MoveNext();
                    break;

                default:

                    if (Scanner.Accept(Scanner.Language.BlockComment[1], false))
                    {
                        _inBlockComment = false;
                        return(TokenType.Comment);
                    }
                    c = Scanner.AppendMoveNext(c);
                    break;
                }
            }

            return(TokenType.Comment);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Classify Character and see what kind of token it is. Override to add functionality.
        /// </summary>
        /// <param name="c"> The char c.</param>
        /// <returns>
        ///  The SourcePreview.TokenType value.
        /// </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public override TokenType ClassifyCharacter(char c)
        {
            if (ScanEolAndWhitespace(c, out var classifyCharacter))
            {
                return(classifyCharacter);
            }

            if (_inBlockComment)
            {
                return(BlockComment(c));
            }

            var lang = Scanner.Language;

            if (lang != null)
            {
                if (!string.IsNullOrEmpty(lang.LineComment) && Scanner.Accept(lang.LineComment, false))
                {
                    Scanner.EndOfLine();
                    return(TokenType.Comment);
                }

                if (lang.BlockComment != null && !string.IsNullOrEmpty(lang.BlockComment[0]) && Scanner.Accept(Scanner.Language.BlockComment[0], false))
                {
                    _inBlockComment = true;
                    return(BlockComment(Scanner.CurrentChar));
                }
            }

            return(base.ClassifyCharacter(c));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Scan Comment. Either entering a comment or in a comment after Eol
        /// </summary>
        /// <returns>
        ///  The Scan.TokenType value.
        /// </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private TokenType ScanComment(char c)
        {
            while (c != '\0' && c != '\n')
            {
                if (Scanner.Accept("-->", false))
                {
                    _state = State.None;
                    break;
                }

                c = Scanner.AppendMoveNext(c);
            }

            return(TokenType.Comment);
        }
Пример #4
0
        private void SkipWhitespace()
        {
            var whitespaceScan = currentScanner.NextToken(TokenTransitions.Captures.Whitespace);

            if (whitespaceScan.Count == 1)
            {
                currentScanner.Accept(whitespaceScan[0]);
            }
        }