parser(members).vb
来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 537 行 · 第 1/2 页
VB
537 行
' ' Visual Basic.Net Compiler' Copyright (C) 2004 - 2007 Rolf Bjarne Kvinge, RKvinge@novell.com' ' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' ' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' ' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA' Partial Class Parser ''' <summary> ''' VariableIdentifiers ::= ''' VariableIdentifier | ''' VariableIdentifiers , VariableIdentifier ''' </summary> ''' <remarks></remarks> Private Function ParseVariableIdentifiers(ByVal Parent As ParsedObject) As VariableIdentifiers Dim result As New VariableIdentifiers(Parent) If ParseList(Of VariableIdentifier)(result, New ParseDelegate_Parent(Of VariableIdentifier)(AddressOf ParseVariableIdentifier), Parent) = False Then Helper.ErrorRecoveryNotImplemented() End If Return result End Function ''' <summary> ''' ConstructorMemberDeclaration ::= ''' [ Attributes ] [ ConstructorModifier+ ] "Sub" "New" [ "(" [ ParameterList ] ")" ] LineTerminator ''' [ Block ] ''' "End" "Sub" StatementTerminator ''' </summary> ''' <remarks></remarks> Private Function ParseConstructorMember(ByVal Parent As TypeDeclaration, ByVal Info As ParseAttributableInfo) As ConstructorDeclaration Dim result As New ConstructorDeclaration(Parent) Dim m_Modifiers As Modifiers Dim m_ParameterList As New ParameterList(result) Dim m_Signature As SubSignature Dim m_Block As CodeBlock m_Modifiers = ParseModifiers(result, ModifierMasks.ConstructorModifiers) tm.AcceptIfNotInternalError(KS.Sub) tm.AcceptIfNotInternalError(KS.[New]) If tm.Accept(KS.LParenthesis) Then If tm.Accept(KS.RParenthesis) = False Then If ParseList(Of Parameter)(m_ParameterList, New ParseDelegate_Parent(Of Parameter)(AddressOf ParseParameter), m_ParameterList) = False Then Helper.ErrorRecoveryNotImplemented() End If If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented() End If End If m_Signature = New SubSignature(result, "", m_ParameterList) If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() m_Block = ParseCodeBlock(result, False) If m_Block Is Nothing Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptIfNotError(KS.End_Sub) = False Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() result.Init(Info.Attributes, m_Modifiers, m_Signature, m_Block) Return result End Function ''' <summary> ''' RegularPropertyMemberDeclaration ::= ''' [ Attributes ] [ PropertyModifier+ ] "Property" FunctionSignature [ ImplementsClause ] ''' LineTerminator ''' PropertyAccessorDeclaration+ ''' "End" "Property" StatementTerminator ''' </summary> ''' <remarks></remarks> Private Function ParseRegularPropertyMemberDeclaration(ByVal Parent As TypeDeclaration, ByVal Info As ParseAttributableInfo) As RegularPropertyDeclaration Dim result As New RegularPropertyDeclaration(Parent) Dim m_Modifiers As Modifiers Dim m_Signature As FunctionSignature Dim m_ImplementsClause As MemberImplementsClause Dim m_Attributes As New Attributes(result) Dim m_Get As PropertyGetDeclaration = Nothing Dim m_Set As PropertySetDeclaration = Nothing m_Modifiers = ParseModifiers(result, ModifierMasks.PropertyModifiers) tm.AcceptIfNotInternalError(KS.Property) m_Signature = ParseFunctionSignature(result) If m_Signature Is Nothing Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptEndOfStatement() = False Then m_ImplementsClause = ParseImplementsClause(result) If m_ImplementsClause Is Nothing Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() Else m_ImplementsClause = Nothing End If Do m_Attributes = ParseAttributes(result) If PropertyGetDeclaration.IsMe(tm) Then If m_Get IsNot Nothing Then Helper.AddError("Found more than one Get Property.") End If m_Get = ParsePropertyGetMember(result, New ParseAttributableInfo(Compiler, m_Attributes), m_Signature, m_ImplementsClause, m_Modifiers.Mask) If m_Get Is Nothing Then Helper.ErrorRecoveryNotImplemented() m_Attributes = Nothing ElseIf PropertySetDeclaration.IsMe(tm) Then If m_Set IsNot Nothing Then Helper.AddError("Found more than one Set Property.") End If m_Set = ParsePropertySetMember(result, New ParseAttributableInfo(Compiler, m_Attributes), m_Signature, m_ImplementsClause, m_Modifiers.Mask) If m_Set Is Nothing Then Helper.ErrorRecoveryNotImplemented() m_Attributes = Nothing Else If m_Attributes IsNot Nothing AndAlso m_Attributes.Count > 0 Then 'Hanging attributes. Helper.NotImplemented() 'Some error End If Exit Do End If Loop If tm.AcceptIfNotError(KS.End_Property) = False Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() result.Init(Info.Attributes, m_Modifiers, m_Signature, m_Get, m_Set, m_ImplementsClause) Return result End Function ''' <summary> ''' PropertySetDeclaration ::= ''' [ Attributes ] [ AccessModifier ] "Set" [ ( ParameterList ) ] LineTerminator ''' [ Block ] ''' "End" "Set" StatementTerminator ''' </summary> ''' <remarks></remarks> Private Function ParsePropertySetMember(ByVal Parent As PropertyDeclaration, ByVal Info As ParseAttributableInfo, ByVal ParentSignature As FunctionSignature, ByVal ParentImplements As MemberImplementsClause, ByVal ParentModifiers As ModifierMasks) As PropertySetDeclaration Dim result As New PropertySetDeclaration(Parent) Dim m_Modifiers As Modifiers Dim m_ParameterList As New ParameterList(result) Dim m_Block As CodeBlock m_Modifiers = ParseModifiers(result, ModifierMasks.AccessModifiers) If m_Modifiers.Empty = False Then m_Modifiers.AddModifiers(ParentModifiers And (Not ModifierMasks.AccessModifiers)) Else m_Modifiers.AddModifiers(ParentModifiers) End If tm.AcceptIfNotInternalError(KS.Set) If tm.Accept(KS.LParenthesis) Then If ParseList(Of Parameter)(m_ParameterList, New ParseDelegate_Parent(Of Parameter)(AddressOf ParseParameter), m_ParameterList) = False Then Helper.ErrorRecoveryNotImplemented() End If If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented() End If If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() m_Block = ParseCodeBlock(result, False) If m_Block Is Nothing Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptIfNotError(KS.End_Set) = False Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() result.Init(Info.Attributes, m_Modifiers, ParentSignature, ParentImplements, m_Block, m_ParameterList) Return result End Function ''' <summary> ''' PropertyGetDeclaration ::= ''' [ Attributes ] [ AccessModifier ] Get LineTerminator ''' [ Block ] ''' End Get StatementTerminator ''' </summary> ''' <remarks></remarks> Private Function ParsePropertyGetMember(ByVal Parent As PropertyDeclaration, ByVal Info As ParseAttributableInfo, ByVal ParentSignature As FunctionSignature, ByVal ParentImplements As MemberImplementsClause, ByVal ParentModifiers As ModifierMasks) As PropertyGetDeclaration Dim result As New PropertyGetDeclaration(Parent) Dim m_Modifiers As Modifiers Dim m_Block As CodeBlock m_Modifiers = ParseModifiers(result, ModifierMasks.AccessModifiers) If m_Modifiers.Empty = False Then m_Modifiers.AddModifiers(ParentModifiers And (Not ModifierMasks.AccessModifiers)) Else m_Modifiers.AddModifiers(ParentModifiers) End If tm.AcceptIfNotInternalError(KS.Get) If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() m_Block = ParseCodeBlock(result, False) If m_Block Is Nothing Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptIfNotError(KS.End_Get) = False Then Helper.ErrorRecoveryNotImplemented() If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented() result.Init(Info.Attributes, m_Modifiers, ParentSignature, ParentImplements, m_Block) Return result End Function ''' <summary> ''' Tries to parse a sub signature. Returns false if not successful. ''' SubSignature ::= Identifier [ TypeParameterList ] [ "(" [ ParameterList ] ")" ] ''' </summary> ''' <param name="Parent"></param> ''' <param name="m_Identifier">Output parameter, must be nothing on entry.</param> ''' <param name="m_TypeParameters">Output parameter, must be nothing on entry.</param> ''' <param name="m_ParameterList">Input/Output parameter, must not be nothing on entry.</param> ''' <returns></returns> ''' <remarks></remarks> Private Function ParseSubSignature(ByVal Parent As ParsedObject, ByRef m_Identifier As Token, ByRef m_TypeParameters As TypeParameters, ByVal m_ParameterList As ParameterList) As Boolean Dim result As Boolean = True 'Helper.Assert(m_Identifier Is Nothing) Helper.Assert(m_TypeParameters Is Nothing) Helper.Assert(m_ParameterList IsNot Nothing) result = tm.AcceptIdentifier(m_Identifier) AndAlso result If vbnc.TypeParameters.IsMe(tm) Then m_TypeParameters = ParseTypeParameters(Parent) End If If tm.Accept(KS.LParenthesis) Then If tm.Accept(KS.RParenthesis) = False Then If ParseList(Of Parameter)(m_ParameterList, New ParseDelegate_Parent(Of Parameter)(AddressOf ParseParameter), m_ParameterList) = False Then Helper.ErrorRecoveryNotImplemented() End If result = tm.AcceptIfNotError(KS.RParenthesis) AndAlso result End If End If 'Helper.Assert(m_Identifier IsNot Nothing) Return result End Function ''' <summary> ''' SubSignature ::= Identifier [ TypeParameterList ] [ "(" [ ParameterList ] ")" ] ''' </summary> ''' <remarks></remarks> Private Function ParseSubSignature(ByVal Parent As ParsedObject) As SubSignature Dim result As New SubSignature(Parent) Dim m_Identifier As Token = Nothing
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?