private Token?NextComment() { while (!IsEof()) { char c = Code.GetChar(Index); if (c == '\'') { ++Index; return(NextComment(1, false)); } else if (CharUtils.Equals(c, 'r')) { char c2 = Code.GetChar(Index + 1); char c3 = Code.GetChar(Index + 2); char c4 = Code.GetChar(Index + 3); if (CharUtils.Equals(c2, 'e') && CharUtils.Equals(c3, 'm') && CharUtils.IsWhiteSpace(c4)) { Index += 3; return(NextComment(3, true)); } else { break; } } else { break; } } return(null); }
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); }
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()); }