diff --git a/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb b/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb index 70e34368ff738..a97fc2c1de907 100644 --- a/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb +++ b/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb @@ -225,16 +225,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Private Function ScanNextCharAsToken(leadingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken Dim token As SyntaxToken - - If Not CanGet() Then + Dim c As Char + If Not Peep(0, c) Then token = MakeEofToken(leadingTrivia) Else _badTokenCount += 1 If _badTokenCount < BadTokenCountLimit Then ' // Don't break up surrogate pairs - Dim c = Peek() - Dim length = If(IsHighSurrogate(c) AndAlso CanGet(1) AndAlso IsLowSurrogate(Peek(1)), 2, 1) + Dim length = If(IsHighSurrogate(c) AndAlso Peep(1, c) AndAlso IsLowSurrogate(c), 2, 1) token = MakeBadToken(leadingTrivia, length, ERRID.ERR_IllegalChar) Else ' If we get too many characters that we cannot make sense of, absorb the rest of the input. @@ -265,9 +264,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End If Dim condLineStart = _lineBufferOffset + Dim c As Char - While (CanGet()) - Dim c As Char = Peek() + While Peep(0, c) Select Case (c) @@ -322,8 +321,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Sub EatThroughLine() - While CanGet() - Dim c As Char = Peek() + Dim c As Char + While Peep(0, c) If IsNewLine(c) Then EatThroughLineBreak(c) @@ -415,7 +414,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Function NextIs(offset As Integer, c As Char) As Boolean - Return CanGet(offset) AndAlso (Peek(offset) = c) + Dim ch As Char + Return Peep(offset, ch) AndAlso (ch = c) End Function Private Function CanGet() As Boolean @@ -533,27 +533,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Function ScanLineContinuation(tList As SyntaxListBuilder) As Boolean - If Not CanGet() Then - Return False - End If - - If Not IsAfterWhitespace() Then - Return False - End If - - Dim ch As Char = Peek() - If Not IsUnderscore(ch) Then + Dim ch As Char + If Not Peep(0, ch) OrElse + Not IsAfterWhitespace() OrElse + Not IsUnderscore(ch) Then Return False End If Dim Here = 1 - While CanGet(Here) - ch = Peek(Here) - If IsWhitespace(ch) Then - Here += 1 - Else - Exit While - End If + While Peep(Here, ch) AndAlso IsWhitespace(ch) + Here += 1 End While ' Line continuation is valid at the end of the @@ -579,8 +568,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' implicit line continuations. (See Scanner::EatLineContinuation.) Otherwise, ' include the new line and any additional spaces as trivia. If startComment = 0 AndAlso - CanGet(Here) AndAlso - Not IsNewLine(Peek(Here)) Then + Peep(Here, ch) AndAlso + Not IsNewLine(ch) Then tList.Add(MakeEndOfLineTrivia(GetText(newLine))) If spaces > 0 Then @@ -601,12 +590,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ''' Consumes all trivia until a nontrivia char is found ''' Friend Function ScanMultilineTrivia() As SyntaxList(Of VisualBasicSyntaxNode) - If Not CanGet() Then + Dim ch As Char + If Not Peep(0, ch) Then Return Nothing End If - Dim ch = Peek() - ' optimization for a common case ' the ASCII range between ': and ~ , with exception of except "'", "_" and R cannot start trivia If ch > ":"c AndAlso ch <= "~"c AndAlso ch <> "'"c AndAlso ch <> "_"c AndAlso ch <> "R"c AndAlso ch <> "r"c Then @@ -626,7 +614,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ''' Scans a single piece of trivia ''' Private Function TryScanSinglePieceOfMultilineTrivia(tList As SyntaxListBuilder) As Boolean - If CanGet() Then + Dim ch As Char + If Peep(0, ch) Then Dim atNewLine = IsAtNewLine() @@ -641,7 +630,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End If End If - Dim ch = Peek() If IsWhitespace(ch) Then ' eat until linebreak or non-whitespace Dim wslen = GetWhitespaceLength(1) @@ -686,11 +674,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' check for # Private Function StartsDirective(Here As Integer) As Boolean - If CanGet(Here) Then - Dim ch = Peek(Here) - Return IsHash(ch) - End If - Return False + Dim ch As Char + Return Peep(Here, ch) AndAlso IsHash(ch) End Function Private Function IsAtNewLine() As Boolean @@ -730,8 +715,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Sub Private Sub ScanSingleLineTriviaInXmlDoc(tList As SyntaxListBuilder) - If CanGet() Then - Dim c As Char = Peek() + Dim c As Char + If Peep(0, c) Then + Select Case (c) ' // Whitespace ' // S ::= (#x20 | #x9 | #xD | #xA)+ @@ -763,7 +749,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Sub ScanWhitespaceAndLineContinuations(tList As SyntaxListBuilder) - If CanGet() AndAlso IsWhitespace(Peek()) Then + Dim ch As Char + If Peep(0, ch) AndAlso IsWhitespace(ch) Then tList.Add(ScanWhitespace(1)) ' collect { lineCont, ws } While ScanLineContinuation(tList) @@ -833,9 +820,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' Case 3 is required to parse single line if's and numeric labels. ' Case 4 is required to limit explicit line continuations to single new line - If CanGet() Then + Dim ch As Char + If Peep(0, ch) Then - Dim ch As Char = Peek() Dim startOfTerminatorTrivia = _lineBufferOffset If IsNewLine(ch) Then @@ -847,11 +834,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' collect { ws, colon } Do Dim len = GetWhitespaceLength(0) - If Not CanGet(len) Then + If Not Peep(len, ch) Then Exit Do End If - ch = Peek(len) If Not IsColonAndNotColonEquals(ch, offset:=len) Then Exit Do End If @@ -887,7 +873,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Private Function GetWhitespaceLength(len As Integer) As Integer ' eat until linebreak or non-whitespace - While CanGet(len) AndAlso IsWhitespace(Peek(len)) + Dim ch As Char + While Peep(len, ch) AndAlso IsWhitespace(ch) len += 1 End While Return len @@ -895,7 +882,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Private Function GetXmlWhitespaceLength(len As Integer) As Integer ' eat until linebreak or non-whitespace - While CanGet(len) AndAlso IsXmlWhitespace(Peek(len)) + Dim ch As Char + While Peep(len, ch) AndAlso IsXmlWhitespace(ch) len += 1 End While Return len @@ -924,26 +912,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax AdvanceChar() ' eat until linebreak or non-whitespace - While CanGet() AndAlso IsWhitespace(Peek) + Dim ch As Char + While Peep(0, ch) AndAlso IsWhitespace(ch) AdvanceChar() End While End Sub Private Function PeekStartComment(i As Integer) As Integer - - If CanGet(i) Then - Dim ch = Peek(i) + Dim ch As Char + If Peep(i, ch) Then If IsSingleQuote(ch) Then Return 1 ElseIf MatchOneOrAnotherOrFullwidth(ch, "R"c, "r"c) AndAlso - CanGet(i + 2) AndAlso MatchOneOrAnotherOrFullwidth(Peek(i + 1), "E"c, "e"c) AndAlso - MatchOneOrAnotherOrFullwidth(Peek(i + 2), "M"c, "m"c) Then + Peep(i + 2, ch) AndAlso MatchOneOrAnotherOrFullwidth(Peek(i + 1), "E"c, "e"c) AndAlso + MatchOneOrAnotherOrFullwidth(ch, "M"c, "m"c) Then - If Not CanGet(i + 3) OrElse IsNewLine(Peek(i + 3)) Then + If Not Peep(i + 3, ch) OrElse IsNewLine(ch) Then ' have only 'REM' Return 3 - ElseIf Not IsIdentifierPartCharacter(Peek(i + 3)) Then + ElseIf Not IsIdentifierPartCharacter(ch) Then ' have 'REM ' Return 4 End If @@ -961,9 +949,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Dim looksLikeDocComment As Boolean = StartsXmlDoc(0) ' eat all chars until EoL - While CanGet(length) AndAlso - Not IsNewLine(Peek(length)) - + Dim ch As Char + While Peep(length, ch) AndAlso Not IsNewLine(ch) length += 1 End While @@ -1033,7 +1020,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return If(dl, MakeHashToken(precedingTrivia, fullWidth)) Case "&"c - If CanGet(1) AndAlso BeginsBaseLiteral(Peek(1)) Then + If Peep(1, ch) AndAlso BeginsBaseLiteral(ch) Then Return ScanNumericLiteral(precedingTrivia) End If @@ -1105,7 +1092,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return MakeExclamationToken(precedingTrivia, fullWidth) Case "."c - If CanGet(1) AndAlso IsDecimalDigit(Peek(1)) Then + If Peep(1, ch) AndAlso IsDecimalDigit(ch) Then Return ScanNumericLiteral(precedingTrivia) Else Return MakeDotToken(precedingTrivia, fullWidth) @@ -1153,13 +1140,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return ScanIdentifierOrKeyword(precedingTrivia) Case "_"c - If CanGet(1) AndAlso IsIdentifierPartCharacter(Peek(1)) Then + If Peep(1, ch) AndAlso IsIdentifierPartCharacter(ch) Then Return ScanIdentifierOrKeyword(precedingTrivia) End If Dim err As ERRID = ERRID.ERR_ExpectedIdentifier Dim len = GetWhitespaceLength(1) - If Not CanGet(len) OrElse IsNewLine(Peek(len)) OrElse PeekStartComment(len) > 0 Then + If Not Peep(len, ch) OrElse IsNewLine(ch) OrElse PeekStartComment(len) > 0 Then err = ERRID.ERR_LineContWithCommentOrNoPrecSpace End If @@ -1178,7 +1165,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End If Case "$"c, FULLWIDTH_DOLLAR_SIGN - If Not fullWidth AndAlso CanGet(1) AndAlso IsDoubleQuote(Peek(1)) Then + Dim cx As Char + If Not fullWidth AndAlso Peep(1, cx) AndAlso IsDoubleQuote(cx) Then Return MakePunctuationToken(precedingTrivia, 2, SyntaxKind.DollarSignDoubleQuoteToken) End If @@ -1203,8 +1191,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' at this point it is very likely that we are located at the beginning of a token Private Function TryScanToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken - If CanGet() Then - Return ScanTokenCommon(precedingTrivia, Peek(), False) + Dim ch As Char + If Peep(0, ch) Then + Return ScanTokenCommon(precedingTrivia, ch, False) End If Return MakeEofToken(precedingTrivia) End Function @@ -1221,8 +1210,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Dim Here = Index Dim eq As Char - While CanGet(Here) - eq = Peek(Here) + While Peep(Here, eq) Here += 1 If Not IsWhitespace(eq) Then If eq = "="c OrElse eq = FULLWIDTH_EQUALS_SIGN Then @@ -1237,16 +1225,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Function ScanRightAngleBracket(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), charIsFullWidth As Boolean) As SyntaxToken - Debug.Assert(CanGet) ' > - Debug.Assert(Peek() = ">"c OrElse Peek() = FULLWIDTH_GREATER_THAN_SIGN) - + Dim c As Char +#If DEBUG Then + Dim ok = Peep(0, c) + Debug.Assert(ok) ' > + Debug.Assert(c = ">"c OrElse c = FULLWIDTH_GREATER_THAN_SIGN) +#End If Dim length As Integer = 1 ' // Allow whitespace between the characters of a two-character token. length = GetWhitespaceLength(length) - If CanGet(length) Then - Dim c As Char = Peek(length) + If Peep(length, c) Then If c = "="c OrElse c = FULLWIDTH_EQUALS_SIGN Then length += 1 @@ -1264,20 +1254,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Function ScanLeftAngleBracket(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), charIsFullWidth As Boolean, scanTrailingTrivia As ScanTriviaFunc) As SyntaxToken - Debug.Assert(CanGet) ' < - Debug.Assert(Peek() = "<"c OrElse Peek() = FULLWIDTH_LESS_THAN_SIGN) - + Dim c As Char +#If DEBUG Then + Dim ok = Peep(0, c) + Debug.Assert(ok) ' < + Debug.Assert(c = "<"c OrElse c = FULLWIDTH_LESS_THAN_SIGN) +#End If Dim length As Integer = 1 ' Check for XML tokens - If Not charIsFullWidth AndAlso CanGet(length) Then - Dim c As Char = Peek(length) + If Not charIsFullWidth AndAlso Peep(length, c) Then Select Case c Case "!"c - If CanGet(length + 2) Then + If Peep(length + 2, c) Then Select Case (Peek(length + 1)) Case "-"c - If CanGet(length + 3) AndAlso Peek(length + 2) = "-"c Then + If CanGet(length + 3) AndAlso c = "-"c Then Return XmlMakeBeginCommentToken(precedingTrivia, scanTrailingTrivia) End If Case "["c @@ -1299,8 +1291,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' // Allow whitespace between the characters of a two-character token. length = GetWhitespaceLength(length) - If CanGet(length) Then - Dim c As Char = Peek(length) + If Peep(length, c) Then If c = "="c OrElse c = FULLWIDTH_EQUALS_SIGN Then length += 1 @@ -1311,8 +1302,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ElseIf c = "<"c OrElse c = FULLWIDTH_LESS_THAN_SIGN Then length += 1 - If CanGet(length) Then - c = Peek(length) + If Peep(length, c) Then 'if the second "<" is a part of "<%" - like in "<<%" , we do not want to use it. If c <> "%"c AndAlso c <> FULLWIDTH_PERCENT_SIGN Then @@ -1363,10 +1353,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Debug.Assert(IsIdentifierStartCharacter(Peek)) Debug.Assert(PeekStartComment(0) = 0) ' comment should be handled by caller - Dim ch = Peek() - If CanGet(1) Then - Dim ch1 = Peek(1) - If IsConnectorPunctuation(ch) AndAlso Not IsIdentifierPartCharacter(ch1) Then + Dim cx As Char, ch = Peek() + If Peep(1, cx) Then + If IsConnectorPunctuation(ch) AndAlso Not IsIdentifierPartCharacter(cx) Then Return MakeBadToken(precedingTrivia, 1, ERRID.ERR_ExpectedIdentifier) End If End If @@ -1376,8 +1365,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' // The C++ compiler refuses to inline IsIdentifierCharacter, so the ' // < 128 test is inline here. (This loop gets a *lot* of traffic.) ' TODO: make sure we get good perf here - While CanGet(len) - ch = Peek(len) + + While Peep(len, ch) Dim code = Convert.ToUInt16(ch) If code < 128 AndAlso IsNarrowIdentifierCharacter(code) OrElse @@ -1391,18 +1380,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax 'Check for a type character Dim TypeCharacter As TypeCharacter = TypeCharacter.None - If CanGet(len) Then - ch = Peek(len) + If Peep(len, ch) Then FullWidthRepeat: Select Case ch Case "!"c ' // If the ! is followed by an identifier it is a dictionary lookup operator, not a type character. - If CanGet(len + 1) Then - Dim NextChar As Char = Peek(len + 1) - - If IsIdentifierStartCharacter(NextChar) OrElse - MatchOneOrAnotherOrFullwidth(NextChar, "["c, "]"c) Then + ' Dim ch As Char + If Peep(len + 1, ch) Then + If IsIdentifierStartCharacter(ch) OrElse + MatchOneOrAnotherOrFullwidth(ch, "["c, "]"c) Then Exit Select End If End If @@ -1477,34 +1464,33 @@ FullWidthRepeat: End Function Private Function ScanBracketedIdentifier(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken - Debug.Assert(CanGet) ' [ - Debug.Assert(Peek() = "["c OrElse Peek() = FULLWIDTH_LEFT_SQUARE_BRACKET) - + Dim ch As Char +#If DEBUG Then + Debug.Assert(Peep(0, ch)) ' [ + Debug.Assert(ch = "["c OrElse ch = FULLWIDTH_LEFT_SQUARE_BRACKET) +#End If Dim IdStart As Integer = 1 Dim Here As Integer = IdStart Dim InvalidIdentifier As Boolean = False - If Not CanGet(Here) Then + If Not Peep(Here, ch) Then Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_MissingEndBrack) End If - Dim ch = Peek(Here) - ' check if we can start an ident. If Not IsIdentifierStartCharacter(ch) OrElse (IsConnectorPunctuation(ch) AndAlso - Not (CanGet(Here + 1) AndAlso - IsIdentifierPartCharacter(Peek(Here + 1)))) Then + Not (Peep(Here + 1, ch) AndAlso + IsIdentifierPartCharacter(ch))) Then InvalidIdentifier = True End If ' check ident until ] - While CanGet(Here) - Dim [Next] As Char = Peek(Here) + While Peep(Here, ch) - If [Next] = "]"c OrElse [Next] = FULLWIDTH_RIGHT_SQUARE_BRACKET Then + If ch = "]"c OrElse ch = FULLWIDTH_RIGHT_SQUARE_BRACKET Then Dim IdStringLength As Integer = Here - IdStart If IdStringLength > 0 AndAlso Not InvalidIdentifier Then @@ -1526,9 +1512,9 @@ FullWidthRepeat: ' // The sequence "[]" does not define a valid identifier. Return MakeBadToken(precedingTrivia, Here + 1, ERRID.ERR_ExpectedIdentifier) End If - ElseIf IsNewLine([Next]) Then + ElseIf IsNewLine(ch) Then Exit While - ElseIf Not IsIdentifierPartCharacter([Next]) Then + ElseIf Not IsIdentifierPartCharacter(ch) Then InvalidIdentifier = True Exit While End If @@ -1567,7 +1553,7 @@ FullWidthRepeat: Dim ch = Peek() If ch = "&"c OrElse ch = FULLWIDTH_AMPERSAND Then Here += 1 - ch = If(CanGet(Here), Peek(Here), ChrW(0)) + If Not Peep(Here, ch) Then ch = ChrW(0) FullWidthRepeat: Select Case ch @@ -1576,11 +1562,7 @@ FullWidthRepeat: IntegerLiteralStart = Here Base = LiteralBase.Hexadecimal - While CanGet(Here) - ch = Peek(Here) - If Not IsHexDigit(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso IsHexDigit(ch) Here += 1 End While @@ -1589,11 +1571,7 @@ FullWidthRepeat: IntegerLiteralStart = Here Base = LiteralBase.Octal - While CanGet(Here) - ch = Peek(Here) - If Not IsOctalDigit(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso IsOctalDigit(ch) Here += 1 End While @@ -1608,11 +1586,7 @@ FullWidthRepeat: Else ' no base specifier - just go through decimal digits. IntegerLiteralStart = Here - While CanGet(Here) - ch = Peek(Here) - If Not IsDecimalDigit(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso IsDecimalDigit(ch) Here += 1 End While End If @@ -1622,21 +1596,17 @@ FullWidthRepeat: ' // Unless there was an explicit base specifier (which indicates an integer literal), ' // read the rest of a float literal. - If Base = LiteralBase.Decimal AndAlso CanGet(Here) Then + If Base = LiteralBase.Decimal AndAlso Peep(Here, ch) Then ' // First read a '.' followed by a sequence of one or more digits. - ch = Peek(Here) + If (ch = "."c Or ch = FULLWIDTH_FULL_STOP) AndAlso - CanGet(Here + 1) AndAlso - IsDecimalDigit(Peek(Here + 1)) Then + Peep(Here + 1, ch) AndAlso + IsDecimalDigit(ch) Then Here += 2 ' skip dot and first digit ' all following decimal digits belong to the literal (fractional part) - While CanGet(Here) - ch = Peek(Here) - If Not IsDecimalDigit(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso IsDecimalDigit(ch) Here += 1 End While literalKind = NumericLiteralKind.Float @@ -1644,24 +1614,18 @@ FullWidthRepeat: ' // Read an exponent symbol followed by an optional sign and a sequence of ' // one or more digits. - If CanGet(Here) AndAlso BeginsExponent(Peek(Here)) Then + If Peep(Here, ch) AndAlso BeginsExponent(ch) Then Here += 1 - If CanGet(Here) Then - ch = Peek(Here) - + If Peep(Here, ch) Then If MatchOneOrAnotherOrFullwidth(ch, "+"c, "-"c) Then Here += 1 End If End If - If CanGet(Here) AndAlso IsDecimalDigit(Peek(Here)) Then + If Peep(Here, ch) AndAlso IsDecimalDigit(ch) Then Here += 1 - While CanGet(Here) - ch = Peek(Here) - If Not IsDecimalDigit(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso IsDecimalDigit(ch) Here += 1 End While Else @@ -1680,8 +1644,7 @@ FullWidthRepeat: Dim TypeCharacter As TypeCharacter = TypeCharacter.None - If CanGet(Here) Then - ch = Peek(Here) + If Peep(Here, ch) Then FullWidthRepeat2: Select Case ch @@ -1757,8 +1720,7 @@ FullWidthRepeat2: literalKind = NumericLiteralKind.Decimal ' check if this was not attempt to use obsolete exponent - If CanGet(Here + 1) Then - ch = Peek(Here + 1) + If Peep(Here + 1, ch) Then If IsDecimalDigit(ch) OrElse MatchOneOrAnotherOrFullwidth(ch, "+"c, "-"c) Then Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_ObsoleteExponent) @@ -1769,17 +1731,15 @@ FullWidthRepeat2: End If Case "U"c, "u"c - If literalKind <> NumericLiteralKind.Float AndAlso CanGet(Here + 1) Then - Dim NextChar As Char = Peek(Here + 1) - + If literalKind <> NumericLiteralKind.Float AndAlso Peep(Here + 1, ch) Then 'unsigned suffixes - US, UL, UI - If MatchOneOrAnotherOrFullwidth(NextChar, "S"c, "s"c) Then + If MatchOneOrAnotherOrFullwidth(ch, "S"c, "s"c) Then TypeCharacter = TypeCharacter.UShortLiteral Here += 2 - ElseIf MatchOneOrAnotherOrFullwidth(NextChar, "I"c, "i"c) Then + ElseIf MatchOneOrAnotherOrFullwidth(ch, "I"c, "i"c) Then TypeCharacter = TypeCharacter.UIntegerLiteral Here += 2 - ElseIf MatchOneOrAnotherOrFullwidth(NextChar, "L"c, "l"c) Then + ElseIf MatchOneOrAnotherOrFullwidth(ch, "L"c, "l"c) Then TypeCharacter = TypeCharacter.ULongLiteral Here += 2 End If @@ -1947,25 +1907,16 @@ FullWidthRepeat2: ByRef Here As Integer ) As Boolean Debug.Assert(Here >= 0) + Dim ch As Char - If Not CanGet(Here) Then - Return False - End If - - Dim ch = Peek(Here) - If Not IsDecimalDigit(ch) Then + If Not Peep(Here, ch) OrElse Not IsDecimalDigit(ch) Then Return False End If Dim IntegralValue As Integer = IntegralLiteralCharacterValue(ch) Here += 1 - While CanGet(Here) - ch = Peek(Here) - - If Not IsDecimalDigit(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso IsDecimalDigit(ch) Dim nextDigit = IntegralLiteralCharacterValue(ch) If IntegralValue < 214748364 OrElse @@ -2000,7 +1951,7 @@ FullWidthRepeat2: Dim YearIsTwoDigits As Boolean = False Dim DaysToMonth As Integer() = Nothing Dim yearIsFirst As Boolean = False - + Dim ch, cx, FirstDateSeparator As Char ' // Unfortunately, we can't fall back on OLE Automation's date parsing because ' // they don't have the same range as the URT's DateTime class @@ -2017,8 +1968,8 @@ FullWidthRepeat2: ' // If we see a /, then it's a date - If CanGet(Here) AndAlso IsDateSeparatorCharacter(Peek(Here)) Then - Dim FirstDateSeparator As Integer = Here + If Peep(Here, ch) AndAlso IsDateSeparatorCharacter(ch) Then + FirstDateSeparator = ch ' // We've got a date HaveDateValue = True @@ -2038,10 +1989,10 @@ FullWidthRepeat2: End If ' Do we have a day value? - If CanGet(Here) AndAlso IsDateSeparatorCharacter(Peek(Here)) Then + If Peep(Here, cx) AndAlso IsDateSeparatorCharacter(cx) Then ' // Check to see they used a consistent separator - If Peek(Here) <> Peek(FirstDateSeparator) Then + If cx <> FirstDateSeparator Then GoTo baddate End If @@ -2063,11 +2014,10 @@ FullWidthRepeat2: End If ' // Do we have a year value? - - If CanGet(Here) AndAlso IsDateSeparatorCharacter(Peek(Here)) Then + If Peep(Here, cx) AndAlso IsDateSeparatorCharacter(cx) Then ' // Check to see they used a consistent separator - If Peek(Here) <> Peek(FirstDateSeparator) Then + If cx <> FirstDateSeparator Then GoTo baddate End If @@ -2106,8 +2056,7 @@ FullWidthRepeat2: If HaveTimeValue Then ' // Do we see a :? - - If CanGet(Here) AndAlso IsColon(Peek(Here)) Then + If Peep(Here, cx) AndAlso IsColon(cx) Then Here += 1 ' // Now let's get the minute value @@ -2120,7 +2069,7 @@ FullWidthRepeat2: ' // Do we have a second value? - If CanGet(Here) AndAlso IsColon(Peek(Here)) Then + If Peep(Here, cx) AndAlso IsColon(cx) Then ' // Yes. HaveSecondValue = True Here += 1 @@ -2135,24 +2084,24 @@ FullWidthRepeat2: ' // Check AM/PM - If CanGet(Here) Then - If Peek(Here) = "A"c OrElse Peek(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_A OrElse - Peek(Here) = "a"c OrElse Peek(Here) = FULLWIDTH_LATIN_SMALL_LETTER_A Then + If Peep(Here, cx) Then + If cx = "A"c OrElse cx = FULLWIDTH_LATIN_CAPITAL_LETTER_A OrElse + cx = "a"c OrElse cx = FULLWIDTH_LATIN_SMALL_LETTER_A Then HaveAM = True Here += 1 - ElseIf Peek(Here) = "P"c OrElse Peek(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_P OrElse - Peek(Here) = "p"c OrElse Peek(Here) = FULLWIDTH_LATIN_SMALL_LETTER_P Then + ElseIf cx = "P"c OrElse cx = FULLWIDTH_LATIN_CAPITAL_LETTER_P OrElse + cx = "p"c OrElse cx = FULLWIDTH_LATIN_SMALL_LETTER_P Then HavePM = True Here += 1 End If - If CanGet(Here) AndAlso (HaveAM OrElse HavePM) Then - If Peek(Here) = "M"c OrElse Peek(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_M OrElse - Peek(Here) = "m"c OrElse Peek(Here) = FULLWIDTH_LATIN_SMALL_LETTER_M Then + If Peep(Here, cx) AndAlso (HaveAM OrElse HavePM) Then + If cx = "M"c OrElse cx = FULLWIDTH_LATIN_CAPITAL_LETTER_M OrElse + cx = "m"c OrElse cx = FULLWIDTH_LATIN_SMALL_LETTER_M Then Here = GetWhitespaceLength(Here + 1) @@ -2169,7 +2118,7 @@ FullWidthRepeat2: End If End If - If Not CanGet(Here) OrElse Not IsHash(Peek(Here)) Then + If Not Peep(Here, ch) OrElse Not IsHash(ch) Then GoTo baddate End If @@ -2281,19 +2230,15 @@ baddate: ' // If we can find a closing #, then assume it's a malformed date, ' // otherwise, it's not a date - While CanGet(Here) - Dim ch As Char = Peek(Here) - If IsHash(ch) OrElse IsNewLine(ch) Then - Exit While - End If + While Peep(Here, ch) AndAlso Not (IsHash(ch) OrElse IsNewLine(ch)) Here += 1 End While - If Not CanGet(Here) OrElse IsNewLine(Peek(Here)) Then + If Not Peep(Here, ch) OrElse IsNewLine(ch) Then ' // No closing # Return Nothing Else - Debug.Assert(IsHash(Peek(Here))) + Debug.Assert(IsHash(ch)) Here += 1 ' consume trailing # Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_InvalidDate) End If @@ -2309,26 +2254,22 @@ baddate: ' // Check for a Char literal, which can be of the form: ' // """"c or ""c - - If CanGet(3) AndAlso IsDoubleQuote(Peek(2)) Then - If IsDoubleQuote(Peek(1)) Then - If IsDoubleQuote(Peek(3)) AndAlso - CanGet(4) AndAlso - IsLetterC(Peek(4)) Then + Dim cx As Char + If Peep(3, cx) AndAlso IsDoubleQuote(Peek(2)) Then + ch = Peek(1) + If IsDoubleQuote(ch) Then + If IsDoubleQuote(cx) AndAlso Peep(4, ch) AndAlso IsLetterC(ch) Then ' // Double-quote Char literal: """"c Return MakeCharacterLiteralToken(precedingTrivia, """"c, 5) End If - ElseIf IsLetterC(Peek(3)) Then + ElseIf IsLetterC(cx) Then ' // Char literal. "x"c - Return MakeCharacterLiteralToken(precedingTrivia, Peek(1), 4) + Return MakeCharacterLiteralToken(precedingTrivia, ch, 4) End If End If - - If CanGet(2) AndAlso - IsDoubleQuote(Peek(1)) AndAlso - IsLetterC(Peek(2)) Then + If Peep(2, ch) AndAlso IsDoubleQuote(Peek(1)) AndAlso IsLetterC(ch) Then ' // Error. ""c is not a legal char constant Return MakeBadToken(precedingTrivia, 3, ERRID.ERR_IllegalCharConstant) @@ -2337,13 +2278,9 @@ baddate: Dim haveNewLine As Boolean = False Dim scratch = GetScratch() - While CanGet(length) - ch = Peek(length) - + While Peep(length, ch) If IsDoubleQuote(ch) Then - If CanGet(length + 1) Then - ch = Peek(length + 1) - + If Peep(length + 1, ch) Then If IsDoubleQuote(ch) Then ' // An escaped double quote scratch.Append(""""c) diff --git a/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb b/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb index 30e698a182c37..7847c892f8b92 100644 --- a/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb +++ b/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb @@ -95,6 +95,34 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return p End Function + ''' + ''' + ''' + ''' Skip Position + ''' The char at the skip position, does not alter current value on false. + ''' True - if it can get the skip position, otherwise False. + Private Function Peep(skip As Integer, ByRef ch As Char) As Boolean + If (_lineBufferOffset + skip < _bufferLen) Then + Debug.Assert(skip >= -MaxCharsLookBehind) + Dim position = _lineBufferOffset + Dim page = _curPage + position += skip + ch = page._arr(position And s_PAGE_MASK) + + Dim start = page._pageStart + Dim expectedStart = position And s_NOT_PAGE_MASK + + If start <> expectedStart Then + page = GetPage(position) + ch = page._arr(position And s_PAGE_MASK) + End If + Return True + Else + Return False + End If + + End Function + ' PERF CRITICAL Private Function Peek(skip As Integer) As Char Debug.Assert(CanGet(skip)) @@ -215,4 +243,4 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return result End Function End Class -End Namespace +End Namespace \ No newline at end of file diff --git a/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb b/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb index 40a522c7dbfdd..db9467271e183 100644 --- a/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb +++ b/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb @@ -19,13 +19,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Dim leadingTriviaLength = GetWhitespaceLength(0) Dim offset = leadingTriviaLength Dim length As Integer - - If Not CanGet(offset) Then + Dim c As Char + If Not Peep(offset, c) Then Return MakeEndOfInterpolatedStringToken() End If - Dim c = Peek(offset) - ' This should only ever happen for $" or } Debug.Assert(leadingTriviaLength = 0 OrElse c = "$"c OrElse c = FULLWIDTH_DOLLAR_SIGN OrElse IsRightCurlyBracket(c)) @@ -37,8 +35,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Select Case c Case "$"c, FULLWIDTH_DOLLAR_SIGN + Dim ch As Char - If CanGet(offset + 1) AndAlso IsDoubleQuote(Peek(offset + 1)) Then + If Peep(offset + 1, ch) AndAlso IsDoubleQuote(ch) Then kind = SyntaxKind.DollarSignDoubleQuoteToken length = 2 scanTrailingTrivia = False ' Trailing whitespace should be scanned as interpolated string text. @@ -74,7 +73,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Case Else If IsDoubleQuote(c) Then - Debug.Assert(Not CanGet(offset + 1) OrElse Not IsDoubleQuote(Peek(offset + 1))) + Dim ch As Char + Debug.Assert(Not Peep(offset + 1, ch) OrElse Not IsDoubleQuote(ch)) kind = SyntaxKind.DoubleQuoteToken length = 1 @@ -112,22 +112,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Function IsInterpolatedStringPunctuation(Optional offset As Integer = 0) As Boolean - If Not CanGet(offset) Then Return False - - Dim c = Peek(offset) + Dim c As Char + If Not Peep(offset, c) Then Return False If IsLeftCurlyBracket(c) Then - Return Not CanGet(offset + 1) OrElse Not IsLeftCurlyBracket(Peek(offset + 1)) + Return Not Peep(offset + 1, c) OrElse Not IsLeftCurlyBracket(c) ElseIf IsRightCurlyBracket(c) Then - Return Not CanGet(offset + 1) OrElse Not IsRightCurlyBracket(Peek(offset + 1)) + Return Not Peep(offset + 1, c) OrElse Not IsRightCurlyBracket(c) ElseIf IsDoubleQuote(c) 'A subtle difference between this case and the one above. ' In both interpolated and literal strings the two quote characters used in an escape sequence don't have to match. ' It's enough that the next character is *a* quote char. It doesn't have to be the same quote. ' If we want to preserve consistency the quotes need to be special cased. - Return Not CanGet(offset + 1) OrElse Not IsDoubleQuote(Peek(offset + 1)) + Return Not Peep(offset + 1, c) OrElse Not IsDoubleQuote(c) Else Return False @@ -135,22 +134,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function Private Function ScanInterpolatedStringText(scanTrailingWhitespaceAsTrivia As Boolean) As SyntaxToken - If Not CanGet() Then Return MakeEndOfInterpolatedStringToken() + Dim c As Char + If Not Peep(0, c) Then Return MakeEndOfInterpolatedStringToken() Dim offset = 0 Dim pendingWhitespace = 0 Dim valueBuilder = GetScratch() - - Do While CanGet(offset) - - Dim c = Peek(offset) + Dim ch As Char + Do While Peep(offset, c) ' Any combination of fullwidth and ASCII curly braces of the same direction is an escaping sequence for the corresponding ASCII curly brace. ' We insert that curly brace doubled and because this is the escaping sequence understood by String.Format, that will be replaced by a single brace. ' This is deliberate design and it aligns with existing rules for double quote escaping in strings. If IsLeftCurlyBracket(c) Then - If CanGet(offset + 1) AndAlso IsLeftCurlyBracket(Peek(offset + 1)) Then + If Peep(offset + 1, ch) AndAlso IsLeftCurlyBracket(ch) Then ' This is an escape sequence. valueBuilder.Append("{{") @@ -164,7 +162,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ElseIf IsRightCurlyBracket(c) Then - If CanGet(offset + 1) AndAlso IsRightCurlyBracket(Peek(offset + 1)) Then + If Peep(offset + 1, ch) AndAlso IsRightCurlyBracket(ch) Then ' This is an escape sequence. valueBuilder.Append("}}") @@ -178,7 +176,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ElseIf IsDoubleQuote(c) - If CanGet(offset + 1) AndAlso IsDoubleQuote(Peek(offset + 1)) Then + If Peep(offset + 1, ch) AndAlso IsDoubleQuote(ch) Then ' This is a VB double quote escape. Oddly enough this logic allows mixing and matching of ' smart and dumb double quotes in any order. Regardless we always emit as a standard double quote. ' This is consistent with their handling in string literals. @@ -232,4 +230,4 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End Function End Class -End Namespace +End Namespace \ No newline at end of file diff --git a/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb b/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb index 4c743cb28de4e..04c79d50b4b4c 100644 --- a/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb +++ b/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb @@ -34,10 +34,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Exit Do End If - If Not CanGet(len) Then + If Not Peep(len, c) Then Exit Do End If - c = Peek(len) Loop If len > 0 Then @@ -68,9 +67,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax ' // Whitespace Dim leadingTrivia As SyntaxList(Of VisualBasicSyntaxNode) = Nothing - - While CanGet() - Dim c As Char = Peek() + Dim c As Char + While Peep(0, c) Select Case (c) ' // Whitespace @@ -93,7 +91,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax leadingTrivia = ScanXmlTrivia(c) Case "/"c - If CanGet(1) AndAlso Peek(1) = ">" Then + If Peep(1, c) AndAlso c = ">"c Then Return XmlMakeEndEmptyElementToken(leadingTrivia) End If Return XmlMakeDivToken(leadingTrivia) @@ -113,12 +111,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return XmlMakeDoubleQuoteToken(leadingTrivia, c, isOpening:=True) Case "<"c - If CanGet(1) Then - Dim ch As Char = Peek(1) - Select Case ch + If Peep(1, c) Then + Select Case c Case "!"c - If CanGet(2) Then - Select Case (Peek(2)) + If Peep(2, c) Then + Select Case c Case "-"c If NextIs(3, "-"c) Then Return XmlMakeBeginCommentToken(leadingTrivia, s_scanNoTriviaFunc) @@ -128,7 +125,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax Return XmlMakeBeginCDataToken(leadingTrivia, s_scanNoTriviaFunc) End If Case "D"c - If Nextare(3, "OCTYPE") Then + If NextAre(3, "OCTYPE") Then Return XmlMakeBeginDTDToken(leadingTrivia) End If End Select @@ -207,14 +204,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax '// NL WS* ' '// Example ' This is a comment Private Function ScanXmlForPossibleStatement(state As ScannerState) As Boolean - If Not CanGet() Then + Dim c As Char + If Not Peep(0, c) Then Return False End If Dim token As SyntaxToken Dim possibleStatement As Boolean = False Dim offsets = CreateOffsetRestorePoint() - Dim c As Char = Peek() Select Case c Case "#"c, @@ -308,9 +305,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End If Dim scratch = GetScratch() - - While CanGet(Here) - Dim c As Char = Peek(Here) + Dim c As Char + While Peep(Here, c) Select Case (c) Case CARRIAGE_RETURN, LINE_FEED @@ -342,12 +338,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax End If Debug.Assert(Here = 0) - If CanGet(1) Then - Dim ch As Char = Peek(1) - Select Case ch + If Peep(1, c) Then + Select Case c Case "!"c - If CanGet(2) Then - Select Case (Peek(2)) + If Peep(2, c) Then + Select Case c Case "-"c If NextIs(3, "-"c) Then Return XmlMakeBeginCommentToken(precedingTrivia, s_scanNoTriviaFunc) @@ -492,8 +487,8 @@ ScanChars: End If Dim Here = 0 - While CanGet(Here) - Dim c As Char = Peek(Here) + Dim c As Char + While Peep(Here, c) Select Case (c) Case CARRIAGE_RETURN, LINE_FEED @@ -511,9 +506,8 @@ ScanChars: Return XmlMakeCommentToken(precedingTrivia, Here) End If - If CanGet(Here + 2) Then + If Peep(Here + 2, c) Then - c = Peek(Here + 2) Here += 2 ' // if > is not found then this is an error. Return the -- string @@ -583,9 +577,9 @@ ScanChars: Dim scratch = GetScratch() Dim Here = 0 + Dim c As Char - While CanGet(Here) - Dim c As Char = Peek(Here) + While Peep(Here, c) Select Case (c) Case CARRIAGE_RETURN, LINE_FEED @@ -647,11 +641,11 @@ ScanChars: Dim precedingTrivia = _triviaListPool.Allocate(Of VisualBasicSyntaxNode)() Dim result As SyntaxToken + Dim c As Char - If state = ScannerState.StartProcessingInstruction AndAlso CanGet() Then + If state = ScannerState.StartProcessingInstruction AndAlso Peep(0, c) Then ' // Whitespace ' // S ::= (#x20 | #x9 | #xD | #xA)+ - Dim c = Peek() Select Case c Case CARRIAGE_RETURN, LINE_FEED, " "c, CHARACTER_TABULATION Dim wsTrivia = ScanXmlTrivia(c) @@ -660,8 +654,7 @@ ScanChars: End If Dim Here = 0 - While CanGet(Here) - Dim c As Char = Peek(Here) + While Peep(Here, c) Select Case (c) Case CARRIAGE_RETURN, LINE_FEED @@ -720,8 +713,8 @@ CleanUp: ' // Misc ::= Comment | PI | S Dim precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode) = Nothing - While CanGet() - Dim c As Char = Peek() + Dim c As Char + While Peep(0, c) Select Case (c) ' // Whitespace @@ -732,9 +725,8 @@ CleanUp: precedingTrivia = ScanXmlTrivia(c) Case "<"c - If CanGet(1) Then - Dim ch As Char = Peek(1) - Select Case ch + If Peep(1, c) Then + Select Case c Case "!"c If NextAre(2, "--") Then Return XmlMakeBeginCommentToken(precedingTrivia, s_scanNoTriviaFunc) @@ -752,31 +744,31 @@ CleanUp: Return XmlMakeLessToken(precedingTrivia) - ' TODO: review + ' TODO: review - ' If Not m_State.m_ScannedElement OrElse c = "?"c OrElse c = "!"c Then - ' ' // Remove tEOL from token ring if any exists + ' If Not m_State.m_ScannedElement OrElse c = "?"c OrElse c = "!"c Then + ' ' // Remove tEOL from token ring if any exists - ' If tEOL IsNot Nothing Then - ' m_FirstFreeToken = tEOL - ' End If + ' If tEOL IsNot Nothing Then + ' m_FirstFreeToken = tEOL + ' End If - ' m_State.m_LexicalState = LexicalState.XmlMarkup - ' MakeToken(tokens.tkLT, 1) - ' m_InputStreamPosition += 1 - ' Return - ' End If - 'End If + ' m_State.m_LexicalState = LexicalState.XmlMarkup + ' MakeToken(tokens.tkLT, 1) + ' m_InputStreamPosition += 1 + ' Return + ' End If + 'End If - 'm_State.EndXmlState() + 'm_State.EndXmlState() - 'If tEOL IsNot Nothing Then - ' tEOL.m_EOL.m_NextLineAlreadyScanned = True - 'Else - ' MakeToken(tokens.tkLT, 1) - ' m_InputStreamPosition += 1 - 'End If - 'Return + 'If tEOL IsNot Nothing Then + ' tEOL.m_EOL.m_NextLineAlreadyScanned = True + 'Else + ' MakeToken(tokens.tkLT, 1) + ' m_InputStreamPosition += 1 + 'End If + 'Return Case Else Return SyntaxFactory.Token(precedingTrivia.Node, SyntaxKind.EndOfXmlToken, Nothing, String.Empty) @@ -795,9 +787,9 @@ CleanUp: Dim Here = 0 Dim scratch = GetScratch() + Dim c As Char - While CanGet(Here) - Dim c As Char = Peek(Here) + While Peep(Here, c) Select Case (c) @@ -888,9 +880,8 @@ ScanChars: Dim Here = 0 Dim scratch = GetScratch() - - While CanGet(Here) - Dim c As Char = Peek(Here) + Dim c As Char + While Peep(Here, c) If c = terminatingChar Or c = altTerminatingChar Then If Here > 0 Then result = XmlMakeAttributeDataToken(precedingTrivia, Here, scratch) @@ -988,12 +979,15 @@ CleanUp: ''' 1 is an error ''' Private Function ScanSurrogatePair(c1 As Char, Here As Integer) As XmlCharResult + Dim c2 As Char +#If DEBUG Then Debug.Assert(Here >= 0) - Debug.Assert(CanGet(Here)) - Debug.Assert(Peek(Here) = c1) + Dim ok = Peep(Here, c2) + Debug.Assert(ok) + Debug.Assert(c2 = c1) +#End If - If IsHighSurrogate(c1) AndAlso CanGet(Here + 1) Then - Dim c2 = Peek(Here + 1) + If IsHighSurrogate(c1) AndAlso Peep(Here + 1, c2) Then If IsLowSurrogate(c2) Then Return New XmlCharResult(c1, c2) @@ -1033,9 +1027,9 @@ CleanUp: Private Function ScanXmlChar(Here As Integer) As XmlCharResult Debug.Assert(Here >= 0) - Debug.Assert(CanGet(Here)) - - Dim c = Peek(Here) + Dim c As Char + Dim ok = Peep(Here, c) + Debug.Assert(ok) If Not isValidUtf16(c) Then Return Nothing @@ -1066,8 +1060,8 @@ CleanUp: 'TODO - Fix ScanXmlNCName to conform to XML spec instead of old loose scanning. - While CanGet(Here) - Dim c As Char = Peek(Here) + Dim c As Char + While Peep(Here, c) Select Case (c) @@ -1134,8 +1128,8 @@ CreateNCNameToken: Debug.Assert(Peek() = "&"c) ' skip 1 char for "&" - If CanGet(1) Then - Dim c As Char = Peek(1) + Dim c As Char + If Peep(1, c) Then Select Case (c) Case "#"c @@ -1150,7 +1144,8 @@ CreateNCNameToken: value = Intern({result.Char1, result.Char2}) End If - If CanGet(Here) AndAlso Peek(Here) = ";"c Then + Dim ch As Char + If Peep(Here, ch) AndAlso ch = ";"c Then Return XmlMakeEntityLiteralToken(precedingTrivia, Here + 1, value) Else Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, Here, value) @@ -1162,9 +1157,8 @@ CreateNCNameToken: Case "a"c ' // & ' // ' - - If CanGet(4) AndAlso NextAre(2, "mp") Then - If Peek(4) = ";"c Then + If Peep(4, c) AndAlso NextAre(2, "mp") Then + If c = ";"c Then Return XmlMakeAmpLiteralToken(precedingTrivia) Else Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 4, "&") @@ -1172,9 +1166,9 @@ CreateNCNameToken: Return DirectCast(noSemicolon.SetDiagnostics({noSemicolonError}), XmlTextTokenSyntax) End If - ElseIf CanGet(5) AndAlso NextAre(2, "pos") Then + ElseIf Peep(5, c) AndAlso NextAre(2, "pos") Then - If Peek(5) = ";"c Then + If c = ";"c Then Return XmlMakeAposLiteralToken(precedingTrivia) Else Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 5, "'") @@ -1185,10 +1179,9 @@ CreateNCNameToken: Case "l"c ' // < + If Peep(3, c) AndAlso NextIs(2, "t"c) Then - If CanGet(3) AndAlso NextIs(2, "t"c) Then - - If Peek(3) = ";"c Then + If c = ";"c Then Return XmlMakeLtLiteralToken(precedingTrivia) Else Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 3, "<") @@ -1199,10 +1192,9 @@ CreateNCNameToken: Case "g"c ' // > + If Peep(3, c) AndAlso NextIs(2, "t"c) Then - If CanGet(3) AndAlso NextIs(2, "t"c) Then - - If Peek(3) = ";"c Then + If c = ";"c Then Return XmlMakeGtLiteralToken(precedingTrivia) Else Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 3, ">") @@ -1213,10 +1205,9 @@ CreateNCNameToken: Case "q"c ' // " + If Peep(5, c) AndAlso NextAre(2, "uot") Then - If CanGet(5) AndAlso NextAre(2, "uot") Then - - If Peek(5) = ";"c Then + If c = ";"c Then Return XmlMakeQuotLiteralToken(precedingTrivia) Else Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 5, """") @@ -1236,8 +1227,8 @@ CreateNCNameToken: Private Function ScanXmlCharRef(ByRef index As Integer) As XmlCharResult Debug.Assert(index >= 0) - - If Not CanGet(index) Then + Dim ch As Char + If Not Peep(index, ch) Then Return Nothing End If @@ -1245,12 +1236,11 @@ CreateNCNameToken: Dim charRefSb As New StringBuilder Dim Here = index - Dim ch = Peek(Here) If ch = "x"c Then Here += 1 - While CanGet(Here) - ch = Peek(Here) + While Peep(Here, ch) + If XmlCharType.IsHexDigit(ch) Then charRefSb.Append(ch) Else @@ -1266,8 +1256,8 @@ CreateNCNameToken: Return result End If Else - While CanGet(Here) - ch = Peek(Here) + While Peep(Here, ch) + If XmlCharType.IsDigit(ch) Then charRefSb.Append(ch) Else