parser.vb

来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 1,498 行 · 第 1/4 页

VB
1,498
字号
            If ShowErrors Then Compiler.Report.ShowMessage(Messages.VBNC90007, tm.CurrentToken.Location, tm.CurrentToken.ToString)            Return Nothing        End If        m_ArrayNameModifier = ParseArrayNameModifier(result)        If m_ArrayNameModifier Is Nothing Then            If m_ShowErrors = False Then Return Nothing            Helper.ErrorRecoveryNotImplemented()        End If        If tm.CurrentToken <> KS.LBrace Then            If ShowErrors Then tm.AcceptIfNotError(KS.LBrace)            Return Nothing        End If        m_ArrayElementInitializer = ParseArrayElementInitializer(result)        If m_ArrayElementInitializer Is Nothing Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_NonArrayTypeName, m_ArrayNameModifier, m_ArrayElementInitializer)        Return result    End Function    ''' <summary>    ''' ArrayElementInitializer  ::=  {  [  VariableInitializerList  ]  }    ''' </summary>    ''' <remarks></remarks>    Private Function ParseArrayElementInitializer(ByVal Parent As ParsedObject) As ArrayElementInitializer        Dim result As New ArrayElementInitializer(Parent)        Dim m_VariableInitializerList As VariableInitializerList        m_VariableInitializerList = New VariableInitializerList(result)        tm.AcceptIfNotInternalError(KS.LBrace)        If tm.Accept(KS.RBrace) = False Then            If ParseList(Of VariableInitializer)(m_VariableInitializerList, New ParseDelegate_Parent(Of VariableInitializer)(AddressOf ParseVariableInitializer), result) = False Then                Helper.ErrorRecoveryNotImplemented()            End If            If tm.AcceptIfNotError(KS.RBrace) = False Then Helper.ErrorRecoveryNotImplemented()        End If        result.Init(m_VariableInitializerList)        Return result    End Function    ''' <summary>    ''' VariableInitializer  ::=  RegularInitializer  |  ArrayElementInitializer    ''' RegularInitializer ::= Expression    ''' </summary>    ''' <remarks></remarks>    Private Function ParseVariableInitializer(ByVal Parent As ParsedObject) As VariableInitializer        Dim result As New VariableInitializer(Parent)        If ArrayElementInitializer.CanBeMe(tm) Then            Dim newAEI As ArrayElementInitializer            newAEI = ParseArrayElementInitializer(Parent)            result.Init(newAEI)        Else            Dim newExp As Expression            newExp = ParseExpression(Parent)            result.Init(newExp)        End If        Return result    End Function    ''' <summary>    ''' ArrayNameModifier  ::=	ArrayTypeModifiers  |	ArraySizeInitializationModifier    ''' </summary>    ''' <remarks></remarks>    Private Function ParseArrayNameModifier(ByVal Parent As ParsedObject) As ArrayNameModifier        Dim result As New ArrayNameModifier(Parent)        If ArrayTypeModifiers.CanBeMe(tm) Then            Dim newATM As ArrayTypeModifiers            newATM = ParseArrayTypeModifiers(result)            If newATM Is Nothing Then Helper.ErrorRecoveryNotImplemented()            result.Init(newATM)        ElseIf ArraySizeInitializationModifier.CanBeMe(tm) Then            Dim newASIM As ArraySizeInitializationModifier            newASIM = ParseArraySizeInitializationModifer(result)            If newASIM Is Nothing Then                If m_ShowErrors = False Then Return Nothing                Helper.ErrorRecoveryNotImplemented()            End If            result.Init(newASIM)        Else            Throw New InternalException(result)        End If        Return result    End Function    ''' <summary>    ''' ArraySizeInitializationModifier  ::= "("  BoundList  ")"  [  ArrayTypeModifiers  ]    ''' LAMESPEC this might be correct? REMOVED, CURRENTLY USING ^ SPEC!    ''' ArraySizeInitializationModifier  ::= "("  [ BoundList]  ")"  [  ArrayTypeModifiers  ]    ''' </summary>    ''' <remarks></remarks>    Private Function ParseArraySizeInitializationModifer(ByVal Parent As ParsedObject) As ArraySizeInitializationModifier        Dim result As New ArraySizeInitializationModifier(Parent)        Dim m_BoundList As BoundList = Nothing        Dim m_ArrayTypeModifiers As ArrayTypeModifiers = Nothing        tm.AcceptIfNotInternalError(KS.LParenthesis)        m_BoundList = ParseBoundList(result)        If m_BoundList Is Nothing Then            If m_ShowErrors = False Then Return Nothing            Helper.ErrorRecoveryNotImplemented()        End If        If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        If vbnc.ArrayTypeModifiers.CanBeMe(tm) Then            m_ArrayTypeModifiers = ParseArrayTypeModifiers(result)            If m_ArrayTypeModifiers Is Nothing Then Helper.ErrorRecoveryNotImplemented()        End If        result.Init(m_BoundList, m_ArrayTypeModifiers)        Return result    End Function    ''' <summary>    ''' InterfaceBase   ::= Inherits  InterfaceBases  StatementTerminator    ''' InterfaceBases  ::= NonArrayTypeName  | InterfaceBases  ","  NonArrayTypeName    ''' </summary>    ''' <remarks></remarks>    Private Function ParseInterfaceBases(ByVal Parent As ParsedObject) As InterfaceBases        Dim result As New InterfaceBases(Parent)        Dim tmp As New Generic.List(Of NonArrayTypeName)        Do While tm.Accept(KS.Inherits)            Do                Dim newBase As NonArrayTypeName                newBase = ParseNonArrayTypeName(result)                tmp.Add(newBase)            Loop While tm.Accept(KS.Comma)            If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        Loop        If tmp.Count <= 0 Then Helper.ErrorRecoveryNotImplemented()        result.Init(tmp.ToArray)        Return result    End Function    ''' <summary>    ''' TypeImplementsClause  ::=  "Implements" Implements StatementTerminator    ''' Implements  ::=	NonArrayTypeName  |	Implements  ","  NonArrayTypeName    ''' </summary>    ''' <remarks></remarks>    Private Function ParseTypeImplementsClauses(ByVal Parent As ParsedObject) As TypeImplementsClauses        Dim result As New TypeImplementsClauses(Parent)        Dim m_Clauses As New Generic.List(Of NonArrayTypeName)        Do While tm.Accept(KS.Implements)            Do                Dim newI As NonArrayTypeName                newI = ParseNonArrayTypeName(result)                If newI Is Nothing Then Helper.ErrorRecoveryNotImplemented()                m_Clauses.Add(newI)            Loop While tm.Accept(KS.Comma)            If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        Loop        result.Init(m_Clauses)        Return result    End Function    ''' <summary>    ''' BoundList::= Expression | "0" "To" Expression  | UpperBoundList ,  Expression    ''' UpperBoundList::= Expression | UpperBoundList , Expression    ''' </summary>    ''' <remarks></remarks>    Private Function ParseBoundList(ByVal Parent As ParsedObject) As BoundList        Dim result As New BoundList(Parent)        Dim newExp As Expression = Nothing        Dim tmp As New Generic.List(Of Expression)        Do            If tm.CurrentToken.IsIntegerLiteral AndAlso tm.CurrentToken.IntegralLiteral = 0 AndAlso tm.PeekToken.Equals(KS.To) Then tm.NextToken(2)            newExp = ParseExpression(result)            If newExp Is Nothing Then                If m_ShowErrors = False Then Return Nothing                Helper.ErrorRecoveryNotImplemented()            End If            tmp.Add(newExp)        Loop While tm.Accept(KS.Comma)        result.Init(tmp.ToArray)        Return result    End Function    ''' <summary>    ''' NonArrayTypeName  ::= SimpleTypeName  |	ConstructedTypeName    ''' SimpleTypeName    ::= QualifiedIdentifier  |	*BuiltInTypeName*    ''' BuiltInTypeName   ::= "Object"  |  *PrimitiveTypeName*    ''' PrimitiveTypeName      ::=  *NumericTypeName*  |  "Boolean" |  "Date"  |  "Char"  |  "String"    ''' NumericTypeName        ::=  *IntegralTypeName*  |  *FloatingPointTypeName*  |  "Decimal"    ''' IntegralTypeName       ::=  "Byte"  |  "SByte"  |  "UShort"  |  "Short"  |  "UInteger"  |  "Integer"  |  "ULong"  |  "Long"    ''' FloatingPointTypeName  ::=  "Single"  |  "Double"    ''' ConstructedTypeName    ::=  QualifiedIdentifier  "("  "Of"  TypeArgumentList  ")"    ''' </summary>    ''' <remarks></remarks>    Private Function ParseNonArrayTypeName(ByVal Parent As ParsedObject) As NonArrayTypeName        Dim result As New NonArrayTypeName(Parent)        Dim m_SimpleTypeName As SimpleTypeName        Dim m_ConstructedTypeName As ConstructedTypeName        m_SimpleTypeName = ParseSimpleTypeName(result)        If m_SimpleTypeName Is Nothing Then Return Nothing        If m_SimpleTypeName.IsQualifiedIdentifier AndAlso tm.CurrentToken = KS.LParenthesis AndAlso tm.PeekToken = KS.Of Then            Dim m_TypeArgumentList As TypeArgumentList            m_TypeArgumentList = ParseTypeArgumentList(result)            If m_TypeArgumentList Is Nothing Then Return Nothing            m_ConstructedTypeName = New ConstructedTypeName(result, m_SimpleTypeName.AsQualifiedIdentifier, m_TypeArgumentList)            result.Init(m_ConstructedTypeName)        Else            result.Init(m_SimpleTypeName)        End If        Return result    End Function    ''' <summary>    ''' ConstructedTypeName ::=	QualifiedIdentifier  "("  "Of"  TypeArgumentList  ")"    ''' </summary>    ''' <remarks></remarks>    Private Function ParseConstructedTypeName(ByVal Parent As ParsedObject) As ConstructedTypeName        Dim result As New ConstructedTypeName(Parent)        Dim m_QualifiedIdentifier As QualifiedIdentifier = Nothing        Dim m_TypeArgumentList As TypeArgumentList = Nothing        m_QualifiedIdentifier = ParseQualifiedIdentifier(result)        If m_QualifiedIdentifier Is Nothing Then Helper.ErrorRecoveryNotImplemented()        tm.AcceptIfNotInternalError(KS.LParenthesis)        tm.AcceptIfNotInternalError(KS.Of)        If ParseList(Of TypeName)(m_TypeArgumentList, New ParseDelegate_Parent(Of TypeName)(AddressOf ParseTypeName), Parent) = False Then            Helper.ErrorRecoveryNotImplemented()        End If        If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_QualifiedIdentifier, m_TypeArgumentList)        Return result    End Function    ''' <summary>    ''' TypeArgumentList ::=	"("  "Of"  TypeArgumentList  ")"    ''' </summary>    ''' <remarks></remarks>    Private Function ParseTypeArgumentList(ByVal Parent As ParsedObject) As TypeArgumentList        Dim result As New TypeArgumentList(Parent)        tm.AcceptIfNotInternalError(KS.LParenthesis)        tm.AcceptIfNotInternalError(KS.Of)        If ParseList(Of TypeName)(result, New ParseDelegate_Parent(Of TypeName)(AddressOf ParseTypeName), Parent) = False Then            Return Nothing        End If        If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        Return result    End Function    ''' <summary>    ''' TypeName ::= ArrayTypeName | NonArrayTypeName    '''     ''' ArrayTypeName          ::=  NonArrayTypeName  ArrayTypeModifiers    ''' ArrayTypeModifiers     ::=  ArrayTypeModifier+    ''' ArrayTypeModifier      ::=  "("  [  RankList  ]  ")"    ''' RankList               ::=  ","  | RankList    ''' </summary>    ''' <remarks></remarks>    Private Function ParseTypeName(ByVal Parent As ParsedObject) As TypeName        Dim result As New TypeName(Parent)        Dim m_NonArrayTypeName As NonArrayTypeName        Dim m_ArrayTypeModifiers As ArrayTypeModifiers        Dim m_ArrayTypeName As ArrayTypeName        m_NonArrayTypeName = ParseNonArrayTypeName(result)        If m_NonArrayTypeName Is Nothing Then Return Nothing        If ArrayTypeName.CanBeArrayTypeModifier(tm) Then            m_ArrayTypeName = New ArrayTypeName(Parent)            m_ArrayTypeModifiers = ParseArrayTypeModifiers(m_ArrayTypeName)            If m_ArrayTypeModifiers Is Nothing Then Helper.ErrorRecoveryNotImplemented()            m_NonArrayTypeName.Parent = m_ArrayTypeName            m_ArrayTypeName.Init(m_NonArrayTypeName, m_ArrayTypeModifiers)            result.Init(m_ArrayTypeName)        Else            result.Init(m_NonArrayTypeName)        End If        Return result    End Function    ''' <summary>    ''' ArrayTypeModifiers  ::=  ArrayTypeModifier+    ''' </summary>    ''' <remarks></remarks>    Private Function ParseArrayTypeModifiers(ByVal Parent As ParsedObject) As ArrayTypeModifiers        Dim result As New ArrayTypeModifiers(Parent)        Dim tmp As New Generic.List(Of ArrayTypeModifier)        Do            Dim newATM As ArrayTypeModifier            newATM = ParseArrayTypeModifier(result)            If newATM Is Nothing Then Helper.ErrorRecoveryNotImplemented()            tmp.Add(newATM)        Loop While ArrayTypeModifier.CanBeMe(tm)        result.Init(tmp.ToArray)        Return result    End Function    ''' <summary>    ''' ArrayTypeModifier  ::=  "("  [  RankList  ]  ")"    ''' RankList  ::= ","  | RankList  ","    ''' </summary>    ''' <remarks></remarks>    Private Function ParseArrayTypeModifier(ByVal Parent As ParsedObject) As ArrayTypeModifier        Dim result As New ArrayTypeModifier(Parent)        tm.AcceptIfNotInternalError(KS.LParenthesis)        Dim m_Ranks As Integer        Do            m_Ranks += 1        Loop While tm.Accept(KS.Comma)        If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        result.Init(m_Ranks)        Return result    End Function    ''' <summary>    ''' SimpleTypeName ::= QualifiedIdentifier | BuiltInTypeName    ''' </summary>    ''' <remarks></remarks>    Private Function ParseSimpleTypeName(ByVal Parent As ParsedObject) As SimpleTypeName        Dim result As New SimpleTypeName(Parent)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?