2019-07-17 22:01:31 +08:00
|
|
|
|
#Region "Microsoft.VisualBasic::04b70b48eab1dafca8861e45bd5803df, Scripting\VisualBasic\KeywordProcessor.vb"
|
2019-05-06 18:27:46 +08:00
|
|
|
|
|
|
|
|
|
|
' Author:
|
|
|
|
|
|
'
|
|
|
|
|
|
' asuka (amethyst.asuka@gcmodeller.org)
|
|
|
|
|
|
' xie (genetics@smrucc.org)
|
|
|
|
|
|
' xieguigang (xie.guigang@live.com)
|
|
|
|
|
|
'
|
|
|
|
|
|
' Copyright (c) 2018 GPL3 Licensed
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' GNU GENERAL PUBLIC LICENSE (GPL3)
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
' it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
' the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
' (at your option) any later version.
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program 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 General Public License for more details.
|
|
|
|
|
|
'
|
|
|
|
|
|
' You should have received a copy of the GNU General Public License
|
|
|
|
|
|
' along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
' /********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
' Summaries:
|
|
|
|
|
|
|
|
|
|
|
|
' Class KeywordProcessor
|
|
|
|
|
|
'
|
|
|
|
|
|
' Properties: Words
|
|
|
|
|
|
'
|
|
|
|
|
|
' Constructor: (+1 Overloads) Sub New
|
|
|
|
|
|
' Function: AutoEscapeVBKeyword
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' /********************************************************************************/
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
|
|
Imports System.Runtime.CompilerServices
|
|
|
|
|
|
|
2018-10-03 13:28:23 +08:00
|
|
|
|
Namespace Scripting.SymbolBuilder.VBLanguage
|
|
|
|
|
|
|
2018-08-02 20:14:48 +08:00
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Keyword processor of the VB.NET language
|
|
|
|
|
|
''' </summary>
|
2018-10-03 13:28:23 +08:00
|
|
|
|
Public NotInheritable Class KeywordProcessor
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' List of VB.NET language keywords
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
Public Const VBKeywords$ =
|
|
|
|
|
|
"|AddHandler|AddressOf|Alias|And|AndAlso|As|" &
|
|
|
|
|
|
"|Boolean|ByRef|Byte|" &
|
|
|
|
|
|
"|Call|Case|Catch|CBool|CByte|CChar|CDate|CDec|CDbl|Char|CInt|Class|CLng|CObj|Const|Continue|CSByte|CShort|CSng|CStr|CType|CUInt|CULng|CUShort|" &
|
|
|
|
|
|
"|Date|Decimal|Declare|Default|Delegate|Dim|DirectCast|Do|Double|" &
|
|
|
|
|
|
"|Each|Else|ElseIf|End|EndIf|Enum|Erase|Error|Event|Exit|" &
|
|
|
|
|
|
"|False|Finally|For|Friend|Function|" &
|
|
|
|
|
|
"|Get|GetType|GetXMLNamespace|Global|GoSub|GoTo|" &
|
|
|
|
|
|
"|Handles|" &
|
|
|
|
|
|
"|If|Implements|Imports|In|Inherits|Integer|Interface|Is|IsNot|" &
|
|
|
|
|
|
"|Let|Lib|Like|Long|Loop|" &
|
|
|
|
|
|
"|Me|Mod|Module|MustInherit|MustOverride|MyBase|MyClass|" &
|
|
|
|
|
|
"|Namespace|Narrowing|New|Next|Not|Nothing|NotInheritable|NotOverridable|NameOf|" &
|
|
|
|
|
|
"|Object|Of|On|Operator|Option|Optional|Or|OrElse|Overloads|Overridable|Overrides|" &
|
|
|
|
|
|
"|ParamArray|Partial|Private|Property|Protected|Public|" &
|
|
|
|
|
|
"|RaiseEvent|ReadOnly|ReDim|REM|RemoveHandler|Resume|Return|" &
|
|
|
|
|
|
"|SByte|Select|Set|Shadows|Shared|Short|Single|Static|Step|Stop|String|Structure|Sub|SyncLock|" &
|
|
|
|
|
|
"|Then|Throw|To|True|Try|TryCast|TypeOf|" &
|
|
|
|
|
|
"|Variant|" &
|
|
|
|
|
|
"|Wend|" &
|
|
|
|
|
|
"|UInteger|ULong|UShort|Using|" &
|
|
|
|
|
|
"|When|While|Widening|With|WithEvents|WriteOnly|" &
|
|
|
|
|
|
"|Xor|" &
|
|
|
|
|
|
"|Yield|"
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Tokenize of <see cref="VBKeywords"/>
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <returns></returns>
|
|
|
|
|
|
Public ReadOnly Property Words As String()
|
|
|
|
|
|
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
|
|
|
|
|
Get
|
|
|
|
|
|
Return VBKeywords _
|
|
|
|
|
|
.Split("|"c) _
|
|
|
|
|
|
.Where(Function(s) Not s.StringEmpty) _
|
|
|
|
|
|
.ToArray
|
|
|
|
|
|
End Get
|
|
|
|
|
|
End Property
|
|
|
|
|
|
|
|
|
|
|
|
Private Sub New()
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Escaping the vb variable name when it conflicts with VB keywords name,
|
|
|
|
|
|
''' this function can be using for the VB.NET related code generator.
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="name$">The identifier name.</param>
|
|
|
|
|
|
''' <returns>If the identifier is a VB.NET keyword, then it will be escaping and returns,
|
|
|
|
|
|
''' otherwise, will do nothing, function returns the raw input identifier.
|
|
|
|
|
|
''' </returns>
|
|
|
|
|
|
Public Shared Function AutoEscapeVBKeyword(name$) As String
|
|
|
|
|
|
If InStr(VBKeywords, $"|{name}|", CompareMethod.Text) > 0 Then
|
|
|
|
|
|
Return $"[{name}]"
|
|
|
|
|
|
Else
|
|
|
|
|
|
Return name
|
|
|
|
|
|
End If
|
|
|
|
|
|
End Function
|
|
|
|
|
|
End Class
|
|
|
|
|
|
End Namespace
|