예제 #1
0
        private Token NextComment(int offset, bool isRem)
        {
            int start = Index - offset;
            var str   = GetStringBuilder();

            while (!IsEof())
            {
                char c = Code.GetChar(Index);
                if (CharUtils.IsNewLine(c))
                {
                    break;
                }
                ++Index;
                str.Append(c);
            }

            return(new CommentToken
            {
                Comment = str.ToString(),
                IsRem = isRem,
                Start = start,
                LineNumber = CurrentLine,
                LineStart = CurrentLineStart,
                End = Index,
            });
        }
예제 #2
0
        private Token NextDateLiteral()
        {
            int start = Index++;
            var str   = GetStringBuilder();

            while (!IsEof())
            {
                char c = Code.GetChar(Index);
                if (c == '#' || CharUtils.IsNewLine(c))
                {
                    break;
                }
                else
                {
                    str.Append(c);
                    ++Index;
                }
            }

            if (Code.GetChar(Index) != '#' || str.Length == 0)
            {
                throw VBSyntaxError(VBSyntaxErrorCode.SyntaxError);
            }

            var date = LexerUtils.GetDate(str.ToString());

            return(new DateLiteralToken
            {
                Start = start,
                End = ++Index,
                LineNumber = CurrentLine,
                LineStart = CurrentLineStart,
                Value = date,
            });
        }
예제 #3
0
        private void SkipNewline()
        {
            char c = Code.GetChar(Index++);

            if (CharUtils.IsNewLine(c))
            {
                if (c == '\r' && Code.GetChar(Index) == '\n')
                {
                    ++Index;
                }
                ++CurrentLine;
                CurrentLineStart = Index;
            }
        }
예제 #4
0
        private Token NextStringLiteral()
        {
            bool err   = true;
            int  start = Index++;
            var  str   = GetStringBuilder();

            while (!IsEof())
            {
                char c = Code.GetChar(Index);
                if (c == '"')
                {
                    c = Code.GetChar(++Index);
                    if (c == '"')
                    {
                        ++Index;
                        str.Append(c);
                    }
                    else
                    {
                        err = false;
                        break;
                    }
                }
                else if (CharUtils.IsNewLine(c))
                {
                    break;
                }
                else
                {
                    ++Index;
                    str.Append(c);
                }
            }

            if (err)
            {
                throw VBSyntaxError(VBSyntaxErrorCode.UnterminatedStringConstant);
            }

            return(new StringLiteralToken
            {
                Start = start,
                End = Index - 1,
                LineNumber = CurrentLine,
                LineStart = CurrentLineStart,
                Value = str.ToString(),
            });
        }
예제 #5
0
        public void SkipWhitespaces()
        {
            void SkipWSOnly()
            {
                char c = Code.GetChar(Index);

                while (CharUtils.IsWhiteSpace(c))
                {
                    c = Code.GetChar(++Index);
                }
            }

            while (!IsEof())
            {
                SkipWSOnly();
                char c = Code.GetChar(Index);
                if (c == '_')
                {
                    ++Index;
                    SkipWSOnly();
                    c = Code.GetChar(Index);
                    if (CharUtils.IsNewLine(c))
                    {
                        SkipNewline();
                    }
                    else
                    {
                        throw VBSyntaxError(VBSyntaxErrorCode.InvalidCharacter);
                    }
                }
                else
                {
                    break;
                }
            }
        }