Beispiel #1
0
        private LiteralToken NextOctIntLiteral()
        {
            int start = Index;

            ++Index;

            string str = GetOctStr();
            char   c   = Code.GetChar(Index);

            if (CharUtils.IsDecDigit(c) && !CharUtils.IsOctDigit(c))
            {
                throw VBSyntaxError(VBSyntaxErrorCode.SyntaxError);
            }

            if (CharUtils.IsIdentifierStart(c))
            {
                throw VBSyntaxError(VBSyntaxErrorCode.ExpectedEndOfStatement);
            }

            var result = ParseInteger(str, 8);

            result.Start = start;

            return(result);
        }
Beispiel #2
0
        private LiteralToken NextHexIntLiteral()
        {
            int start = Index;

            Index += 2;

            string str = GetHexStr();
            char   c   = Code.GetChar(Index);

            if (CharUtils.IsIdentifierStart(c))
            {
                throw VBSyntaxError(VBSyntaxErrorCode.ExpectedEndOfStatement);
            }

            var result = ParseInteger(str, 16);

            result.Start = start;

            return(result);
        }
Beispiel #3
0
        private Token NextNumericLiteral()
        {
            int  start = Index;
            char c     = Code.GetChar(Index);
            char next  = Code.GetChar(Index + 1);

            string?       dec  = null;
            StringBuilder?fstr = null;

            if (c != '.')
            {
                if (c == '&')
                {
                    if (CharUtils.Equals(next, 'h'))
                    {
                        return(NextHexIntLiteral());
                    }
                    else if (CharUtils.IsOctDigit(next))
                    {
                        return(NextOctIntLiteral());
                    }
                    else
                    {
                        throw VBSyntaxError(VBSyntaxErrorCode.SyntaxError);
                    }
                }
                else
                {
                    dec = GetDecStr();

                    if (CharUtils.IsIdentifierStart(Code.GetChar(Index)))
                    {
                        throw VBSyntaxError(VBSyntaxErrorCode.ExpectedEndOfStatement);
                    }
                }
            }

            c = Code.GetChar(Index);
            if (c == '.')
            {
                ++Index;
                fstr ??= GetStringBuilder();
                fstr.Append('.').Append(GetDecStr());
                c = Code.GetChar(Index);
            }

            if (CharUtils.Equals(c, 'e'))
            {
                fstr ??= GetStringBuilder();
                fstr.Append('e');

                c = Code.GetChar(++Index);
                if (c == '+' || c == '-')
                {
                    ++Index;
                    fstr.Append(c);
                }

                c = Code.GetChar(Index);
                if (CharUtils.IsDecDigit(c))
                {
                    fstr.Append(GetDecStr());
                }
                else
                {
                    throw VBSyntaxError(VBSyntaxErrorCode.InvalidNumber);
                }
            }

            c = Code.GetChar(Index);
            if (CharUtils.IsIdentifierStart(c))
            {
                throw VBSyntaxError(VBSyntaxErrorCode.ExpectedEndOfStatement);
            }

            if (fstr != null && dec != null)
            {
                fstr.Insert(0, dec);
            }

            if (fstr != null)
            {
                return(new FloatLiteralToken
                {
                    Start = start,
                    End = Index,
                    LineNumber = CurrentLine,
                    LineStart = CurrentLineStart,
                    Value = ParseDouble(fstr.ToString()),
                });
            }

            var result = ParseInteger(dec !, 10);

            result.Start = start;

            return(result);
        }
Beispiel #4
0
        public Token NextToken()
        {
            SkipWhitespaces();

            if (IsEof())
            {
                return(new EofToken
                {
                    Start = Index,
                    End = Index,
                    LineNumber = CurrentLine,
                    LineStart = CurrentLineStart,
                });
            }

            char c    = Code.GetChar(Index);
            char next = Code.GetChar(Index + 1);

            if (CharUtils.IsLineTerminator(c))
            {
                return(NextLineTermination());
            }

            var comment = NextComment();

            if (comment != null)
            {
                return(comment);
            }

            if (CharUtils.IsIdentifierStart(c))
            {
                return(NextIdentifier());
            }

            if (c == '"')
            {
                return(NextStringLiteral());
            }

            if (c == '.')
            {
                if (CharUtils.IsDecDigit(next))
                {
                    return(NextNumericLiteral());
                }
                return(NextPunctuation());
            }

            if (CharUtils.IsDecDigit(c))
            {
                return(NextNumericLiteral());
            }

            if (c == '&')
            {
                if (CharUtils.Equals(next, 'h') || CharUtils.IsDecDigit(next))
                {
                    return(NextNumericLiteral());
                }
                return(NextPunctuation());
            }

            if (c == '#')
            {
                return(NextDateLiteral());
            }

            if (c == '[')
            {
                return(NextExtendedIdentifier());
            }

            return(NextPunctuation());
        }