📄 tokenmanager.vb
字号:
''' <param name="GotoNewline"></param> ''' <returns></returns> ''' <remarks></remarks> Function AcceptIfNotError(ByVal Special As KS, ByVal Message As Messages, Optional ByVal GotoNewline As Boolean = False) As Boolean If Accept(Special) Then Return True Else If GotoNewline Then Me.GotoNewline(True) Compiler.Report.ShowMessage(Message) Return False End If End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> ''' <param name="Special"></param> ''' <param name="Message"></param> ''' <param name="GotoNewline"></param> ''' <returns></returns> ''' <remarks></remarks> <Diagnostics.DebuggerHidden()> Function AcceptIfNotError(ByVal Special As KS, ByVal Message As Messages, ByVal GotoNewline As Boolean, ByVal MessageParameters() As String) As Boolean If Accept(Special) Then Return True Else If GotoNewline Then Me.GotoNewline(True) Compiler.Report.ShowMessage(Message, MessageParameters) Return False End If End Function <Diagnostics.DebuggerHidden()> Function AcceptIfNotError(ByVal Special As KS, ByVal Message As Messages, ByVal GotoNewline As Boolean, ByVal MessageParameter As String) As Boolean If Accept(Special) Then Return True Else If GotoNewline Then Me.GotoNewline(True) Compiler.Report.ShowMessage(Message, MessageParameter) Return False End If End Function ''' <summary> ''' GotoNewline defaults to false for this overload. ''' </summary> ''' <param name="Special"></param> ''' <param name="Message"></param> ''' <returns></returns> ''' <remarks></remarks> Function AcceptIfNotError(ByVal Special As KS, ByVal Message As Messages, ByVal ParamArray MessageParameters() As String) As Boolean Return AcceptIfNotError(Special, Message, False, MessageParameters) End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' Accepts only newline, not endofcode, nor endoffile. ''' </summary> ''' <param name="GotoNewline"></param> ''' <param name="EOFIsError">Specifies whether to return false if the current token is EOF or not.</param> ''' <returns></returns> ''' <remarks></remarks> Function AcceptNewLine(Optional ByVal GotoNewline As Boolean = False, Optional ByVal EOFIsError As Boolean = True, Optional ByVal ReportError As Boolean = False) As Boolean If CurrentToken.IsEndOfLine Then If CurrentToken.IsEndOfLineOnly Then NextToken() Return True ElseIf EOFIsError = False Then Return True Else Return False End If Else If GotoNewline Then Me.GotoNewline(True, ReportError) Return False End If End Function ''' <summary> ''' Accepts Newline or : (not endoffile, nor endofcode) ''' If ReportError = True then: ''' - reports an error if currenttoken != ks.colon AND currenttoken != newline ''' doesn't matter if OnlyColon is true or not. ''' </summary> ''' <param name="OnlyColon">Set to true to only accept colon, not even NewLine</param> ''' <returns></returns> ''' <remarks></remarks> Function AcceptEndOfStatement(Optional ByVal OnlyColon As Boolean = False, Optional ByVal ReportError As Boolean = False) As Boolean Dim result As Boolean = True If OnlyColon Then result = Accept(KS.Colon) If ReportError AndAlso result = False AndAlso CurrentToken.IsEndOfLineOnly = False Then#If DEBUG Then System.Console.WriteLine("Found: " & CurrentToken.ToString)#End If Compiler.Report.ShowMessage(Messages.VBNC30205) End If Return result Else If CurrentToken.IsEndOfLineOnly OrElse CurrentToken() = KS.Colon Then Do NextToken() Loop While CurrentToken.IsEndOfLineOnly OrElse CurrentToken.Equals(KS.Colon) Return True Else If ReportError Then#If DEBUG Then System.Console.WriteLine("Found: " & CurrentToken.ToString)#End If Compiler.Report.ShowMessage(Messages.VBNC30205) End If Return False End If End If End Function Function AcceptEndOfFile() As Boolean If CurrentToken.IsEndOfFile Then NextToken() Return True Else Return False End If End Function Function AcceptIdentifier(ByRef result As Token) As Boolean Dim tmp As Token = CurrentToken() If CurrentToken.IsIdentifier Then result = CurrentToken() If tmp.IsIdentifier = False Then Throw New InternalException("Not an identifier?????") If CurrentToken.IsIdentifier = False Then Throw New InternalException("Not an identifier???") If result.IsIdentifier = False Then Throw New InternalException("Not an identifier?") NextToken() Return True Else Return False End If End Function ''' <summary> ''' Returns true if the current token is an identifier ''' and advances to the next token. ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Function AcceptIdentifier(Optional ByVal GotoNewline As Boolean = False) As Boolean If CurrentToken.IsIdentifier Then NextToken() Return True Else If GotoNewline Then Me.GotoNewline(True) Return False End If End Function Function AcceptStringLiteral(Optional ByVal GotoNewline As Boolean = False) As Boolean If CurrentToken.IsStringLiteral Then NextToken() Return True Else If GotoNewline Then Me.GotoNewline(True) Return False End If End Function Shared Function AcceptStringLiteral(ByVal Reader As ITokenReader, Optional ByVal GotoNewline As Boolean = False) As Boolean If Reader.Peek.IsStringLiteral Then Reader.Next() Return True Else If GotoNewline Then tm.GotoNewline(Reader, True) Return False End If End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> ''' <param name="GotoNewline"></param> ''' <returns></returns> ''' <remarks></remarks> Function AcceptIntegerLiteral(Optional ByVal GotoNewline As Boolean = False) As Boolean If CurrentToken.IsIntegerLiteral Then NextToken() Return True Else If GotoNewline Then Me.GotoNewline(True) Return False End If End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> ''' <param name="GotoNewline"></param> ''' <returns></returns> ''' <remarks></remarks> Shared Function AcceptIntegerLiteral(ByVal Reader As ITokenReader, Optional ByVal GotoNewline As Boolean = False) As Boolean If Reader.Peek.IsIntegerLiteral Then Reader.Next() Return True Else If GotoNewline Then tm.GotoNewline(Reader, True) Return False End If End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> ''' <param name="Special"></param> ''' <param name="GotoNewline"></param> ''' <returns></returns> ''' <remarks></remarks> Function Accept(ByVal Special As KS, Optional ByVal GotoNewline As Boolean = False) As Boolean If CurrentToken.Equals(Special) Then Accept = True NextToken() Else If GotoNewline Then Me.GotoNewline(True) Accept = False End If End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> ''' <param name="Special"></param> ''' <param name="GotoNewline"></param> ''' <returns></returns> ''' <remarks></remarks> Shared Function Accept(ByVal Reader As ITokenReader, ByVal Special As KS, Optional ByVal GotoNewline As Boolean = False) As Boolean If Reader.Peek.Equals(Special) Then Accept = True Reader.Next() Else If GotoNewline Then tm.GotoNewline(Reader, True) Accept = False End If End Function ''' <summary> ''' If GotoNewline = true then calls GotoNewline(True) - next token is the first one after the newline. ''' </summary> Function Accept(ByVal Identifier As String, Optional ByVal GotoNewline As Boolean = False) As Boolean If CurrentToken.Equals(Identifier) Then Accept = True NextToken() Else If GotoNewline Then Me.GotoNewline(True) Accept = False End If End Function Function AcceptAny(ByVal ParamArray Keywords() As KS) As Boolean Dim i As Integer For i = 0 To Keywords.Length - 1 If Accept(Keywords(i)) Then Return True End If Next Return False End Function Function AcceptAll(ByVal ParamArray Specials() As KS) As Boolean Dim i As Integer AcceptAll = True For i = 0 To Specials.Length - 1 AcceptAll = PeekToken(i).Equals(Specials(i)) AndAlso AcceptAll Next If AcceptAll Then NextToken(Specials.Length) End FunctionEnd Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -